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 @@
      * <B>MUST</B> 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);


Reply via email to