]> 127.0.0.1 Git - part/.git/commitdiff
1 (#29) v0.28.20250215204247
authorqydysky <qydysky@foxmail.com>
Sat, 15 Feb 2025 20:42:39 +0000 (04:42 +0800)
committerGitHub <noreply@github.com>
Sat, 15 Feb 2025 20:42:39 +0000 (04:42 +0800)
file/FileWR.go
file/FileWR_test.go

index feba8462319caa84811ddc3fe536ca80314e5ec8..3c39b9743ca73f0079812eae649958aacb1f7986 100644 (file)
@@ -118,8 +118,13 @@ func New(filePath string, curIndex int64, autoClose bool) *File {
        }
 }
 
-func (t *File) InRoot(root string) *File {
+func (t *File) CheckRoot(root string) *File {
        t.Config.root = root
+       if rel, e := filepath.Rel(root, t.Config.FilePath); e != nil {
+               panic(e)
+       } else {
+               t.Config.FilePath = rel
+       }
        return t
 }
 
index 4ebddfd600282ab965a4a756156fca8b2fc3829a..8a8104d1e3f777fde0e61c83f1a9dc33160a2087 100644 (file)
@@ -308,8 +308,11 @@ func TestCreate(t *testing.T) {
 
 func TestIsRoot(t *testing.T) {
        sf := New("../t.txt", 0, true)
-       sf.InRoot("testdata")
+       sf.CheckRoot("testdata")
        if !strings.HasSuffix(sf.Delete().Error(), "path escapes from parent") {
                t.Fatal()
        }
+
+       sf = New("testdata/1.txt", 0, true).CheckRoot("testdata")
+       t.Log(sf.IsExist())
 }