You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by bo...@apache.org on 2012/03/04 08:28:12 UTC

svn commit: r1296763 - in /commons/proper/compress/trunk/src: main/java/org/apache/commons/compress/archivers/tar/TarArchiveEntry.java test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java test/resources/preepoch-gnu.tar

Author: bodewig
Date: Sun Mar  4 07:28:12 2012
New Revision: 1296763

URL: http://svn.apache.org/viewvc?rev=1296763&view=rev
Log:
STAR and GNU tar may use binary encoding for all numeric values, including modification time.  COMPRESS-182

Added:
    commons/proper/compress/trunk/src/test/resources/preepoch-gnu.tar   (with props)
Modified:
    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/TarArchiveInputStreamTest.java

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=1296763&r1=1296762&r2=1296763&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 Sun Mar  4 07:28:12 2012
@@ -808,7 +808,7 @@ public class TarArchiveEntry implements 
 
         name = TarUtils.parseName(header, offset, NAMELEN);
         offset += NAMELEN;
-        mode = (int) TarUtils.parseOctal(header, offset, MODELEN);
+        mode = (int) TarUtils.parseOctalOrBinary(header, offset, MODELEN);
         offset += MODELEN;
         userId = (int) TarUtils.parseOctalOrBinary(header, offset, UIDLEN);
         offset += UIDLEN;
@@ -816,7 +816,7 @@ public class TarArchiveEntry implements 
         offset += GIDLEN;
         size = TarUtils.parseOctalOrBinary(header, offset, SIZELEN);
         offset += SIZELEN;
-        modTime = TarUtils.parseOctal(header, offset, MODTIMELEN);
+        modTime = TarUtils.parseOctalOrBinary(header, offset, MODTIMELEN);
         offset += MODTIMELEN;
         offset += CHKSUMLEN;
         linkFlag = header[offset++];
@@ -830,9 +830,9 @@ public class TarArchiveEntry implements 
         offset += UNAMELEN;
         groupName = TarUtils.parseName(header, offset, GNAMELEN);
         offset += GNAMELEN;
-        devMajor = (int) TarUtils.parseOctal(header, offset, DEVLEN);
+        devMajor = (int) TarUtils.parseOctalOrBinary(header, offset, DEVLEN);
         offset += DEVLEN;
-        devMinor = (int) TarUtils.parseOctal(header, offset, DEVLEN);
+        devMinor = (int) TarUtils.parseOctalOrBinary(header, offset, DEVLEN);
         offset += DEVLEN;
 
         int type = evaluateType(header);

Modified: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java?rev=1296763&r1=1296762&r2=1296763&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java (original)
+++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java Sun Mar  4 07:28:12 2012
@@ -23,8 +23,10 @@ import java.io.FileInputStream;
 import java.io.StringReader;
 import java.net.URI;
 import java.net.URL;
+import java.util.Calendar;
 import java.util.Date;
 import java.util.Map;
+import java.util.TimeZone;
 import org.junit.Test;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
@@ -65,4 +67,23 @@ public class TarArchiveInputStreamTest {
         }
     }        
 
+    @Test
+    public void datePriorToEpochInGNUFormat() throws Exception {
+        URL tar = getClass().getResource("/preepoch-gnu.tar");
+        TarArchiveInputStream in = null;
+        try {
+            in = new TarArchiveInputStream(new FileInputStream(new File(new URI(tar.toString()))));
+            TarArchiveEntry tae = in.getNextTarEntry();
+            assertEquals("foo", tae.getName());
+            Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
+            cal.set(1969, 11, 31, 23, 59, 59);
+            cal.set(Calendar.MILLISECOND, 0);
+            assertEquals(cal.getTime(), tae.getLastModifiedDate());
+        } finally {
+            if (in != null) {
+                in.close();
+            }
+        }
+    }        
+
 }
\ No newline at end of file

Added: commons/proper/compress/trunk/src/test/resources/preepoch-gnu.tar
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/resources/preepoch-gnu.tar?rev=1296763&view=auto
==============================================================================
Binary file - no diff available.

Propchange: commons/proper/compress/trunk/src/test/resources/preepoch-gnu.tar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream