简体   繁体   English

使用 zip4j 在 Windows 中提取 zip 文件时,我可以跳过符号链接吗?

[英]Can I skip symbolic links when extracting a zipfile in Windows using zip4j?

I'm using the zip4j library to extract a zip file containing symbolic links under Windows.我正在使用zip4j库来提取 zip 文件,该文件包含 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 ) (最小的工作示例可在https://github.com/maikelsteneker/zip4j-symlink获得)

This zip file contains a symbolic link.这个 zip 文件包含一个符号链接。 Creating such symbolic links requires Administrator rights in Windows.创建此类符号链接需要 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

Is there a way to skip these symbolic links in order to avoid this exception?有没有办法跳过这些符号链接以避免这种异常? Ideally, I'd like to skip them only if these rights are not available (some users may have Administrator rights or have otherwise configured their system to allow the creation of symbolic links).理想情况下,我只想在这些权限不可用时跳过它们(某些用户可能具有管理员权限或以其他方式配置他们的系统以允许创建符号链接)。 I'm looking for an elegant solution;我正在寻找一个优雅的解决方案; I don't want to work around the library.我不想在图书馆附近工作。

The library doesn't seem to currently support such functionality.该库目前似乎不支持此类功能。 I'd recommend filing a bug/feature request .我建议提交错误/功能请求 You could suggest a custom error handler which allows ignoring certain errors or possibly a custom filter which allows choosing which files to extract on the fly.您可以建议一个允许忽略某些错误的自定义错误处理程序,或者可能是一个允许选择即时提取哪些文件的自定义过滤器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM