ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From co...@apache.org
Subject cvs commit: ant/src/main/org/apache/tools/tar TarInputStream.java
Date Wed, 06 Aug 2003 15:15:27 GMT
conor       2003/08/06 08:15:27

  Modified:    src/main/org/apache/tools/tar TarInputStream.java
  Added:       src/testcases/org/apache/tools/tar TarRoundTripTest.java
  Log:
  Fix extraction of long file names in Tar
  
  PR:	15230
  Submitted by:	J. David Beutel
  
  Revision  Changes    Path
  1.1                  ant/src/testcases/org/apache/tools/tar/TarRoundTripTest.java
  
  Index: TarRoundTripTest.java
  ===================================================================
  package org.apache.tools.tar;
  
  import java.io.IOException;
  import java.io.ByteArrayOutputStream;
  import junit.framework.TestCase;
  
  public class TarRoundTripTest extends TestCase {
  
      private static final String LONG_NAME
          = "this/path/name/contains/more/than/one/hundred/characters/in/order/"
              + "to/test/the/GNU/long/file/name/capability/round/tripped";
  
      public TarRoundTripTest(String name) {
          super(name);
      }
  
      /**
       * test round-tripping long (GNU) entries
       */
      public void testLongRoundTripping() throws IOException {
          TarEntry original = new TarEntry(LONG_NAME);
          assertEquals("over 100 chars", true, LONG_NAME.length() > 100);
          assertEquals("original name", LONG_NAME, original.getName());
  
  
          ByteArrayOutputStream buff = new ByteArrayOutputStream();
          TarOutputStream tos = new TarOutputStream(buff);
          tos.setLongFileMode(TarOutputStream.LONGFILE_GNU);
          tos.putNextEntry(original);
          tos.closeEntry();
          tos.close();
  
          TarInputStream tis
              = new TarInputStream(new ByteArrayInputStream(buff.toByteArray()));
          TarEntry tripped = tis.getNextEntry();
          assertEquals("round-tripped name", LONG_NAME, tripped.getName());
          assertNull("no more entries", tis.getNextEntry());
          tis.close();
      }
  }
  
  
  
  
  
  1.11      +6 -0      ant/src/main/org/apache/tools/tar/TarInputStream.java
  
  Index: TarInputStream.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/tar/TarInputStream.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -w -u -r1.10 -r1.11
  --- TarInputStream.java	19 Jul 2003 11:20:23 -0000	1.10
  +++ TarInputStream.java	6 Aug 2003 15:15:27 -0000	1.11
  @@ -275,6 +275,12 @@
                   longName.append(new String(buffer, 0, length));
               }
               getNextEntry();
  +
  +            // remove trailing null terminator
  +            if (longName.length() > 0
  +                && longName.charAt(longName.length() - 1) == 0) {
  +                longName.deleteCharAt(longName.length() - 1);
  +            }
               this.currEntry.setName(longName.toString());
           }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message