]> 127.0.0.1 Git - part/.git/commitdiff
fix v0.10.11
authorqydysky <32743305+qydysky@users.noreply.github.com>
Sun, 16 Oct 2022 07:37:48 +0000 (15:37 +0800)
committerqydysky <32743305+qydysky@users.noreply.github.com>
Sun, 16 Oct 2022 07:37:48 +0000 (15:37 +0800)
file/FileWR.go
file/FileWR_test.go

index add377088113cfc56d81ee0be0ade3b6b6cd65f7..139922b12356a05697a7a813e2677716eabd71a0 100644 (file)
@@ -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)
                                        }
index 91e1851a7b04ae08b1435dc9d102597f3ac22b15..430efd9a508bfeb29d31cd491c7f762d33ecbc21 100644 (file)
@@ -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)
                }
        }