简体   繁体   中英

Problems writing in archive using TrueZip and symbolic links

I use TrueZip (v 7.6.4) to write into a zip archive. 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. 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? If so, you probably need to include the Truezip-driver-zip dependency in your project. The maven repo for it is here. You don't need to import this into your project, but you need the dependency jar built into the project. If you aren't using maven, use whichever build process you have to include it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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