You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Rico Harnisch <ad...@xenios-net.de> on 2013/01/27 16:49:15 UTC

[compress] Problem adding files with file names longer than 100 chars to tar-stream though LONGFILE_POSIX is enabled

Hello,

I tried to write the following two files to a TarArchiveOutputStream, I 
have the option LONGFILE_POSIX enabled. The two files listed are the 
only ones that should  be written to the output stream.

/Desktop/Downloads/mplayer-checkout-2012-02-29/tests/ref/cyberia-c93/.svn/text-base/intro1.c93.md5.svn-base
/Desktop/Downloads/mplayer-checkout-2012-02-29/tests/ref/tiertex-seq/.svn/text-base/Gameover.seq.md5.svn-base

Normally, I would expect the archiver to handle file names longer than 
100 chars if LONGFILE_POSIX is enabled, but I get the following error 
message

java.io.IOException: request to write '117' bytes exceeds size in header 
of '0' bytes for entry 
'./PaxHeaders.X//Desktop/Downloads/mplayer-checkout-2012-02-29/tests/ref/cyberia-c93/.svn/text-base/'
     at 
org.apache.commons.compress.archivers.tar.TarArchiveOutputStream.write(TarArchiveOutputStream.java:385)
     at java.io.OutputStream.write(OutputStream.java:58)
     at 
org.apache.commons.compress.archivers.tar.TarArchiveOutputStream.writePaxHeaders(TarArchiveOutputStream.java:485)
     at 
org.apache.commons.compress.archivers.tar.TarArchiveOutputStream.putArchiveEntry(TarArchiveOutputStream.java:312)
     at 
target.fileBackupTarget.FileBackupTarget.writeFile(FileBackupTarget.java:209)
     at jbackup.JBackup.performBackup(JBackup.java:319)
     at jbackup.GUI$1.run(GUI.java:287)

for the first file and a similar one for the second file. If I set the 
longfile option to LONGFILE_TRUNCATE the problem does not appear and the 
two files are added to the tar archive as expected with truncated file 
names.

Here is a code-snippet of the usage of the TarArchiveOutputStream in my 
project:

File targetFile;
File source;
long fileLength = source.length();
int bufferSize = 1024;
byte[] buffer = new byte[bufferSize];

sout = new TarArchiveOutputStream(new FileOutputStream(targetFile));
((TarArchiveOutputStream) 
sout).setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_POSIX);
((TarArchiveOutputStream) 
sout).setLongFileMode(TarArchiveOutputStream.LONGFILE_POSIX);

((TarArchiveOutputStream) sout).putArchiveEntry(new 
TarArchiveEntry(source, source.toString()));

long numberOfPackages = (long) Math.floor(fileLength / (bufferSize));

for (long i = 0; i < numberOfPackages; i++) {
         in.read(buffer);
         sout.write(buffer);
}
for (long i = numberOfPackages * (bufferSize); i < fileLength; i++) {
         sout.write(in.read());
}
((TarArchiveOutputStream) sout).closeArchiveEntry();

Is there any error I made using the tar stream? Thank you for your help.

Best regards
Rico Harnisch


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [compress] Problem adding files with file names longer than 100 chars to tar-stream though LONGFILE_POSIX is enabled

Posted by Stefan Bodewig <bo...@apache.org>.
On 2013-01-27, Rico Harnisch wrote:

> I tried to write the following two files to a TarArchiveOutputStream,
> I have the option LONGFILE_POSIX enabled. The two files listed are the
> only ones that should  be written to the output stream.

> /Desktop/Downloads/mplayer-checkout-2012-02-29/tests/ref/cyberia-c93/.svn/text-base/intro1.c93.md5.svn-base
> /Desktop/Downloads/mplayer-checkout-2012-02-29/tests/ref/tiertex-seq/.svn/text-base/Gameover.seq.md5.svn-base

> Normally, I would expect the archiver to handle file names longer than
> 100 chars if LONGFILE_POSIX is enabled, but I get the following error
> message

> java.io.IOException: request to write '117' bytes exceeds size in
> header of '0' bytes for entry

You've likely run into COMPRESS-203 [1] which has been fixed in svn
about a month ago.  The ./PaxHeaders.X entry holding your filename has
been truncated to 100 chars and now ends with a slash - which triggers
the bug.

Apart from building Compress yourself or using a snapshot release[2]
playing with the directory names in between might be an option (so the
100th char is not a slash).

We haven't discussed doing a new release, yet, but it is on my
short-term TODO list.

Stefan

[1] https://issues.apache.org/jira/browse/COMPRESS-203
[2] https://repository.apache.org/content/groups/snapshots/org/apache/commons/commons-compress/1.5-SNAPSHOT/

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org