0

I'm trying to create a 'valid' tar.gz archive by using the apache commons compress librarys. The created archive will be read by an embedded device and has to be in the same format with the same file permissions i think.

If i'm using Linux to create my file, everything works fine, but if i'm using Windows. The file is rejected.

As you can see, the archive only contains to special files with unix permissions. these are correctly set and if i use a "working" tar file and run it through gzip, the created tar.gz also works fine.

The only difference i figured out is, that the non-working tar file is slightly larger (61 instead of 56 kb) and 7zip shows under "Host OS" FAT instead of Unix.

Any ideas, how i can create a "real" tar archive from Windows?

Thanks in advance!

My current sourcecode is:

public static void compress(File configTar, File rcConf, File databaseTxt)
        throws ArchiveException, IOException {

    OutputStream tarFileStream = new GZIPOutputStream(new FileOutputStream(configTar));
    InputStream rcConfStream = new FileInputStream(rcConf);
    InputStream databaseTxtStream = new FileInputStream(databaseTxt);

    ArchiveOutputStream archiveOutputStream = new ArchiveStreamFactory()
            .createArchiveOutputStream(ArchiveStreamFactory.TAR, tarFileStream);

    TarArchiveEntry databaseTxtEntry = new TarArchiveEntry(databaseTxt);
    TarArchiveEntry rcConfEntry = new TarArchiveEntry(rcConf);

    databaseTxtEntry.setName("database.txt");
    databaseTxtEntry.setGroupName("root");
    databaseTxtEntry.setUserName("root");
    databaseTxtEntry.setMode(convertModeFromString("rwxr-xr-x"));

    archiveOutputStream.putArchiveEntry(databaseTxtEntry);
    IOUtils.copy(databaseTxtStream, archiveOutputStream);
    archiveOutputStream.closeArchiveEntry();

    rcConfEntry.setName("rc.conf");
    rcConfEntry.setGroupName("root");
    rcConfEntry.setUserName("root");
    rcConfEntry.setMode(convertModeFromString("rw-rw-rw-"));

    archiveOutputStream.putArchiveEntry(rcConfEntry);
    IOUtils.copy(rcConfStream, archiveOutputStream);
    archiveOutputStream.closeArchiveEntry();

    archiveOutputStream.finish();

    rcConfStream.close();
    databaseTxtStream.close();
    tarFileStream.close();
}

I've done some research and noticed a difference between the TAR headers. Can anybody tell, what i am doing wrong?

Working example of file 1:
   http://i.stack.imgur.com/S8Rbi.jpg

NON-Working example of file 1:
   http://i.stack.imgur.com/bdc9T.jpg

Working example of file 2:
   http://i.stack.imgur.com/rYhr9.jpg

NON-Working example of file 2:
   http://i.stack.imgur.com/4wHw3.jpg
4

1 回答 1

0

您需要使用不同的构造函数。我检查 JavaCode TarArchiveEntry

new TarArchiveEntry(file)最终会变成new TarArchiveEntry(file, file.getPath())

所以,如果你使用new TarArchiveEntry(file, file.getName())它会使它变平

于 2014-11-17T18:51:20.460 回答