refactor: Move File and FileInfo to pkg
This commit is contained in:
@@ -14,7 +14,6 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
ifs "github.com/pojntfx/stfs/internal/fs"
|
|
||||||
"github.com/pojntfx/stfs/internal/pathext"
|
"github.com/pojntfx/stfs/internal/pathext"
|
||||||
"github.com/pojntfx/stfs/pkg/cache"
|
"github.com/pojntfx/stfs/pkg/cache"
|
||||||
"github.com/pojntfx/stfs/pkg/config"
|
"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()
|
f.ioLock.Lock()
|
||||||
defer f.ioLock.Unlock()
|
defer f.ioLock.Unlock()
|
||||||
|
|
||||||
flags := &ifs.FileFlags{}
|
flags := &FileFlags{}
|
||||||
if f.readOnly {
|
if f.readOnly {
|
||||||
if (flag&O_ACCMODE) == os.O_RDONLY || (flag&O_ACCMODE) == os.O_RDWR {
|
if (flag&O_ACCMODE) == os.O_RDONLY || (flag&O_ACCMODE) == os.O_RDWR {
|
||||||
flags.Read = true
|
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 nil, config.ErrIsDirectory
|
||||||
}
|
}
|
||||||
|
|
||||||
return ifs.NewFile(
|
return NewFile(
|
||||||
f.readOps,
|
f.readOps,
|
||||||
f.writeOps,
|
f.writeOps,
|
||||||
|
|
||||||
@@ -490,7 +489,7 @@ func (f *STFS) OpenFile(name string, flag int, perm os.FileMode) (afero.File, er
|
|||||||
&f.ioLock,
|
&f.ioLock,
|
||||||
|
|
||||||
path.Base(hdr.Name),
|
path.Base(hdr.Name),
|
||||||
ifs.NewFileInfoFromTarHeader(hdr, f.log),
|
NewFileInfoFromTarHeader(hdr, f.log),
|
||||||
|
|
||||||
f.onHeader,
|
f.onHeader,
|
||||||
f.log,
|
f.log,
|
||||||
@@ -690,7 +689,7 @@ func (f *STFS) Stat(name string) (os.FileInfo, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return ifs.NewFileInfoFromTarHeader(hdr, f.log), nil
|
return NewFileInfoFromTarHeader(hdr, f.log), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *STFS) updateMetadata(hdr *tar.Header) error {
|
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 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) {
|
func (f *STFS) LstatIfPossible(name string) (os.FileInfo, bool, error) {
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pojntfx/stfs/examples"
|
"github.com/pojntfx/stfs/examples"
|
||||||
ifs "github.com/pojntfx/stfs/internal/fs"
|
|
||||||
"github.com/pojntfx/stfs/pkg/cache"
|
"github.com/pojntfx/stfs/pkg/cache"
|
||||||
"github.com/pojntfx/stfs/pkg/config"
|
"github.com/pojntfx/stfs/pkg/config"
|
||||||
"github.com/pojntfx/stfs/pkg/keys"
|
"github.com/pojntfx/stfs/pkg/keys"
|
||||||
@@ -2537,7 +2536,7 @@ var chownTests = []struct {
|
|||||||
wantGID := 11
|
wantGID := 11
|
||||||
wantUID := 11
|
wantUID := 11
|
||||||
|
|
||||||
gotSys, ok := f.Sys().(*ifs.Stat)
|
gotSys, ok := f.Sys().(*Stat)
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("could not get fs.Stat from FileInfo.Sys()")
|
return errors.New("could not get fs.Stat from FileInfo.Sys()")
|
||||||
}
|
}
|
||||||
@@ -2584,7 +2583,7 @@ var chownTests = []struct {
|
|||||||
wantGID := 11
|
wantGID := 11
|
||||||
wantUID := 11
|
wantUID := 11
|
||||||
|
|
||||||
gotSys, ok := f.Sys().(*ifs.Stat)
|
gotSys, ok := f.Sys().(*Stat)
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("could not get fs.Stat from FileInfo.Sys()")
|
return errors.New("could not get fs.Stat from FileInfo.Sys()")
|
||||||
}
|
}
|
||||||
@@ -2627,7 +2626,7 @@ var chownTests = []struct {
|
|||||||
wantGID := 11
|
wantGID := 11
|
||||||
wantUID := 11
|
wantUID := 11
|
||||||
|
|
||||||
gotSys, ok := f.Sys().(*ifs.Stat)
|
gotSys, ok := f.Sys().(*Stat)
|
||||||
if !ok {
|
if !ok {
|
||||||
return errors.New("could not get fs.Stat from FileInfo.Sys()")
|
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)
|
wantAtime := time.Date(2021, 12, 23, 0, 0, 0, 0, time.UTC)
|
||||||
wantMtime := time.Date(2022, 01, 14, 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 {
|
if !ok {
|
||||||
return errors.New("could not get fs.Stat from FileInfo.Sys()")
|
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)
|
wantAtime := time.Date(2021, 12, 23, 0, 0, 0, 0, time.UTC)
|
||||||
wantMtime := time.Date(2022, 01, 14, 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 {
|
if !ok {
|
||||||
return errors.New("could not get fs.Stat from FileInfo.Sys()")
|
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)
|
wantAtime := time.Date(2021, 12, 23, 0, 0, 0, 0, time.UTC)
|
||||||
wantMtime := time.Date(2022, 01, 14, 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 {
|
if !ok {
|
||||||
return errors.New("could not get fs.Stat from FileInfo.Sys()")
|
return errors.New("could not get fs.Stat from FileInfo.Sys()")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user