简体   繁体   English

使用TrueZip和符号链接在存档中写入时出现问题

[英]Problems writing in archive using TrueZip and symbolic links

I use TrueZip (v 7.6.4) to write into a zip archive. 我使用TrueZip(v 7.6.4)写入zip存档。 I have a set of folders like this: 我有一组这样的文件夹:

> ls -l /home/remi
drwxr-xr-x  2 remi remi  4096 sept. 10 16:49 testtz
drwxr-xr-x  2 remi remi  4096 sept. 10 16:49 symlinktarget
lrwxrwxrwx  1 remi remi    14 sept. 10 16:47 symlink -> symlinktarget/
> ls -l /home/remi/testtz
lrwxrwxrwx 1 remi remi 25 sept. 10 16:47 symlink -> /home/remi/symlinktarget/

Here is the code: 这是代码:

package com.tests.forstackoverflow.truezip;

import java.io.File;
import java.io.Writer;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import de.schlichtherle.truezip.file.TFile;
import de.schlichtherle.truezip.file.TFileWriter;
import de.schlichtherle.truezip.file.TVFS;
import de.schlichtherle.truezip.fs.FsSyncException;

public class TestTz
{
    Logger logger = LoggerFactory.getLogger(getClass());

    public void writeInArchive(String archiveName)
    {
        final File f = new TFile(new File(archiveName) + "/hello.txt");
        try (Writer writer = new TFileWriter(f))
        {
            writer.write("Hello World!\n");
        }
        catch(Exception e)
        {
            logger.error("Exception raised:", e);
        }
        try { TVFS.umount(); } catch(FsSyncException e) { logger.error("umount error", e); }
    }

    public static void main(String args[])
    {
        TestTz test = new TestTz();

        test.writeInArchive("/home/remi/testtz/hello.zip");

        test.writeInArchive("/home/remi/symlink/hello.zip");

        test.writeInArchive("/home/remi/testtz/symlink/hello2.zip");

    }
}

First call to writeInArchive works fine. 第一次调用writeInArchive可以正常工作。 The subsequent calls (which gives an archive path where the last directory is a symbolic link) raise the following exception: 后续调用(提供最后一个目录为符号链接的归档路径)引发以下异常:

sept. 10, 2014 4:49:55 PM com.tests.forstackoverflow.truezip.TestTz writeInArchive
Grave: Exception raised:
java.io.FileNotFoundException: /home/remi/symlink/hello.zip/hello.txt
    at de.schlichtherle.truezip.file.TFileOutputStream.newOutputStream(TFileOutputStream.java:147)
    at de.schlichtherle.truezip.file.TFileOutputStream.<init>(TFileOutputStream.java:116)
    at de.schlichtherle.truezip.file.TFileWriter.<init>(TFileWriter.java:42)
    at com.tests.forstackoverflow.truezip.TestTz.writeInArchive(TestTz.java:21)
    at com.tests.forstackoverflow.truezip.TestTz.main(TestTz.java:38)
Caused by: java.nio.file.FileAlreadyExistsException: /home/remi/symlink
    at sun.nio.fs.UnixException.translateToIOException(UnixException.java:88)
    at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
    at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
    at sun.nio.fs.UnixFileSystemProvider.createDirectory(UnixFileSystemProvider.java:383)
    at java.nio.file.Files.createDirectory(Files.java:628)
    at java.nio.file.Files.createAndCheckIsDirectory(Files.java:732)
    at java.nio.file.Files.createDirectories(Files.java:681)
    at de.schlichtherle.truezip.fs.nio.file.FileOutputSocket.begin(FileOutputSocket.java:97)
    at de.schlichtherle.truezip.fs.nio.file.FileOutputSocket.newOutputStream(FileOutputSocket.java:211)
    at de.schlichtherle.truezip.fs.archive.zip.OptionOutputSocket.newOutputStream(OptionOutputSocket.java:48)
    at de.schlichtherle.truezip.fs.archive.zip.ZipDriver.newOutputShop(ZipDriver.java:589)
    at de.schlichtherle.truezip.fs.archive.zip.ZipDriver.newOutputShop0(ZipDriver.java:579)
    at de.schlichtherle.truezip.fs.archive.zip.ZipDriver.newOutputShop(ZipDriver.java:564)
    at de.schlichtherle.truezip.fs.FsTargetArchiveController.makeOutputArchive(FsTargetArchiveController.java:247)
    at de.schlichtherle.truezip.fs.FsTargetArchiveController.mount0(FsTargetArchiveController.java:182)
    at de.schlichtherle.truezip.fs.FsTargetArchiveController.mount(FsTargetArchiveController.java:155)
    at de.schlichtherle.truezip.fs.FsFileSystemArchiveController$ResetFileSystem.autoMount(FsFileSystemArchiveController.java:85)
    at de.schlichtherle.truezip.fs.FsFileSystemArchiveController.autoMount(FsFileSystemArchiveController.java:37)
    at de.schlichtherle.truezip.fs.FsBasicArchiveController$1Output.mknod(FsBasicArchiveController.java:273)
    at de.schlichtherle.truezip.fs.FsBasicArchiveController$1Output.newOutputStream(FsBasicArchiveController.java:233)
    at de.schlichtherle.truezip.fs.FsContextController$Output.newOutputStream(FsContextController.java:322)
    at de.schlichtherle.truezip.fs.FsResourceController$Output.newOutputStream(FsResourceController.java:273)
    at de.schlichtherle.truezip.socket.DelegatingOutputSocket.newOutputStream(DelegatingOutputSocket.java:57)
    at de.schlichtherle.truezip.fs.FsSyncController$Output.newOutputStream(FsSyncController.java:432)
    at de.schlichtherle.truezip.fs.FsLockController$Output$1NewOutputStream.call(FsLockController.java:509)
    at de.schlichtherle.truezip.fs.FsLockController$Output$1NewOutputStream.call(FsLockController.java:506)
    at de.schlichtherle.truezip.fs.FsLockController.locked(FsLockController.java:328)
    at de.schlichtherle.truezip.fs.FsLockController.writeLocked(FsLockController.java:268)
    at de.schlichtherle.truezip.fs.FsLockController$Output.newOutputStream(FsLockController.java:513)
    at de.schlichtherle.truezip.fs.FsFinalizeController$Output.newOutputStream(FsFinalizeController.java:209)
    at de.schlichtherle.truezip.fs.FsFalsePositiveArchiveController$1Output$NewOutputStream.call(FsFalsePositiveArchiveController.java:409)
    at de.schlichtherle.truezip.fs.FsFalsePositiveArchiveController$1Output$NewOutputStream.call(FsFalsePositiveArchiveController.java:402)
    at de.schlichtherle.truezip.fs.FsFalsePositiveArchiveController$TryChild.call(FsFalsePositiveArchiveController.java:507)
    at de.schlichtherle.truezip.fs.FsFalsePositiveArchiveController.call(FsFalsePositiveArchiveController.java:104)
    at de.schlichtherle.truezip.fs.FsFalsePositiveArchiveController$1Output.newOutputStream(FsFalsePositiveArchiveController.java:399)
    at de.schlichtherle.truezip.file.TFileOutputStream.newOutputStream(TFileOutputStream.java:143)
    ... 4 more

Are you adding TrueZip to an existing projecT? 您要将TrueZip添加到现有项目中吗? If so, you probably need to include the Truezip-driver-zip dependency in your project. 如果是这样,您可能需要在项目中包括Truezip-driver-zip依赖项。 The maven repo for it is here. Maven的回购在这里。 You don't need to import this into your project, but you need the dependency jar built into the project. 您不需要将其导入到项目中,但是需要将依赖项jar内置到项目中。 If you aren't using maven, use whichever build process you have to include it. 如果您不使用Maven,请使用必须包含它的任何构建过程。

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

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