Browse Source

Make sure zip files, that <zip> is reading from, will be closed.

Submitted by:	David Rees <d.rees.l@usa.net>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268772 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 24 years ago
parent
commit
832fe98aea
3 changed files with 56 additions and 7 deletions
  1. +28
    -0
      src/etc/testcases/taskdefs/zip.xml
  2. +15
    -7
      src/main/org/apache/tools/ant/taskdefs/Zip.java
  3. +13
    -0
      src/testcases/org/apache/tools/ant/taskdefs/ZipTest.java

+ 28
- 0
src/etc/testcases/taskdefs/zip.xml View File

@@ -25,9 +25,37 @@
basedir="."/>
</target>

<target name="test5">
<zip zipfile="test5.zip" basedir="." >
<exclude name="test5.zip" />
</zip>
</target>

<target name="test6">
<zip zipfile="test6.zip" basedir=".">
<include name="*.xml" />
<exclude name="zip.*" />
</zip>
</target>

<target name="test7">
<zip zipfile="inner7.zip" basedir="." >
<exclude name="inner7.zip" />
</zip>
<zip zipfile="test7.zip" basedir=".">
<exclude name="**/*.*" />
<zipfileset src="inner7.zip" />
</zip>
</target>



<target name="cleanup">
<delete file="test3.zip"/>
<delete file="test4.zip"/>
<delete file="test5.zip"/>
<delete file="test6.zip"/>
<delete file="inner7.zip"/>
<delete file="test7.zip"/>
</target>
</project>

+ 15
- 7
src/main/org/apache/tools/ant/taskdefs/Zip.java View File

@@ -270,15 +270,23 @@ public class Zip extends MatchingTask {
File zipSrc = fs.getSrc();

ZipEntry entry;
ZipInputStream in = new ZipInputStream(new FileInputStream(zipSrc));
while ((entry = in.getNextEntry()) != null) {
String vPath = entry.getName();
if (zipScanner.match(vPath)) {
addParentDirs(null, vPath, zOut, prefix);
if (! entry.isDirectory()) {
zipFile(in, zOut, prefix+vPath, entry.getTime());
ZipInputStream in = null;
try {
in = new ZipInputStream(new FileInputStream(zipSrc));

while ((entry = in.getNextEntry()) != null) {
String vPath = entry.getName();
if (zipScanner.match(vPath)) {
addParentDirs(null, vPath, zOut, prefix);
if (! entry.isDirectory()) {
zipFile(in, zOut, prefix+vPath, entry.getTime());
}
}
}
} finally {
if (in != null) {
in.close();
}
}
}



+ 13
- 0
src/testcases/org/apache/tools/ant/taskdefs/ZipTest.java View File

@@ -87,4 +87,17 @@ public class ZipTest extends TaskdefsTest {
executeTarget("cleanup");
}
public void test5() {
executeTarget("test5");
}


public void test6() {
executeTarget("test6");
}


public void test7() {
executeTarget("test7");
}
}

Loading…
Cancel
Save