Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extracting zip file containing symbolic links fails with exception in Windows due to insufficient permissions #278

Closed
maikelsteneker opened this issue Jan 21, 2021 · 5 comments
Assignees
Labels
new-feature New feature or request resolved

Comments

@maikelsteneker
Copy link

(Copied from Stack Overflow)

I'm using the zip4j library to extract a zip file containing symbolic links under Windows.

My code is as follows:

final String path = App.class.getResource("/file.zip").getPath();
final ZipFile zipFile = new ZipFile(path);
final Path tempDirectory = Files.createTempDirectory("tmp");
zipFile.extractAll(tempDirectory.toString());

(Minimal working example is available at https://github.com/maikelsteneker/zip4j-symlink)

This zip file contains a symbolic link. Creating such symbolic links requires Administrator rights in Windows. As a result, the following exception occurs:

Exception in thread "main" net.lingala.zip4j.exception.ZipException: java.nio.file.FileSystemException: C:\Users\Maikel\AppData\Local\Temp\tmp10742489646321434610\symlink.txt: A required privilege is not held by the client.

        at net.lingala.zip4j.tasks.AsyncZipTask.performTaskWithErrorHandling(AsyncZipTask.java:53)
        at net.lingala.zip4j.tasks.AsyncZipTask.execute(AsyncZipTask.java:40)
        at net.lingala.zip4j.ZipFile.extractAll(ZipFile.java:436)
        at zip4j.symlink.App.main(App.java:17)
Caused by: java.nio.file.FileSystemException: C:\Users\Maikel\AppData\Local\Temp\tmp10742489646321434610\symlink.txt: A required privilege is not held by the client.

        at java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:92)
        at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
        at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:108)
        at java.base/sun.nio.fs.WindowsFileSystemProvider.createSymbolicLink(WindowsFileSystemProvider.java:585)
        at java.base/java.nio.file.Files.createSymbolicLink(Files.java:1058)
        at net.lingala.zip4j.tasks.AbstractExtractFileTask.createSymLink(AbstractExtractFileTask.java:108)
        at net.lingala.zip4j.tasks.AbstractExtractFileTask.extractFile(AbstractExtractFileTask.java:61)
        at net.lingala.zip4j.tasks.ExtractAllFilesTask.executeTask(ExtractAllFilesTask.java:38)
        at net.lingala.zip4j.tasks.ExtractAllFilesTask.executeTask(ExtractAllFilesTask.java:16)
        at net.lingala.zip4j.tasks.AsyncZipTask.performTaskWithErrorHandling(AsyncZipTask.java:46)
        ... 3 more

I'd like to be able to use a custom error handler in order to ignore errors like this or otherwise exclude symbolic links from being extracted. If more input is necessary, I'd be happy to help. Given some pointers, I'd also be happy to prepare a pull request to enable functionality like this.

@srikanth-lingala
Copy link
Owner

I will add a feature to exclude symlinks.

@srikanth-lingala srikanth-lingala self-assigned this Jan 28, 2021
@srikanth-lingala srikanth-lingala added in-progress new-feature New feature or request labels Jan 28, 2021
@maikelsteneker
Copy link
Author

Great, thank you! I'm looking forward to it and would be happy to test or otherwise contribute.

@srikanth-lingala
Copy link
Owner

Feature is now implemented and I will include this in the next release. To skip extracting symlinks you can now set a flag in UnzipParameters which you can pass to any one of extract*() methods. For example:

UnzipParameters unzipParameters = new UnzipParameters();
unzipParameters.setExtractSymbolicLinks(false);
new ZipFile("test.zip").extractAll("/destinationPath/", unzipParameters);

@srikanth-lingala
Copy link
Owner

Feature added in v2.7.0 which was released today.

@maikelsteneker
Copy link
Author

This works perfectly. Thanks a lot for your efforts!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new-feature New feature or request resolved
Projects
None yet
Development

No branches or pull requests

2 participants