ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1150283 - in /ant/antlibs/compress/trunk/src: main/org/apache/ant/compress/taskdefs/ExpandBase.java main/org/apache/ant/compress/taskdefs/Unzip.java tests/antunit/unzip-test.xml
Date Sun, 24 Jul 2011 05:28:50 GMT
Author: bodewig
Date: Sun Jul 24 05:28:50 2011
New Revision: 1150283

URL: http://svn.apache.org/viewvc?rev=1150283&view=rev
Log:
support for skipping entries Commons Compress knows it cannot read

Modified:
    ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ExpandBase.java
    ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Unzip.java
    ant/antlibs/compress/trunk/src/tests/antunit/unzip-test.xml

Modified: ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ExpandBase.java
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ExpandBase.java?rev=1150283&r1=1150282&r2=1150283&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ExpandBase.java (original)
+++ ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ExpandBase.java Sun
Jul 24 05:28:50 2011
@@ -55,6 +55,8 @@ public abstract class ExpandBase extends
         this.factory = factory;
     }
 
+    private boolean skipUnreadable = false;
+
     /**
      * No encoding support in general.
      * @param encoding not used
@@ -74,6 +76,24 @@ public abstract class ExpandBase extends
                                  + " attribute", getLocation());
     }
 
+    /**
+     * Whether to skip entries that Commons Compress signals it cannot read.
+     *
+     * @since Compress Antlib 1.1
+     */
+    public void setSkipUnreadableEntries(boolean b) {
+        skipUnreadable = b;
+    }
+
+    /**
+     * Whether to skip entries that Commons Compress signals it cannot read.
+     *
+     * @since Compress Antlib 1.1
+     */
+    public boolean getSkipUnreadableEntries() {
+        return skipUnreadable;
+    }
+
     /** {@inheritDoc} */
     protected void expandFile(FileUtils fileUtils, File srcF, File dir) {
         if (!srcF.exists()) {
@@ -125,6 +145,11 @@ public abstract class ExpandBase extends
             boolean empty = true;
             ArchiveEntry ent = null;
             while ((ent = is.getNextEntry()) != null) {
+                if (skipUnreadable && !is.canReadEntryData(ent)) {
+                    log("skipping " + ent.getName()
+                        + ", Commons Compress cannot read it");
+                    continue;
+                }
                 empty = false;
                 log("extracting " + ent.getName(), Project.MSG_DEBUG);
                 extractFile(FileUtils.getFileUtils(), null, dir, is,

Modified: ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Unzip.java
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Unzip.java?rev=1150283&r1=1150282&r2=1150283&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Unzip.java (original)
+++ ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Unzip.java Sun Jul
24 05:28:50 2011
@@ -64,6 +64,11 @@ public class Unzip extends ExpandBase {
             while (e.hasMoreElements()) {
                 empty = false;
                 ZipArchiveEntry ze = (ZipArchiveEntry) e.nextElement();
+                if (getSkipUnreadableEntries() && !zf.canReadEntryData(ze)) {
+                    log("skipping " + ze.getName()
+                        + ", Commons Compress cannot read it");
+                    continue;
+                }
                 log("extracting " + ze.getName(), Project.MSG_DEBUG);
                 InputStream is = null;
                 try {

Modified: ant/antlibs/compress/trunk/src/tests/antunit/unzip-test.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/tests/antunit/unzip-test.xml?rev=1150283&r1=1150282&r2=1150283&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/tests/antunit/unzip-test.xml (original)
+++ ant/antlibs/compress/trunk/src/tests/antunit/unzip-test.xml Sun Jul 24 05:28:50 2011
@@ -91,4 +91,11 @@
                  dest="${output}"/>
     </au:expectfailure>
   </target>
+
+  <target name="testSkipUnreadableEntries" depends="setUp">
+    <cmp:unzip src="../resources/password-encrypted.zip"
+               dest="${output}"
+               skipUnreadableEntries="true"/>
+    <au:assertLogContains text="Commons Compress cannot read it"/>
+  </target>
 </project>



Mime
View raw message