fs/reader: fix open+stat handling

This commit is contained in:
Michael Eischer 2025-04-11 21:49:25 +02:00
parent 19f48084ea
commit 70e1037a49
2 changed files with 23 additions and 10 deletions

View File

@ -128,6 +128,9 @@ func (fs *Reader) OpenFile(name string, flag int, _ bool) (f File, err error) {
} }
f = fakeDir{ f = fakeDir{
fakeFile: fakeFile{
fi: item.fi,
},
entries: slices.Clone(item.children), entries: slices.Clone(item.children),
} }
return f, nil return f, nil

View File

@ -183,28 +183,38 @@ func createDirTest(fpath string, now time.Time) fsTest {
{ {
name: "dir/Open-slash-" + fpath, name: "dir/Open-slash-" + fpath,
f: func(t *testing.T, fs FS) { f: func(t *testing.T, fs FS) {
fi, err := fs.Lstat("/" + fpath) fi := fsStatDir(t, fs, "/"+fpath)
if err != nil {
t.Fatal(err)
}
checkFileInfo(t, fi, "/"+fpath, now, os.ModeDir|0755, true) checkFileInfo(t, fi, "/"+fpath, now, os.ModeDir|0755, true)
}, },
}, },
{ {
name: "dir/Open-current-" + fpath, name: "dir/Open-current-" + fpath,
f: func(t *testing.T, fs FS) { f: func(t *testing.T, fs FS) {
fi, err := fs.Lstat("./" + fpath) fi := fsStatDir(t, fs, "./"+fpath)
if err != nil {
t.Fatal(err)
}
checkFileInfo(t, fi, "/"+fpath, now, os.ModeDir|0755, true) checkFileInfo(t, fi, "/"+fpath, now, os.ModeDir|0755, true)
}, },
}, },
} }
} }
func fsStatDir(t *testing.T, fs FS, fpath string) *ExtendedFileInfo {
f, err := fs.OpenFile(fpath, O_RDONLY, false)
if err != nil {
t.Fatal(err)
}
fi, err := f.Stat()
if err != nil {
t.Fatal(err)
}
err = f.Close()
if err != nil {
t.Fatal(err)
}
return fi
}
func TestFSReader(t *testing.T) { func TestFSReader(t *testing.T) {
data := test.Random(55, 1<<18+588) data := test.Random(55, 1<<18+588)
now := time.Now() now := time.Now()