ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r738853 - in /ant/core/trunk: ./ src/main/org/apache/tools/zip/ src/tests/antunit/taskdefs/ src/tests/antunit/taskdefs/zip/
Date Thu, 29 Jan 2009 13:22:58 GMT
Author: bodewig
Date: Thu Jan 29 13:22:58 2009
New Revision: 738853

URL: http://svn.apache.org/viewvc?rev=738853&view=rev
Log:
Make sure ZIP archive is closed even when a RuntimeExpection occurs.  PR 46559

Added:
    ant/core/trunk/src/tests/antunit/taskdefs/zip/
    ant/core/trunk/src/tests/antunit/taskdefs/zip/Bugzilla-42940.zip   (with props)
    ant/core/trunk/src/tests/antunit/taskdefs/zip/Bugzilla-46559.zip   (with props)
Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/src/main/org/apache/tools/zip/ZipFile.java
    ant/core/trunk/src/tests/antunit/taskdefs/unzip-test.xml

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=738853&r1=738852&r2=738853&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Thu Jan 29 13:22:58 2009
@@ -331,6 +331,11 @@
  * <sort> resource collection kept only one of entries deemed equal by
    the chosen Comparator.  Bugzilla report 46527.
 
+ * the ZipFile class used by <unzip> and others could leave the
+   archive open (making it undeletable on Windows as long as the java
+   VM was running) for files with an unexpected internal structure.
+   Bugzilla Report 46559.
+
 Other changes:
 --------------
 

Modified: ant/core/trunk/src/main/org/apache/tools/zip/ZipFile.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/zip/ZipFile.java?rev=738853&r1=738852&r2=738853&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/zip/ZipFile.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/zip/ZipFile.java Thu Jan 29 13:22:58 2009
@@ -150,16 +150,19 @@
     public ZipFile(File f, String encoding) throws IOException {
         this.encoding = encoding;
         archive = new RandomAccessFile(f, "r");
+        boolean success = false;
         try {
             populateFromCentralDirectory();
             resolveLocalFileHeaderData();
-        } catch (IOException e) {
-            try {
-                archive.close();
-            } catch (IOException e2) {
-                // swallow, throw the original exception instead
+            success = true;
+        } finally {
+            if (!success) {
+                try {
+                    archive.close();
+                } catch (IOException e2) {
+                    // swallow, throw the original exception instead
+                }
             }
-            throw e;
         }
     }
 

Modified: ant/core/trunk/src/tests/antunit/taskdefs/unzip-test.xml
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/unzip-test.xml?rev=738853&r1=738852&r2=738853&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/taskdefs/unzip-test.xml (original)
+++ ant/core/trunk/src/tests/antunit/taskdefs/unzip-test.xml Thu Jan 29 13:22:58 2009
@@ -43,4 +43,18 @@
            dest="${output}"/>
     <au:assertFileExists file="${output}/foo/file"/>
   </target>
+
+  <target name="testArchiveIsClosedForInvalidZips"
+          description="https://issues.apache.org/bugzilla/show_bug.cgi?id=46559"
+          >
+    <mkdir dir="${input}"/>
+    <mkdir dir="${output}"/>
+    <copy file="zip/Bugzilla-46559.zip" tofile="${input}/test.zip"/>
+    <au:expectfailure>
+      <unzip src="${input}/test.zip" dest="${output}"/>
+    </au:expectfailure>
+    <delete file="${input}/test.zip" quiet="true"/>
+    <!-- failed on Windows and other OSes with implicit file locking -->
+    <au:assertFileDoesntExist file="${input}/test.zip"/>
+  </target>
 </project>

Added: ant/core/trunk/src/tests/antunit/taskdefs/zip/Bugzilla-42940.zip
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/zip/Bugzilla-42940.zip?rev=738853&view=auto
==============================================================================
Binary file - no diff available.

Propchange: ant/core/trunk/src/tests/antunit/taskdefs/zip/Bugzilla-42940.zip
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: ant/core/trunk/src/tests/antunit/taskdefs/zip/Bugzilla-46559.zip
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/antunit/taskdefs/zip/Bugzilla-46559.zip?rev=738853&view=auto
==============================================================================
Files ant/core/trunk/src/tests/antunit/taskdefs/zip/Bugzilla-46559.zip (added) and ant/core/trunk/src/tests/antunit/taskdefs/zip/Bugzilla-46559.zip
Thu Jan 29 13:22:58 2009 differ

Propchange: ant/core/trunk/src/tests/antunit/taskdefs/zip/Bugzilla-46559.zip
------------------------------------------------------------------------------
    svn:mergeinfo = 



Mime
View raw message