Return-Path: Delivered-To: apmail-commons-commits-archive@locus.apache.org Received: (qmail 77221 invoked from network); 7 Jan 2009 12:53:08 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 7 Jan 2009 12:53:08 -0000 Received: (qmail 15745 invoked by uid 500); 7 Jan 2009 12:53:06 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 15672 invoked by uid 500); 7 Jan 2009 12:53:06 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 15663 invoked by uid 99); 7 Jan 2009 12:53:06 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Jan 2009 04:53:06 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 07 Jan 2009 12:53:05 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 5704423888AF; Wed, 7 Jan 2009 04:52:45 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r732322 - in /commons/sandbox/compress/trunk/src: main/java/org/apache/commons/compress/archivers/tar/ test/java/org/apache/commons/compress/archivers/ Date: Wed, 07 Jan 2009 12:52:44 -0000 To: commits@commons.apache.org From: tcurdt@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090107125245.5704423888AF@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: tcurdt Date: Wed Jan 7 04:52:42 2009 New Revision: 732322 URL: http://svn.apache.org/viewvc?rev=732322&view=rev Log: applying patch from Christian Grobmeier https://issues.apache.org/jira/browse/SANDBOX-30 Modified: commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarOutputStream.java commons/sandbox/compress/trunk/src/test/java/org/apache/commons/compress/archivers/TarTestCase.java Modified: commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java URL: http://svn.apache.org/viewvc/commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java?rev=732322&r1=732321&r2=732322&view=diff ============================================================================== --- commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java (original) +++ commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java Wed Jan 7 04:52:42 2009 @@ -69,7 +69,7 @@ /** * The length of the name field in a header buffer. */ - public static final int NAMELEN = 100; + public static final int NAMELEN = 99; /** * The entry's modification time. Modified: commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarOutputStream.java URL: http://svn.apache.org/viewvc/commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarOutputStream.java?rev=732322&r1=732321&r2=732322&view=diff ============================================================================== --- commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarOutputStream.java (original) +++ commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarOutputStream.java Wed Jan 7 04:52:42 2009 @@ -217,13 +217,16 @@ * MUST be called to ensure that all buffered data is completely * written to the output stream. * + * The entry must be 0 terminated. Maximum filename is 99 chars, + * according to V7 specification. + * * @param entry The TarArchiveEntry to be written to the archive. * @exception IOException when an IO error causes operation to fail */ public void putNextEntry( final TarArchiveEntry entry ) throws IOException { - if( entry.getName().length() >= TarArchiveEntry.NAMELEN ) + if( entry.getName().length() > TarArchiveEntry.NAMELEN ) { if( m_longFileMode == LONGFILE_GNU ) { @@ -233,10 +236,10 @@ new TarArchiveEntry( TarConstants.GNU_LONGLINK, TarConstants.LF_GNUTYPE_LONGNAME ); - longLinkEntry.setSize( entry.getName().length() ); + longLinkEntry.setSize( entry.getName().length() + 1); putNextEntry( longLinkEntry ); write( entry.getName().getBytes() ); - //write( 0 ); + write( 0 ); closeEntry(); } else if( m_longFileMode != LONGFILE_TRUNCATE ) Modified: commons/sandbox/compress/trunk/src/test/java/org/apache/commons/compress/archivers/TarTestCase.java URL: http://svn.apache.org/viewvc/commons/sandbox/compress/trunk/src/test/java/org/apache/commons/compress/archivers/TarTestCase.java?rev=732322&r1=732321&r2=732322&view=diff ============================================================================== --- commons/sandbox/compress/trunk/src/test/java/org/apache/commons/compress/archivers/TarTestCase.java (original) +++ commons/sandbox/compress/trunk/src/test/java/org/apache/commons/compress/archivers/TarTestCase.java Wed Jan 7 04:52:42 2009 @@ -21,24 +21,22 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; +import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import junit.framework.TestCase; + import org.apache.commons.compress.AbstractTestCase; import org.apache.commons.compress.archivers.tar.TarArchiveEntry; import org.apache.commons.compress.utils.IOUtils; public final class TarTestCase extends AbstractTestCase { public void testTarArchiveCreation() throws Exception { - final File output = new File(dir, "bla.tar"); - final File file1 = new File(getClass().getClassLoader().getResource("test1.xml").getFile()); - final OutputStream out = new FileOutputStream(output); - final ArchiveOutputStream os = new ArchiveStreamFactory().createArchiveOutputStream("tar", out); - final TarArchiveEntry entry = new TarArchiveEntry("testdata/test1.xml"); entry.setModTime(0); entry.setSize(file1.length()); @@ -47,13 +45,58 @@ entry.setUserName("avalon"); entry.setGroupName("excalibur"); entry.setMode(0100000); - os.putArchiveEntry(entry); IOUtils.copy(new FileInputStream(file1), os); - os.closeArchiveEntry(); os.close(); } + + public void testTarArchiveLongNameCreation() throws Exception { + String name = "testdata/12345678901234567890123456789012345678901234567890123456789012345678901234567890123456.xml"; + byte[] bytes = name.getBytes(); + assertEquals(bytes.length, 99); + + final File output = new File(dir, "bla.tar"); + final File file1 = new File(getClass().getClassLoader().getResource("test1.xml").getFile()); + final OutputStream out = new FileOutputStream(output); + final ArchiveOutputStream os = new ArchiveStreamFactory().createArchiveOutputStream("tar", out); + final TarArchiveEntry entry = new TarArchiveEntry(name); + entry.setModTime(0); + entry.setSize(file1.length()); + entry.setUserID(0); + entry.setGroupID(0); + entry.setUserName("avalon"); + entry.setGroupName("excalibur"); + entry.setMode(0100000); + os.putArchiveEntry(entry); + IOUtils.copy(new FileInputStream(file1), os); + os.closeArchiveEntry(); + os.close(); + + + ArchiveOutputStream os2 = null; + try { + String toLongName = "testdata/123456789012345678901234567890123456789012345678901234567890123456789012345678901234567.xml"; + final File output2 = new File(dir, "bla.tar"); + final OutputStream out2 = new FileOutputStream(output2); + os2 = new ArchiveStreamFactory().createArchiveOutputStream("tar", out2); + final TarArchiveEntry entry2 = new TarArchiveEntry(toLongName); + entry2.setModTime(0); + entry2.setSize(file1.length()); + entry2.setUserID(0); + entry2.setGroupID(0); + entry2.setUserName("avalon"); + entry2.setGroupName("excalibur"); + entry2.setMode(0100000); + os.putArchiveEntry(entry); + IOUtils.copy(new FileInputStream(file1), os2); + } catch(IOException e) { + assertTrue(true); + } finally { + os2.closeArchiveEntry(); + } + } + public void testTarUnarchive() throws Exception { final File input = new File(getClass().getClassLoader().getResource("bla.tar").getFile()); final InputStream is = new FileInputStream(input);