lib: Get rid of buggy filesystem wrapping (#8257)
This commit is contained in:
+16
-10
@@ -26,7 +26,7 @@ func TestMtimeFS(t *testing.T) {
|
||||
// a random time with nanosecond precision
|
||||
testTime := time.Unix(1234567890, 123456789)
|
||||
|
||||
mtimefs := newMtimeFS(newBasicFilesystem("."), make(mapStore))
|
||||
mtimefs := newMtimeFS(".", make(mapStore))
|
||||
|
||||
// Do one Chtimes call that will go through to the normal filesystem
|
||||
mtimefs.chtimes = os.Chtimes
|
||||
@@ -88,8 +88,8 @@ func TestMtimeFSWalk(t *testing.T) {
|
||||
}
|
||||
defer func() { _ = os.RemoveAll(dir) }()
|
||||
|
||||
underlying := NewFilesystem(FilesystemTypeBasic, dir)
|
||||
mtimefs := newMtimeFS(underlying, make(mapStore))
|
||||
mtimefs, walkFs := newMtimeFSWithWalk(dir, make(mapStore))
|
||||
underlying := mtimefs.Filesystem
|
||||
mtimefs.chtimes = failChtimes
|
||||
|
||||
if err := os.WriteFile(filepath.Join(dir, "file"), []byte("hello"), 0644); err != nil {
|
||||
@@ -120,7 +120,7 @@ func TestMtimeFSWalk(t *testing.T) {
|
||||
}
|
||||
|
||||
found := false
|
||||
_ = mtimefs.Walk("", func(path string, info FileInfo, err error) error {
|
||||
_ = walkFs.Walk("", func(path string, info FileInfo, err error) error {
|
||||
if path == "file" {
|
||||
found = true
|
||||
if !info.ModTime().Equal(newTime) {
|
||||
@@ -142,8 +142,8 @@ func TestMtimeFSOpen(t *testing.T) {
|
||||
}
|
||||
defer func() { _ = os.RemoveAll(dir) }()
|
||||
|
||||
underlying := NewFilesystem(FilesystemTypeBasic, dir)
|
||||
mtimefs := newMtimeFS(underlying, make(mapStore))
|
||||
mtimefs := newMtimeFS(dir, make(mapStore))
|
||||
underlying := mtimefs.Filesystem
|
||||
mtimefs.chtimes = failChtimes
|
||||
|
||||
if err := os.WriteFile(filepath.Join(dir, "file"), []byte("hello"), 0644); err != nil {
|
||||
@@ -222,12 +222,12 @@ func TestMtimeFSInsensitive(t *testing.T) {
|
||||
|
||||
// The test should fail with a case sensitive mtimefs
|
||||
t.Run("with case sensitive mtimefs", func(t *testing.T) {
|
||||
theTest(t, newMtimeFS(newBasicFilesystem("."), make(mapStore)), false)
|
||||
theTest(t, newMtimeFS(".", make(mapStore)), false)
|
||||
})
|
||||
|
||||
// And succeed with a case insensitive one.
|
||||
t.Run("with case insensitive mtimefs", func(t *testing.T) {
|
||||
theTest(t, newMtimeFS(newBasicFilesystem("."), make(mapStore), WithCaseInsensitivity(true)), true)
|
||||
theTest(t, newMtimeFS(".", make(mapStore), WithCaseInsensitivity(true)), true)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -261,6 +261,12 @@ func evilChtimes(name string, mtime, atime time.Time) error {
|
||||
return os.Chtimes(name, mtime.Add(300*time.Hour).Truncate(time.Hour), atime.Add(300*time.Hour).Truncate(time.Hour))
|
||||
}
|
||||
|
||||
func newMtimeFS(fs Filesystem, db database, options ...MtimeFSOption) *mtimeFS {
|
||||
return NewMtimeFS(fs, db, options...).(*mtimeFS)
|
||||
func newMtimeFS(path string, db database, options ...MtimeFSOption) *mtimeFS {
|
||||
mtimefs, _ := newMtimeFSWithWalk(path, db, options...)
|
||||
return mtimefs
|
||||
}
|
||||
|
||||
func newMtimeFSWithWalk(path string, db database, options ...MtimeFSOption) (*mtimeFS, *walkFilesystem) {
|
||||
wfs := NewFilesystem(FilesystemTypeBasic, path, NewMtimeOption(db, options...)).(*walkFilesystem)
|
||||
return wfs.Filesystem.(*mtimeFS), wfs
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user