From c7e44dc5e9a6b0a2730625fc3b12f0fe6e49de65 Mon Sep 17 00:00:00 2001 From: qydysky <32743305+qydysky@users.noreply.github.com> Date: Sun, 16 Oct 2022 03:42:45 +0800 Subject: [PATCH] fix --- file/FileWR.go | 14 ++++++++++++++ file/FileWR_test.go | 4 ++++ websocket/Recoder.go | 1 + 3 files changed, 19 insertions(+) diff --git a/file/FileWR.go b/file/FileWR.go index b605a3c..63aa99e 100644 --- a/file/FileWR.go +++ b/file/FileWR.go @@ -167,6 +167,20 @@ func (t *File) Seed(index int64) (e error) { return nil } +func (t *File) Sync() (e error) { + t.getRWCloser() + if t.Config.AutoClose { + defer t.Close() + } + + if !t.TryRLock() { + return ErrFailToLock + } + defer t.RUnlock() + + return t.file.Sync() +} + func (t *File) Delete() error { if !t.TryLock() { return ErrFailToLock diff --git a/file/FileWR_test.go b/file/FileWR_test.go index 34b3a50..74673b5 100644 --- a/file/FileWR_test.go +++ b/file/FileWR_test.go @@ -128,6 +128,10 @@ func TestReadUntil(t *testing.T) { t.Fatal(e) } + if e := f.Sync(); e != nil { + t.Fatal(e) + } + if e := f.Seed(0); e != nil { t.Fatal(e) } diff --git a/websocket/Recoder.go b/websocket/Recoder.go index c09efd9..9779916 100644 --- a/websocket/Recoder.go +++ b/websocket/Recoder.go @@ -52,6 +52,7 @@ func (t *Recorder) Start(filePath string) error { } if tmp, ok := data.(Uinterface); ok { f.Write([]byte(fmt.Sprintf("%f,%d,%s\n", time.Since(startTimeStamp).Seconds(), tmp.Id, tmp.Data)), true) + f.Sync() } return false }, -- 2.39.2