parse last modification date from PAX headers if present. COMPRESS-182
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/compress/trunk@1296764 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
index 34e7355..7cd1a10 100644
--- a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
+++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
@@ -339,12 +339,14 @@
private void applyPaxHeadersToCurrentEntry(Map<String, String> headers) {
/*
* The following headers are defined for Pax.
- * atime, ctime, mtime, charset: cannot use these without changing TarArchiveEntry fields
+ * atime, ctime, charset: cannot use these without changing TarArchiveEntry fields
+ * mtime
* comment
* gid, gname
* linkpath
* size
* uid,uname
+ * SCHILY.devminor, SCHILY.devmajor: don't have setters/getters for those
*/
for (Entry<String, String> ent : headers.entrySet()){
String key = ent.getKey();
@@ -363,6 +365,14 @@
currEntry.setUserName(val);
} else if ("size".equals(key)){
currEntry.setSize(Long.parseLong(val));
+ } else if ("mtime".equals(key)){
+ currEntry.setModTime((long) (Double.parseDouble(val) * 1000));
+ /* currently not settable
+ } else if ("SCHILY.devminor".equals(key)){
+ currEntry.setMinor(Integer.parseInt(val));
+ } else if ("SCHILY.devmajor".equals(key)){
+ currEntry.setMajor(Integer.parseInt(val));
+ */
}
}
}
diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
index 4188aab..ef9c142 100644
--- a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
@@ -69,7 +69,17 @@
@Test
public void datePriorToEpochInGNUFormat() throws Exception {
- URL tar = getClass().getResource("/preepoch-gnu.tar");
+ datePriorToEpoch("/preepoch-gnu.tar");
+ }
+
+
+ @Test
+ public void datePriorToEpochInPAXFormat() throws Exception {
+ datePriorToEpoch("/preepoch-posix.tar");
+ }
+
+ private void datePriorToEpoch(String archive) throws Exception {
+ URL tar = getClass().getResource(archive);
TarArchiveInputStream in = null;
try {
in = new TarArchiveInputStream(new FileInputStream(new File(new URI(tar.toString()))));
diff --git a/src/test/resources/preepoch-posix.tar b/src/test/resources/preepoch-posix.tar
new file mode 100644
index 0000000..e9a89c3
--- /dev/null
+++ b/src/test/resources/preepoch-posix.tar
Binary files differ