weichsel/ZIPFoundation

Unzipping a directory having a symlink that points to a non-existent file?

rrsum opened this issue · 2 comments

rrsum commented

When unzipping an archive of a directory having a symlink pointing to a non-existent file, the unzip creates the symlink, but the routine throws an error and no further unzipping is done.

To test, add two directories to /tmp: test and testcheck. In /tmp/test create the symlink nofile -> /nodir/nofile. Then perform, where fm is a file manager,

        try fm.zipItem(at: URL(fileURLWithPath: "/tmp/test"), to: URL(fileURLWithPath: "/tmp/test.zip"))
        try fm.unzipItem(at: URL(fileURLWithPath: "/tmp/test.zip"), to: URL(fileURLWithPath: "/tmp/testcheck"))

The zip works fine, but the unzip throws an error with "The file “nofile” doesn’t exist." However the link is actually there, but the throw stops the execution.

Is this the intended outcome? This is important because I use swift to create web pages that are moved to a web server where the symlinks make sense.

Is this the intended outcome?

No, I think this is a bug.
I assume the code throws not during link creation, but when trying to restore file attributes from the archive to the non-existent symlink destination? Can you share a sample archive?

While this is not strictly the same issue, I'll close it as duplicate of #185

The underlying issue is the same:

  • We currently don't properly handle symlinks for non-existant destinations
  • File System attribute restoration is always performed (even when not possible)
rrsum commented

Well, the simplest one is as indicated in my original post:

Create dirs: /tmp/test, /tmp/testcheck
cd /tmp/test
ln -s /nodir/nofile nofile

Then run

try fm.zipItem(at: URL(fileURLWithPath: "/tmp/test"), to: URL(fileURLWithPath: /tmp/test.zip"))

This creates /tmp/test.zip, which as near as I can tell, is valid, and since all the urls are absolute, the current path is irrelevant..

Hope this helps,

Rick