From dad33e59c2b910e1ae06a62bc00556afbf783985 Mon Sep 17 00:00:00 2001 From: qydysky Date: Sun, 16 Feb 2025 03:06:58 +0800 Subject: [PATCH] 1 (#27) --- file/FileWR.go | 14 ++++---------- file/FileWR_test.go | 3 ++- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/file/FileWR.go b/file/FileWR.go index 6fbed22..3a854a2 100644 --- a/file/FileWR.go +++ b/file/FileWR.go @@ -107,10 +107,9 @@ type Config struct { Coder encoder.Encoding } -func NewInRoot(root string, filePath string, curIndex int64, autoClose bool) *File { +func New(filePath string, curIndex int64, autoClose bool) *File { return &File{ Config: Config{ - root: root, FilePath: filePath, CurIndex: curIndex, AutoClose: autoClose, @@ -118,14 +117,9 @@ func NewInRoot(root string, filePath string, curIndex int64, autoClose bool) *Fi } } -func New(filePath string, curIndex int64, autoClose bool) *File { - return &File{ - Config: Config{ - FilePath: filePath, - CurIndex: curIndex, - AutoClose: autoClose, - }, - } +func (t *File) InRoot(root string) *File { + t.Config.root = root + return t } func (t *File) CopyTo(to *File, copyIOConfig pio.CopyConfig, tryLock bool) error { diff --git a/file/FileWR_test.go b/file/FileWR_test.go index 26abcab..4ebddfd 100644 --- a/file/FileWR_test.go +++ b/file/FileWR_test.go @@ -307,7 +307,8 @@ func TestCreate(t *testing.T) { } func TestIsRoot(t *testing.T) { - sf := NewInRoot("./testdata", "../t.txt", 0, true) + sf := New("../t.txt", 0, true) + sf.InRoot("testdata") if !strings.HasSuffix(sf.Delete().Error(), "path escapes from parent") { t.Fatal() } -- 2.39.2