You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.
I'm guessing the err = f.Format.Extract(f.context(), inputStream, filter, handler) call should be smarter to understand that if there are files listed with directories not represented in the dir list that they should have a implicitDirEntry{} entry stubbed in.
// ReadDir reads the named directory from within the archive.func (fArchiveFS) ReadDir(namestring) ([]fs.DirEntry, error) {
...handler:=func(_ context.Context, fileFile) error {
// directories may end with trailing slash; standardize nametrimmedName:=strings.Trim(file.NameInArchive, "/")
// don't include the named directory itself in the list of entriesiftrimmedName==name {
returnnil
}
// items added to an archive depth-first results in the subfolder entry being// added to the archive after all the files within it, meaning we won't have// the chance to return SkipDir before traversing into it; so we have to also// check if we are within a subfolder deeper than the requested name (because// this is a ReadDir function, we do not intend to traverse subfolders) (issue #310)// in other words, archive entries can be created out-of-(breadth-first)-order,// or even an arbitrary/random order, and we need to make sure we get all entries// in just this directoryifpath.Dir(trimmedName) !=name {
// additionally, some archive files don't have actual entries for folders,// leaving them to be inferred from the names of files instead (issue #330)// so as we traverse deeper, we need to implicitly find subfolders within// this current directory and add fake entries to the outputremainingPath:=strings.TrimPrefix(file.NameInArchive, name)
nextDir:=topDir(remainingPath) // if name in archive is "a/b/c" and root is "a", this becomes "b" (the implied folder to add)implicitDir:=path.Join(name, nextDir) // the full path of the implied directory// create fake entry only if no entry currently exists (don't overwrite a real entry)if_, ok:=entries[implicitDir]; !ok {
entries[implicitDir] =implicitDirEntry{implicitDir}
}
returnfs.SkipDir
}
entries[file.NameInArchive] =fs.FileInfoToDirEntry(file)
// don't traverse deeper into subfoldersiffile.IsDir() {
returnfs.SkipDir
}
returnnil
}
// handle special case of reading from root of archivevarfilter []stringifname!="." {
filter= []string{name}
}
varinputStream io.Reader=archiveFileiff.Stream!=nil {
inputStream=io.NewSectionReader(f.Stream, 0, f.Stream.Size())
}
err=f.Format.Extract(f.context(), inputStream, filter, handler)
iferr!=nil {
returnnil, err
}
...
}
Please link to any related issues, pull requests, and/or discussion
What version of the package or command are you using?
v4.0.0-alpha.7
What are you trying to do?
ArchiveFS.ReadDir
with a zip file that does not have explicit directory entries.unzip -l nodir-testassets.zip Archive: nodir-testassets.zip Length Date Time Name --------- ---------- ----- ---- 10 2022-06-04 05:25 index.html 12 2022-06-04 05:25 assets/1.txt 12 2022-06-04 05:25 assets/2.txt 7 2022-06-04 05:25 site.js 12 2022-06-08 06:50 weird #1.txt 10 2022-06-07 08:27 weird#.txt 10 2022-06-07 08:27 weird$.txt 17 2022-06-04 05:25 assets/more/3.txt 17 2022-06-04 05:25 assets/four/4.txt 20 2022-06-04 05:25 assets/fivesix/5.txt 20 2022-06-04 05:25 assets/fivesix/6.txt --------- ------- 147 11 files
Archiver works fine when there are explicit directory entries like:
What steps did you take?
ArchiveFS.ReadDir("assets")
This returns:
What did you expect to happen, and what actually happened instead?
ArchiveFS.ReadDir("assets")
Should Return
How do you think this should be fixed?
I'm guessing the
err = f.Format.Extract(f.context(), inputStream, filter, handler)
call should be smarter to understand that if there are files listed with directories not represented in the dir list that they should have aimplicitDirEntry{}
entry stubbed in.Please link to any related issues, pull requests, and/or discussion
jeremyje/gowebserver#64
You can trigger this problem by editing
xTestDirlessArchive
toTestDirlessArchive
. Then run the tests via:Bonus: What do you use archiver for, and do you find it useful?
http.FileSystem
to browse different archives and archive file nesting.The text was updated successfully, but these errors were encountered: