From 84f91bfd4a2d1f993b6c4977baf8fb125bf2d988 Mon Sep 17 00:00:00 2001 From: Felicitas Pojtinger Date: Tue, 18 Jan 2022 21:01:55 +0100 Subject: [PATCH] refactor: Move `File` and `FileInfo` to `pkg` --- {internal => pkg}/fs/file.go | 0 {internal => pkg}/fs/fileinfo.go | 0 pkg/fs/filesystem.go | 11 +++++------ pkg/fs/filesystem_test.go | 13 ++++++------- .../fileinfo_non_unix.go => pkg/fs/stat_non_unix.go | 0 internal/fs/fileinfo_unix.go => pkg/fs/stat_unix.go | 0 6 files changed, 11 insertions(+), 13 deletions(-) rename {internal => pkg}/fs/file.go (100%) rename {internal => pkg}/fs/fileinfo.go (100%) rename internal/fs/fileinfo_non_unix.go => pkg/fs/stat_non_unix.go (100%) rename internal/fs/fileinfo_unix.go => pkg/fs/stat_unix.go (100%) diff --git a/internal/fs/file.go b/pkg/fs/file.go similarity index 100% rename from internal/fs/file.go rename to pkg/fs/file.go diff --git a/internal/fs/fileinfo.go b/pkg/fs/fileinfo.go similarity index 100% rename from internal/fs/fileinfo.go rename to pkg/fs/fileinfo.go diff --git a/pkg/fs/filesystem.go b/pkg/fs/filesystem.go index 1016d44..b7afdf0 100644 --- a/pkg/fs/filesystem.go +++ b/pkg/fs/filesystem.go @@ -14,7 +14,6 @@ import ( "sync" "time" - ifs "github.com/pojntfx/stfs/internal/fs" "github.com/pojntfx/stfs/internal/pathext" "github.com/pojntfx/stfs/pkg/cache" "github.com/pojntfx/stfs/pkg/config" @@ -393,7 +392,7 @@ func (f *STFS) OpenFile(name string, flag int, perm os.FileMode) (afero.File, er f.ioLock.Lock() defer f.ioLock.Unlock() - flags := &ifs.FileFlags{} + flags := &FileFlags{} if f.readOnly { if (flag&O_ACCMODE) == os.O_RDONLY || (flag&O_ACCMODE) == os.O_RDWR { flags.Read = true @@ -475,7 +474,7 @@ func (f *STFS) OpenFile(name string, flag int, perm os.FileMode) (afero.File, er return nil, config.ErrIsDirectory } - return ifs.NewFile( + return NewFile( f.readOps, f.writeOps, @@ -490,7 +489,7 @@ func (f *STFS) OpenFile(name string, flag int, perm os.FileMode) (afero.File, er &f.ioLock, path.Base(hdr.Name), - ifs.NewFileInfoFromTarHeader(hdr, f.log), + NewFileInfoFromTarHeader(hdr, f.log), f.onHeader, f.log, @@ -690,7 +689,7 @@ func (f *STFS) Stat(name string) (os.FileInfo, error) { return nil, err } - return ifs.NewFileInfoFromTarHeader(hdr, f.log), nil + return NewFileInfoFromTarHeader(hdr, f.log), nil } func (f *STFS) updateMetadata(hdr *tar.Header) error { @@ -868,7 +867,7 @@ func (f *STFS) lstatIfPossibleWithoutLocking(name string) (info os.FileInfo, lin return nil, "", true, err } - return ifs.NewFileInfoFromTarHeader(hdr, f.log), path.Base(hdr.Linkname), true, nil + return NewFileInfoFromTarHeader(hdr, f.log), path.Base(hdr.Linkname), true, nil } func (f *STFS) LstatIfPossible(name string) (os.FileInfo, bool, error) { diff --git a/pkg/fs/filesystem_test.go b/pkg/fs/filesystem_test.go index 4ffd3b6..2e512e8 100644 --- a/pkg/fs/filesystem_test.go +++ b/pkg/fs/filesystem_test.go @@ -17,7 +17,6 @@ import ( "time" "github.com/pojntfx/stfs/examples" - ifs "github.com/pojntfx/stfs/internal/fs" "github.com/pojntfx/stfs/pkg/cache" "github.com/pojntfx/stfs/pkg/config" "github.com/pojntfx/stfs/pkg/keys" @@ -2537,7 +2536,7 @@ var chownTests = []struct { wantGID := 11 wantUID := 11 - gotSys, ok := f.Sys().(*ifs.Stat) + gotSys, ok := f.Sys().(*Stat) if !ok { return errors.New("could not get fs.Stat from FileInfo.Sys()") } @@ -2584,7 +2583,7 @@ var chownTests = []struct { wantGID := 11 wantUID := 11 - gotSys, ok := f.Sys().(*ifs.Stat) + gotSys, ok := f.Sys().(*Stat) if !ok { return errors.New("could not get fs.Stat from FileInfo.Sys()") } @@ -2627,7 +2626,7 @@ var chownTests = []struct { wantGID := 11 wantUID := 11 - gotSys, ok := f.Sys().(*ifs.Stat) + gotSys, ok := f.Sys().(*Stat) if !ok { return errors.New("could not get fs.Stat from FileInfo.Sys()") } @@ -2738,7 +2737,7 @@ var chtimesTests = []struct { wantAtime := time.Date(2021, 12, 23, 0, 0, 0, 0, time.UTC) wantMtime := time.Date(2022, 01, 14, 0, 0, 0, 0, time.UTC) - gotSys, ok := f.Sys().(*ifs.Stat) + gotSys, ok := f.Sys().(*Stat) if !ok { return errors.New("could not get fs.Stat from FileInfo.Sys()") } @@ -2785,7 +2784,7 @@ var chtimesTests = []struct { wantAtime := time.Date(2021, 12, 23, 0, 0, 0, 0, time.UTC) wantMtime := time.Date(2022, 01, 14, 0, 0, 0, 0, time.UTC) - gotSys, ok := f.Sys().(*ifs.Stat) + gotSys, ok := f.Sys().(*Stat) if !ok { return errors.New("could not get fs.Stat from FileInfo.Sys()") } @@ -2828,7 +2827,7 @@ var chtimesTests = []struct { wantAtime := time.Date(2021, 12, 23, 0, 0, 0, 0, time.UTC) wantMtime := time.Date(2022, 01, 14, 0, 0, 0, 0, time.UTC) - gotSys, ok := f.Sys().(*ifs.Stat) + gotSys, ok := f.Sys().(*Stat) if !ok { return errors.New("could not get fs.Stat from FileInfo.Sys()") } diff --git a/internal/fs/fileinfo_non_unix.go b/pkg/fs/stat_non_unix.go similarity index 100% rename from internal/fs/fileinfo_non_unix.go rename to pkg/fs/stat_non_unix.go diff --git a/internal/fs/fileinfo_unix.go b/pkg/fs/stat_unix.go similarity index 100% rename from internal/fs/fileinfo_unix.go rename to pkg/fs/stat_unix.go