Open ForNeVeR opened 1 year ago
Zip listing strange but resulting zip-archive is correct.
It depends on your definition of "correct".
It depends on your definition of "correct".
Look at uzip. And unzipping as expected:
7z x file.zip
$ (dir ./pt -Recurse).FullName
/home/herz/Desktop/pt/fspt
/home/herz/Desktop/pt/fspt/d
/home/herz/Desktop/pt/fspt/d/file.txt
Perhaps this is a compression algorithm when empty directories are "merged" with a file.
If your definition of "correct" is "whatever 7zip works with", then yes, it is correct.
It is not correct w.r.t. every interop scenario, though.
In particular, java.util.zip.ZipEntry::isDirectory
has problems with such an archive: it reports directory entries to be files, which breaks things.
Though, after taking a closer look, I see that it only has problems with an archive created by Windows PowerShell 5.1, not PowerShell 7.3: it's the kind of the final slash that turns out to be important for it[^1]. Not the flags reported by zipinfo
.
The logic of creating directory entries only for directories of certain nesting level and with no files still looks kinda weird.
Notably, the version from the master
branch doesn't have this strange logic: it creates a new entry for every directory it seems.
[^1]: Not sure I mentioned that fact above, but the only notable difference between archives created by pwsh 5.1 and pwsh 7.3 is that 7.3 generated paths inside archives separated with /
(even on Windows), while pwsh 5.1 separates paths with \
.
If your definition of "correct" is "whatever 7zip works with", then yes, it is correct.
Yes. file-roller, unzip, 7-zip, mc and Far plugins. All of them extract file.zip without errors.I can't test the other archivers.
Prerequisites
Steps to reproduce
Sometimes,
Compress-Archive
creates a weird directory-like entry in the produced archive. The details I was able to find:Compress-Archive
will create a ZIP entry called<yourDirectoryName>/
not marked as directory according to the output ofzipinfo
So, exact steps to reproduce:
Now, examine the resulting archive using
zipinfo
(I wasn't able to quickly find azipinfo
distribution for Windows, so installedsudo apt install unzip
on my Ubuntu into WSL):The weird path is the first entry:
Notably, the weird entry goes away if I create a file in directory
pt/fspt
:I've seen two kinds of other archives:
drwxr-xr-x
flags instead of-rw----
.At the same time,
[System.IO.Compression.ZipFile]::CreateFromDirectory
works well:So,
System.IO.Compression.ZipFile]::CreateFromDirectory
doesn't have this problem.For empty directory, it will still create an entry with
-rw----
flags, though, so it is not without problems.Expected behavior
I'd say that
Compress-Archive
should work the same way asSystem.IO.Compression.ZipFile]::CreateFromDirectory
.Actual behavior
Compress-Archive
behaves differently fromSystem.IO.Compression.ZipFile]::CreateFromDirectory
, and in a very strange way that is.Environment data
The issue reproduces in both Windows PowerShell 5.1 and PowerShell 7.3.