lib: Get rid of buggy filesystem wrapping (#8257)

This commit is contained in:
Simon Frei
2022-04-10 20:55:05 +02:00
committed by GitHub
parent 9b09bcc5f1
commit db72579f0e
26 changed files with 226 additions and 189 deletions
+16 -10
View File
@@ -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
}