From: qydysky <32743305+qydysky@users.noreply.github.com> Date: Sun, 16 Oct 2022 07:37:48 +0000 (+0800) Subject: fix X-Git-Tag: v0.10.11 X-Git-Url: http://127.0.0.1:8081/?a=commitdiff_plain;h=eead2d89b23532ce34ca51916ac5a2505d45006b;p=part%2F.git fix --- diff --git a/file/FileWR.go b/file/FileWR.go index add3770..139922b 100644 --- a/file/FileWR.go +++ b/file/FileWR.go @@ -24,6 +24,7 @@ type File struct { file *os.File wr io.Writer rr io.Reader + cu int64 sync.RWMutex } @@ -168,7 +169,7 @@ func (t *File) Seed(index int64) (e error) { if index < 0 { whenc = 2 } - t.Config.CurIndex, e = t.file.Seek(index, whenc) + t.cu, e = t.file.Seek(index, whenc) return nil } @@ -200,6 +201,8 @@ func (t *File) Close() error { if t.file != nil { if e := t.file.Close(); e != nil { return e + } else { + t.file = nil } } return nil @@ -234,7 +237,8 @@ func (t *File) getRWCloser() { panic(e) } else { if t.Config.CurIndex > 0 { - t.Config.CurIndex, e = f.Seek(t.Config.CurIndex, 0) + t.cu = t.Config.CurIndex + t.cu, e = f.Seek(t.cu, 0) if e != nil { panic(e) } @@ -246,11 +250,13 @@ func (t *File) getRWCloser() { panic(e) } else { if t.Config.CurIndex != 0 { + t.cu = t.Config.CurIndex whenc := 0 if t.Config.CurIndex < 0 { + t.cu = t.cu + 1 whenc = 2 } - t.Config.CurIndex, e = f.Seek(t.Config.CurIndex, whenc) + t.cu, e = f.Seek(t.cu, whenc) if e != nil { panic(e) } diff --git a/file/FileWR_test.go b/file/FileWR_test.go index 91e1851..430efd9 100644 --- a/file/FileWR_test.go +++ b/file/FileWR_test.go @@ -11,27 +11,25 @@ import ( ) func TestWriteReadDelSync(t *testing.T) { - f := New("test/rwd.txt", -1, true) - if i, e := f.Write([]byte("sss"), true); i == 0 || e != nil { + f := New("test/rwd.txt", -6, true) + if i, e := f.Write([]byte("sssa\n"), true); i == 0 || e != nil { t.Fatal(e) } - var buf = make([]byte, 3) + var buf = make([]byte, 5) if i, e := f.Read(buf); i == 0 || e != nil { t.Fatal(i, e) } else { - if !bytes.Equal(buf[:i], []byte("sss")) { - t.Fatal(string(buf[:i]), e) + if !bytes.Equal(buf[:i], []byte("sssa\n")) { + t.Fatal(i, string(buf), e) } } if i, e := f.Read(buf); i == 0 || e != nil { t.Fatal(i, e) } else { - for _, v := range buf { - if v != 's' { - t.Fatal(v) - } + if !bytes.Equal(buf[:i], []byte("sssa\n")) { + t.Fatal(i, string(buf), e) } }