提交 01348d08 authored 作者: Thomas Mueller's avatar Thomas Mueller

File system bugfixes

上级 8d934127
...@@ -57,7 +57,11 @@ public class FilePathZip extends FilePath { ...@@ -57,7 +57,11 @@ public class FilePathZip extends FilePath {
return true; return true;
} }
ZipFile file = openZipFile(); ZipFile file = openZipFile();
return file.getEntry(entryName) != null; try {
return file.getEntry(entryName) != null;
} finally {
file.close();
}
} catch (IOException e) { } catch (IOException e) {
return false; return false;
} }
...@@ -93,19 +97,23 @@ public class FilePathZip extends FilePath { ...@@ -93,19 +97,23 @@ public class FilePathZip extends FilePath {
return true; return true;
} }
ZipFile file = openZipFile(); ZipFile file = openZipFile();
Enumeration<? extends ZipEntry> en = file.entries(); try {
while (en.hasMoreElements()) { Enumeration<? extends ZipEntry> en = file.entries();
ZipEntry entry = en.nextElement(); while (en.hasMoreElements()) {
String n = entry.getName(); ZipEntry entry = en.nextElement();
if (n.equals(entryName)) { String n = entry.getName();
return entry.isDirectory(); if (n.equals(entryName)) {
} else if (n.startsWith(entryName)) { return entry.isDirectory();
if (n.length() == entryName.length() + 1) { } else if (n.startsWith(entryName)) {
if (n.equals(entryName + "/")) { if (n.length() == entryName.length() + 1) {
return true; if (n.equals(entryName + "/")) {
return true;
}
} }
} }
} }
} finally {
file.close();
} }
return false; return false;
} catch (IOException e) { } catch (IOException e) {
...@@ -127,8 +135,12 @@ public class FilePathZip extends FilePath { ...@@ -127,8 +135,12 @@ public class FilePathZip extends FilePath {
public long size() { public long size() {
try { try {
ZipFile file = openZipFile(); ZipFile file = openZipFile();
ZipEntry entry = file.getEntry(getEntryName()); try {
return entry == null ? 0 : entry.getSize(); ZipEntry entry = file.getEntry(getEntryName());
return entry == null ? 0 : entry.getSize();
} finally {
file.close();
}
} catch (IOException e) { } catch (IOException e) {
return 0; return 0;
} }
...@@ -146,22 +158,26 @@ public class FilePathZip extends FilePath { ...@@ -146,22 +158,26 @@ public class FilePathZip extends FilePath {
path += "/"; path += "/";
} }
ZipFile file = openZipFile(); ZipFile file = openZipFile();
String dirName = getEntryName(); try {
String prefix = path.substring(0, path.length() - dirName.length()); String dirName = getEntryName();
Enumeration<? extends ZipEntry> en = file.entries(); String prefix = path.substring(0, path.length() - dirName.length());
while (en.hasMoreElements()) { Enumeration<? extends ZipEntry> en = file.entries();
ZipEntry entry = en.nextElement(); while (en.hasMoreElements()) {
String name = entry.getName(); ZipEntry entry = en.nextElement();
if (!name.startsWith(dirName)) { String name = entry.getName();
continue; if (!name.startsWith(dirName)) {
} continue;
if (name.length() <= dirName.length()) { }
continue; if (name.length() <= dirName.length()) {
} continue;
int idx = name.indexOf('/', dirName.length()); }
if (idx < 0 || idx >= name.length() - 1) { int idx = name.indexOf('/', dirName.length());
list.add(getPath(prefix + name)); if (idx < 0 || idx >= name.length() - 1) {
list.add(getPath(prefix + name));
}
} }
} finally {
file.close();
} }
return list; return list;
} catch (IOException e) { } catch (IOException e) {
...@@ -179,6 +195,7 @@ public class FilePathZip extends FilePath { ...@@ -179,6 +195,7 @@ public class FilePathZip extends FilePath {
ZipFile file = openZipFile(); ZipFile file = openZipFile();
ZipEntry entry = file.getEntry(getEntryName()); ZipEntry entry = file.getEntry(getEntryName());
if (entry == null) { if (entry == null) {
file.close();
throw new FileNotFoundException(name); throw new FileNotFoundException(name);
} }
return new FileZip(file, entry); return new FileZip(file, entry);
...@@ -368,6 +385,7 @@ class FileZip extends FileBase { ...@@ -368,6 +385,7 @@ class FileZip extends FileBase {
in.close(); in.close();
in = null; in = null;
} }
file.close();
} }
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论