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
Symlinks to directories are placed in the wrong locations.
For example, I have a directory named a, and a symlink pointing to it named b (b -> a), and they are put in the same root directory.
When I use zip4j to compress the root directory by calling params.setSymbolicLinkAction(INCLUDE_LINK_ONLY) and zip.addFolder(dirFile, params), the symlink b is placed at a/b.
I discovered this problem when I was trying to pack a symlink file node_modules/log-facade -> ../app/log, the unzip result is node_modules/log/log-facade -> ../app/log, where log-facade is replaced with the pointing directory's name log and created as a directory, and log-facade symlink is placed inside the log/ directory.
Details
click to reveal
Construct a directory structure:
mkdir test-zip
cd test-zip
mkdir a
echo "xx" > a/x
ln -s a b
mkdir c
echo "dd" > c/d
mkdir e
ln -s '../c/d' e/f
cd ../
The tree result would be (please ignore the testing .java,.jar,.class files):
.
├── Main.class
├── Main.java
├── test-zip
│ ├── a
│ │ └── x
│ ├── b -> a
│ ├── c
│ │ └── d
│ └── e
│ └── f -> ../c/d
└── zip4j-2.11.5.jar
5 directories, 6 files
You can test their validity by cat test-zip/b/x and cat test-zip/e/f
results of zip command
Run: zip --symlinks -r test-zip.zip ./test-zip
Move the test-zip.zip somewhere else and run unzip test-zip.zip, I can get the output:
If the file is a symlink, then the getCanonicalFile() will return the pointing directory/file's File instead of the symbolic file's own File, so the getCanonicalFile().getName() returns the pointing directory/file's name.
So, for symlinks pointing to directories, the code will silently put them to the wrong location.
As for symlinks to files, the rootPath will also be incorrect, but in the code addSymlinkToZip it calls replaceFileNameInZip, which trims the filename, and appends the symlink's file name, which eventually will be correct.
This doesn't fix the wrong location of directories' symlinks because they have a trailing /.
Also, there will always be an additional directory for symlinks to directories, because the code shows that the symlink's name will always be appended.
I hope this could be fixed.
The text was updated successfully, but these errors were encountered:
Abstract
Symlinks to directories are placed in the wrong locations.
For example, I have a directory named
a
, and a symlink pointing to it namedb
(b -> a
), and they are put in the same root directory.When I use
zip4j
to compress the root directory by callingparams.setSymbolicLinkAction(INCLUDE_LINK_ONLY)
andzip.addFolder(dirFile, params)
, the symlinkb
is placed ata/b
.I discovered this problem when I was trying to pack a symlink file
node_modules/log-facade -> ../app/log
, theunzip
result isnode_modules/log/log-facade -> ../app/log
, wherelog-facade
is replaced with the pointing directory's namelog
and created as a directory, andlog-facade
symlink is placed inside thelog/
directory.Details
click to reveal
Construct a directory structure:
The
tree
result would be (please ignore the testing.java,.jar,.class
files):You can test their validity by
cat test-zip/b/x
andcat test-zip/e/f
results of
zip
commandRun:
zip --symlinks -r test-zip.zip ./test-zip
Move the
test-zip.zip
somewhere else and rununzip test-zip.zip
, I can get the output:and
tree
output:results of
zip4j
Run:
unzip
result:tree
output:Some debug into the code
In FileUtils.java#L221, it says:
If the file is a symlink, then the
getCanonicalFile()
will return the pointing directory/file'sFile
instead of the symbolic file's ownFile
, so thegetCanonicalFile().getName()
returns the pointing directory/file's name.So, for symlinks pointing to directories, the code will silently put them to the wrong location.
As for symlinks to files, the
rootPath
will also be incorrect, but in the codeaddSymlinkToZip
it callsreplaceFileNameInZip
, which trims the filename, and appends the symlink's file name, which eventually will be correct.This doesn't fix the wrong location of directories' symlinks because they have a trailing
/
.Also, there will always be an additional directory for symlinks to directories, because the code shows that the symlink's name will always be appended.
I hope this could be fixed.
The text was updated successfully, but these errors were encountered: