}
}
-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
}
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())
}