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

时间:2014-09-10 14:59:21

标签: java unix symlink truezip

我使用TrueZip(v 7.6.4)写入zip存档。我有一组像这样的文件夹:

> 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/

以下是代码:

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");

    }
}

第一次拨打writeInArchive的工作正常。后续调用(提供最后一个目录是符号链接的存档路径)引发以下异常:

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

1 个答案:

答案 0 :(得分:0)

您是否正在将TrueZip添加到现有项目中?如果是这样,您可能需要在项目中包含Truezip-driver-zip依赖项。 The maven repo for it is here.您不需要将其导入到项目中,但需要在项目中内置依赖关系jar。如果您不使用maven,请使用您必须包含的构建过程。