Author: bodewig
Date: Thu Aug 8 16:18:45 2013
New Revision: 1511850
URL: http://svn.apache.org/r1511850
Log:
COMPRESS-236 - CpioArchiveInputStream doesn't like Redline RPM's archives.
Patch by Andrew Duffy
Added:
commons/proper/compress/trunk/src/test/resources/redline.cpio (with props)
Modified:
commons/proper/compress/trunk/src/changes/changes.xml
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveEntry.java
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioUtil.java
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStreamTest.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=1511850&r1=1511849&r2=1511850&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/changes/changes.xml (original)
+++ commons/proper/compress/trunk/src/changes/changes.xml Thu Aug 8 16:18:45
2013
@@ -80,11 +80,16 @@ The <action> type attribute can be add,u
due-to="BELUGA BEHR">
Readabilty patch to TarArchiveInputStream.
</action>
- <action type="update" date="2013-07-08" issue="COMPRESS-234"
+ <action type="update" date="2013-08-08" issue="COMPRESS-234"
due-to="BELUGA BEHR">
Performance improvements to TarArchiveInputStream, in
particular to the skip method.
</action>
+ <action type="fix" date="2013-08-08" issue="COMPRESS-236"
+ due-to="Andrew Duffy">
+ CpioArchiveInputStream failed to read archives created by
+ Redline RPM.
+ </action>
</release>
<release version="1.5" date="2013-03-14"
description="Release 1.5">
Modified:
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveEntry.java
URL:
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveEntry.java?rev=1511850&r1=1511849&r2=1511850&view=diff
==============================================================================
---
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveEntry.java
(original)
+++
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveEntry.java
Thu Aug 8 16:18:45 2013
@@ -596,7 +596,7 @@ public class CpioArchiveEntry implements
* @return TRUE if this entry is a block device.
*/
public boolean isBlockDevice() {
- return (this.mode & S_IFMT) == C_ISBLK;
+ return CpioUtil.fileType(mode) == C_ISBLK;
}
/**
@@ -605,7 +605,7 @@ public class CpioArchiveEntry implements
* @return TRUE if this entry is a character device.
*/
public boolean isCharacterDevice() {
- return (this.mode & S_IFMT) == C_ISCHR;
+ return CpioUtil.fileType(mode) == C_ISCHR;
}
/**
@@ -614,7 +614,7 @@ public class CpioArchiveEntry implements
* @return TRUE if this entry is a directory.
*/
public boolean isDirectory() {
- return (this.mode & S_IFMT) == C_ISDIR;
+ return CpioUtil.fileType(mode) == C_ISDIR;
}
/**
@@ -623,7 +623,7 @@ public class CpioArchiveEntry implements
* @return TRUE if this entry is a network device.
*/
public boolean isNetwork() {
- return (this.mode & S_IFMT) == C_ISNWK;
+ return CpioUtil.fileType(mode) == C_ISNWK;
}
/**
@@ -632,7 +632,7 @@ public class CpioArchiveEntry implements
* @return TRUE if this entry is a pipe.
*/
public boolean isPipe() {
- return (this.mode & S_IFMT) == C_ISFIFO;
+ return CpioUtil.fileType(mode) == C_ISFIFO;
}
/**
@@ -641,7 +641,7 @@ public class CpioArchiveEntry implements
* @return TRUE if this entry is a regular file.
*/
public boolean isRegularFile() {
- return (this.mode & S_IFMT) == C_ISREG;
+ return CpioUtil.fileType(mode) == C_ISREG;
}
/**
@@ -650,7 +650,7 @@ public class CpioArchiveEntry implements
* @return TRUE if this entry is a socket.
*/
public boolean isSocket() {
- return (this.mode & S_IFMT) == C_ISSOCK;
+ return CpioUtil.fileType(mode) == C_ISSOCK;
}
/**
@@ -659,7 +659,7 @@ public class CpioArchiveEntry implements
* @return TRUE if this entry is a symbolic link.
*/
public boolean isSymbolicLink() {
- return (this.mode & S_IFMT) == C_ISLNK;
+ return CpioUtil.fileType(mode) == C_ISLNK;
}
/**
Modified:
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java
URL:
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java?rev=1511850&r1=1511849&r2=1511850&view=diff
==============================================================================
---
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java
(original)
+++
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStream.java
Thu Aug 8 16:18:45 2013
@@ -328,7 +328,7 @@ public class CpioArchiveInputStream exte
ret.setInode(readAsciiLong(8, 16));
long mode = readAsciiLong(8, 16);
- if (mode != 0){ // mode is initialised to 0
+ if (CpioUtil.fileType(mode) != 0){ // mode is initialised to 0
ret.setMode(mode);
}
ret.setUID(readAsciiLong(8, 16));
@@ -344,7 +344,7 @@ public class CpioArchiveInputStream exte
ret.setChksum(readAsciiLong(8, 16));
String name = readCString((int) namesize);
ret.setName(name);
- if (mode == 0 && !name.equals(CPIO_TRAILER)){
+ if (CpioUtil.fileType(mode) == 0 && !name.equals(CPIO_TRAILER)){
throw new IOException("Mode 0 only allowed in the trailer. Found
entry name: "+name + " Occured at byte: " + getBytesRead());
}
skip(ret.getHeaderPadCount());
@@ -358,7 +358,7 @@ public class CpioArchiveInputStream exte
ret.setDevice(readAsciiLong(6, 8));
ret.setInode(readAsciiLong(6, 8));
final long mode = readAsciiLong(6, 8);
- if (mode != 0) {
+ if (CpioUtil.fileType(mode) != 0) {
ret.setMode(mode);
}
ret.setUID(readAsciiLong(6, 8));
@@ -370,7 +370,7 @@ public class CpioArchiveInputStream exte
ret.setSize(readAsciiLong(11, 8));
final String name = readCString((int) namesize);
ret.setName(name);
- if (mode == 0 && !name.equals(CPIO_TRAILER)){
+ if (CpioUtil.fileType(mode) == 0 && !name.equals(CPIO_TRAILER)){
throw new IOException("Mode 0 only allowed in the trailer. Found
entry: "+ name + " Occured at byte: " + getBytesRead());
}
@@ -384,7 +384,7 @@ public class CpioArchiveInputStream exte
ret.setDevice(readBinaryLong(2, swapHalfWord));
ret.setInode(readBinaryLong(2, swapHalfWord));
final long mode = readBinaryLong(2, swapHalfWord);
- if (mode != 0){
+ if (CpioUtil.fileType(mode) != 0){
ret.setMode(mode);
}
ret.setUID(readBinaryLong(2, swapHalfWord));
@@ -396,7 +396,7 @@ public class CpioArchiveInputStream exte
ret.setSize(readBinaryLong(4, swapHalfWord));
final String name = readCString((int) namesize);
ret.setName(name);
- if (mode == 0 && !name.equals(CPIO_TRAILER)){
+ if (CpioUtil.fileType(mode) == 0 && !name.equals(CPIO_TRAILER)){
throw new IOException("Mode 0 only allowed in the trailer. Found
entry: "+name + "Occured at byte: " + getBytesRead());
}
skip(ret.getHeaderPadCount());
Modified:
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioUtil.java
URL:
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioUtil.java?rev=1511850&r1=1511849&r2=1511850&view=diff
==============================================================================
---
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioUtil.java
(original)
+++
commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/cpio/CpioUtil.java
Thu Aug 8 16:18:45 2013
@@ -24,6 +24,14 @@ package org.apache.commons.compress.arch
* @Immutable
*/
class CpioUtil {
+
+ /**
+ * Extracts the file type bits from a mode.
+ */
+ static long fileType(long mode) {
+ return mode & CpioConstants.S_IFMT;
+ }
+
/**
* Converts a byte array to a long. Halfwords can be swapped by setting
* swapHalfWord=true.
Modified:
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStreamTest.java
URL:
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStreamTest.java?rev=1511850&r1=1511849&r2=1511850&view=diff
==============================================================================
---
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStreamTest.java
(original)
+++
commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/archivers/cpio/CpioArchiveInputStreamTest.java
Thu Aug 8 16:18:45 2013
@@ -45,4 +45,18 @@ public class CpioArchiveInputStreamTest
in.close();
assertEquals(result.toString(), expected.toString());
}
+
+ public void testCpioUnarchiveCreatedByRedlineRpm() throws Exception {
+ CpioArchiveInputStream in =
+ new CpioArchiveInputStream(new
FileInputStream(getFile("redline.cpio")));
+ CpioArchiveEntry entry= null;
+
+ int count = 0;
+ while ((entry = (CpioArchiveEntry) in.getNextEntry()) != null) {
+ count++;
+ }
+ in.close();
+
+ assertEquals(count, 1);
+ }
}
Added: commons/proper/compress/trunk/src/test/resources/redline.cpio
URL:
http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/resources/redline.cpio?rev=1511850&view=auto
==============================================================================
Binary file - no diff available.
Propchange: commons/proper/compress/trunk/src/test/resources/redline.cpio
------------------------------------------------------------------------------
svn:mime-type = application/octet-stream