ArchiveFS.Open returns the first file in an implicit directory rather than a fs.ReadDirFile
jeremyje opened this issue · 1 comments
jeremyje commented
What version of the package or command are you using?
v4.0.0-alpha.7
What are you trying to do?
ArchiveFS.Open()
with a zip file that does not have explicit directory entries.
What steps did you take?
Adding a disabled test to showcase the bug via #339.
When you run the tests you'll get the following output.
$ go test ./...
--- FAIL: TestArchiveFS_ReadDir (0.00s)
--- FAIL: TestArchiveFS_ReadDir/nodir.zip (0.00s)
--- FAIL: TestArchiveFS_ReadDir/nodir.zip/Open(cmd) (0.00s)
fs_test.go:136: 'cmd' did not return a fs.ReadDirFile, <nil>
--- FAIL: TestArchiveFS_ReadDir/nodir.zip/Open(.github) (0.00s)
fs_test.go:136: '.github' did not return a fs.ReadDirFile, <nil>
FAIL
FAIL github.com/mholt/archiver/v4 0.064s
? github.com/mholt/archiver/v4/cmd/arc [no test files]
FAIL
Subtest of TestArchiveFS_ReadDir
that reproduces this issue:
// Uncomment to reproduce https://github.com/mholt/archiver/issues/340.
t.Run(fmt.Sprintf("Open(%s)", baseDir), func(t *testing.T) {
f, err := fsys.Open(baseDir)
if err != nil {
t.Error(err)
}
rdf, ok := f.(fs.ReadDirFile)
if !ok {
t.Fatalf("'%s' did not return a fs.ReadDirFile, %+v", baseDir, rdf)
}
dis, err := rdf.ReadDir(-1)
if err != nil {
t.Fatal(err)
}
dirs := []string{}
for _, di := range dis {
dirs = append(dirs, di.Name())
}
// Stabilize the sort order
sort.Strings(dirs)
if diff := cmp.Diff(wantLS, dirs); diff != "" {
t.Errorf("Open().ReadDir(-1) mismatch (-want +got):\n%s", diff)
}
})
What did you expect to happen, and what actually happened instead?
For ArchiveFS.Open() will return the first file with that directory prefix.
How do you think this should be fixed?
ArchiveFS.Open(<directory>)
to return an fs.ReadDirFile
probably in the concrete form of dirFile
.
Please link to any related issues, pull requests, and/or discussion
Bonus: What do you use archiver for, and do you find it useful?
mholt commented
Thanks, I will need to find a moment to look into this