]> 127.0.0.1 Git - part/.git/commitdiff
fix v0.10.4
authorqydysky <32743305+qydysky@users.noreply.github.com>
Sat, 15 Oct 2022 19:42:45 +0000 (03:42 +0800)
committerqydysky <32743305+qydysky@users.noreply.github.com>
Sat, 15 Oct 2022 19:42:45 +0000 (03:42 +0800)
file/FileWR.go
file/FileWR_test.go
websocket/Recoder.go

index b605a3c99e8eed2c1d97b808ed5411bc83cfd811..63aa99efa34f2feef01ebf81217e808f119cc415 100644 (file)
@@ -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
index 34b3a50cf912be3d501646495f42a6bb0b1c1762..74673b5bdf0467738c35a6d0c3414226616e8662 100644 (file)
@@ -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)
        }
index c09efd906a08ddb2e855cdac6435fb48fdfc99bc..9779916e28754e53635079e0f6ad42f0e9206708 100644 (file)
@@ -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
                        },