diff options
Diffstat (limited to 'sched')
4 files changed, 31 insertions, 15 deletions
diff --git a/sched/src/com/android/sched/vfs/InputOutputZipVDir.java b/sched/src/com/android/sched/vfs/InputOutputZipVDir.java index 7f472a7..b48e991 100644 --- a/sched/src/com/android/sched/vfs/InputOutputZipVDir.java +++ b/sched/src/com/android/sched/vfs/InputOutputZipVDir.java @@ -98,6 +98,7 @@ class InputOutputZipVDir extends AbstractVElement implements InputOutputVDir { @Override @Nonnull public OutputVFile createOutputVFile(@Nonnull VPath path) throws CannotCreateFileException { + assert !vfs.isClosed(); File file = new File(dir, path.getPathAsString(ZipUtils.ZIP_SEPARATOR)); if (!file.getParentFile().mkdirs() && !file.getParentFile().isDirectory()) { throw new CannotCreateFileException(new DirectoryLocation(file.getParentFile())); @@ -145,6 +146,7 @@ class InputOutputZipVDir extends AbstractVElement implements InputOutputVDir { @Override @Nonnull public void delete(@Nonnull VPath path) throws CannotDeleteFileException { + assert !vfs.isClosed(); File file = new File(dir, path.getPathAsString(File.separatorChar)); if (!file.delete()) { throw new CannotDeleteFileException( diff --git a/sched/src/com/android/sched/vfs/InputOutputZipVFS.java b/sched/src/com/android/sched/vfs/InputOutputZipVFS.java index 6c7d7c7..680712e 100644 --- a/sched/src/com/android/sched/vfs/InputOutputZipVFS.java +++ b/sched/src/com/android/sched/vfs/InputOutputZipVFS.java @@ -36,6 +36,8 @@ import javax.annotation.Nonnull; * closed. */ public class InputOutputZipVFS extends AbstractInputOutputVFS implements InputOutputVFS { + + private boolean closed = false; @Nonnull private final OutputZipFile zipFile; @Nonnull @@ -53,12 +55,15 @@ public class InputOutputZipVFS extends AbstractInputOutputVFS implements InputOu } @Override - public void close() throws IOException { - try { - addDirToZip(zipOS, getRootInputOutputVDir()); - } finally { - zipOS.close(); - FileUtils.deleteDir(dir); + public synchronized void close() throws IOException { + if (!closed) { + try { + addDirToZip(zipOS, getRootInputOutputVDir()); + } finally { + zipOS.close(); + FileUtils.deleteDir(dir); + closed = true; + } } } @@ -97,4 +102,8 @@ public class InputOutputZipVFS extends AbstractInputOutputVFS implements InputOu public String getPath() { return zipFile.getPath(); } + + synchronized boolean isClosed() { + return closed; + } } diff --git a/sched/src/com/android/sched/vfs/InputOutputZipVFile.java b/sched/src/com/android/sched/vfs/InputOutputZipVFile.java index c8e2222..d1190d1 100644 --- a/sched/src/com/android/sched/vfs/InputOutputZipVFile.java +++ b/sched/src/com/android/sched/vfs/InputOutputZipVFile.java @@ -79,6 +79,7 @@ class InputOutputZipVFile extends AbstractVElement implements InputOutputVFile { @Nonnull @Override public OutputStream openWrite() throws FileNotFoundException { + assert !vfs.isClosed(); return new FileOutputStream(file); } diff --git a/sched/src/com/android/sched/vfs/MessageDigestInputOutputVFS.java b/sched/src/com/android/sched/vfs/MessageDigestInputOutputVFS.java index 4acdd9c..eb64b96 100644 --- a/sched/src/com/android/sched/vfs/MessageDigestInputOutputVFS.java +++ b/sched/src/com/android/sched/vfs/MessageDigestInputOutputVFS.java @@ -79,7 +79,7 @@ public class MessageDigestInputOutputVFS implements InputOutputVFS { @Override @Nonnull public OutputStream openWrite() throws IOException { - assert !closed; + assert !isClosed(); return new DigestOutputStream(file.openWrite(), MessageDigestInputOutputVFS.this.mdFactory.create()) { @@ -133,7 +133,7 @@ public class MessageDigestInputOutputVFS implements InputOutputVFS { @Nonnull public synchronized OutputVFile createOutputVFile(@Nonnull VPath path) throws CannotCreateFileException { - assert !closed; + assert !isClosed(); MessageDigestOutputVFile file = new MessageDigestOutputVFile(dir.createOutputVFile(path), path); @@ -162,7 +162,7 @@ public class MessageDigestInputOutputVFS implements InputOutputVFS { @Override @Nonnull public Collection<? extends InputVElement> list() { - assert !closed; + assert !isClosed(); return dir.list(); } @@ -171,7 +171,7 @@ public class MessageDigestInputOutputVFS implements InputOutputVFS { @Nonnull public InputVDir getInputVDir(@Nonnull VPath path) throws NotFileOrDirectoryException, NoSuchFileException { - assert !closed; + assert !isClosed(); return dir.getInputVDir(path); } @@ -180,7 +180,7 @@ public class MessageDigestInputOutputVFS implements InputOutputVFS { @Nonnull public InputVFile getInputVFile(@Nonnull VPath path) throws NotFileOrDirectoryException, NoSuchFileException { - assert !closed; + assert !isClosed(); return dir.getInputVFile(path); } @@ -188,7 +188,7 @@ public class MessageDigestInputOutputVFS implements InputOutputVFS { @Override @Nonnull public void delete(@Nonnull VPath path) throws CannotDeleteFileException { - assert !closed; + assert !isClosed(); dir.delete(path); } @@ -216,10 +216,14 @@ public class MessageDigestInputOutputVFS implements InputOutputVFS { } } + synchronized boolean isClosed() { + return closed; + } + @Override @Nonnull public OutputVDir getRootOutputVDir() { - assert !closed; + assert !isClosed(); return root; } @@ -227,7 +231,7 @@ public class MessageDigestInputOutputVFS implements InputOutputVFS { @Override @Nonnull public InputVDir getRootInputVDir() { - assert !closed; + assert !isClosed(); return root; } @@ -235,7 +239,7 @@ public class MessageDigestInputOutputVFS implements InputOutputVFS { @Override @Nonnull public InputOutputVDir getRootInputOutputVDir() { - assert !closed; + assert !isClosed(); return root; } |