Skip to content

Commit a6166fa

Browse files
committed
Amortize implicit dirs too; fix skipped entries in subsequent walks
1 parent 9132adf commit a6166fa

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

fs.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ func (f *ArchiveFS) ReadDir(name string) ([]fs.DirEntry, error) {
640640
return &fs.PathError{Op: "readdir", Path: name, Err: errors.New("not a directory")}
641641
}
642642

643-
// index this file info for quick access
643+
// index this file info for quick access (overwrite any implicit one that may have been created)
644644
f.contents[file.NameInArchive] = file
645645

646646
// amortize the DirEntry list per directory, and prefer the real entry's DirEntry over an implicit/fake
@@ -682,6 +682,16 @@ func (f *ArchiveFS) ReadDir(name string) ([]fs.DirEntry, error) {
682682
if !found {
683683
f.dirs[dir] = slices.Insert(f.dirs[dir], idx, dirInfo)
684684
}
685+
686+
// we also need to treat implicit directories as real ones for the sake of FS traversal,
687+
// so be sure to add to our amortization cache an implicit FileInfo for each parent dir
688+
// that doesn't have an explicit entry in the archive; this will get overwritten with
689+
// a real one if we encounter it, but without filling in the implied directory tree,
690+
// FS walks *after the first one* (the first one doesn't use the contents cache) will
691+
// omit all implicit directories from their walk, missing many contents!
692+
if _, ok := f.contents[dir]; !ok {
693+
f.contents[dir] = dirInfo.(fs.FileInfo)
694+
}
685695
}
686696

687697
return nil

0 commit comments

Comments
 (0)