commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1427488 - in /commons/proper/compress/trunk/src: changes/changes.xml main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java test/java/org/apache/commons/compress/archivers/tar/TarArchiveEntryTest.java
Date Tue, 01 Jan 2013 17:30:48 GMT
Author: bodewig
Date: Tue Jan  1 17:30:48 2013
New Revision: 1427488

URL: http://svn.apache.org/viewvc?rev=1427488&view=rev
Log:
COMPRESS-201 add an additional convenience constructor to TarArchiveEntry

Modified:
    commons/proper/compress/trunk/src/changes/changes.xml
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java
    commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveEntryTest.java

Modified: commons/proper/compress/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/changes/changes.xml?rev=1427488&r1=1427487&r2=1427488&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/changes/changes.xml (original)
+++ commons/proper/compress/trunk/src/changes/changes.xml Tue Jan  1 17:30:48 2013
@@ -95,6 +95,10 @@ The <action> type attribute can be add,u
         when the archiver was willing to split the archive but in the
         end only needed a single segment - so didn't split anything. 
       </action>
+      <action type="update" date="2013-01-01" issue="COMPRESS-201">
+        TarArchiveEntry has a new constructor that allows setting
+        linkFlag and preserveLeadingSlashes at the same time.
+      </action>
     </release>
     <release version="1.4.1" date="2012-05-23"
              description="Release 1.4.1">

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java?rev=1427488&r1=1427487&r2=1427488&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java
Tue Jan  1 17:30:48 2013
@@ -233,7 +233,21 @@ public class TarArchiveEntry implements 
      * @param linkFlag the entry link flag.
      */
     public TarArchiveEntry(String name, byte linkFlag) {
-        this(name);
+        this(name, linkFlag, false);
+    }
+
+    /**
+     * Construct an entry with a name and a link flag.
+     *
+     * @param name the entry name
+     * @param linkFlag the entry link flag.
+     * @param preserveLeadingSlashes whether to allow leading slashes
+     * in the name.
+     * 
+     * @since 1.5
+     */
+    public TarArchiveEntry(String name, byte linkFlag, boolean preserveLeadingSlashes) {
+        this(name, preserveLeadingSlashes);
         this.linkFlag = linkFlag;
         if (linkFlag == LF_GNUTYPE_LONGNAME) {
             magic = MAGIC_GNU;

Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveEntryTest.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveEntryTest.java?rev=1427488&r1=1427487&r2=1427488&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveEntryTest.java
(original)
+++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveEntryTest.java
Tue Jan  1 17:30:48 2013
@@ -28,7 +28,7 @@ import junit.framework.TestCase;
 
 import org.apache.commons.compress.AbstractTestCase;
 
-public class TarArchiveEntryTest extends TestCase {
+public class TarArchiveEntryTest extends TestCase implements TarConstants {
 
     private static final String OS =
         System.getProperty("os.name").toLowerCase(Locale.US);
@@ -116,4 +116,37 @@ public class TarArchiveEntryTest extends
         t.setSize(077777777777L);
         t.setSize(0100000000000L);
     }
+
+    public void testLinkFlagConstructor() throws IOException {
+        TarArchiveEntry t = new TarArchiveEntry("/foo", LF_GNUTYPE_LONGNAME);
+        assertGnuMagic(t);
+        assertEquals("foo", t.getName());
+    }
+
+    public void testLinkFlagConstructorWithFileFlag() throws IOException {
+        TarArchiveEntry t = new TarArchiveEntry("/foo", LF_NORMAL);
+        assertPosixMagic(t);
+        assertEquals("foo", t.getName());
+    }
+
+    public void testLinkFlagConstructorWithPreserve() throws IOException {
+        TarArchiveEntry t = new TarArchiveEntry("/foo", LF_GNUTYPE_LONGNAME,
+                                                true);
+        assertGnuMagic(t);
+        assertEquals("/foo", t.getName());
+    }
+
+    private void assertGnuMagic(TarArchiveEntry t) throws IOException {
+        assertEquals(MAGIC_GNU + VERSION_GNU_SPACE, readMagic(t));
+    }
+
+    private void assertPosixMagic(TarArchiveEntry t) throws IOException {
+        assertEquals(MAGIC_POSIX + VERSION_POSIX, readMagic(t));
+    }
+
+    private String readMagic(TarArchiveEntry t) throws IOException {
+        byte[] buf = new byte[512];
+        t.writeEntryHeader(buf);
+        return new String(buf, MAGIC_OFFSET, MAGICLEN + VERSIONLEN);
+    }
 }



Mime
View raw message