[jboss-cvs] JBossAS SVN: r92338 - in projects/vfs/branches/Branch_2_1/src: main/java/org/jboss/virtual/plugins/context/zip and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Aug 14 02:49:43 EDT 2009
Author: jason.greene at jboss.com
Date: 2009-08-14 02:49:42 -0400 (Fri, 14 Aug 2009)
New Revision: 92338
Modified:
projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java
projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/context/zip/ZipBytesWrapper.java
projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java
projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryHandler.java
projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/context/zip/ZipFileWrapper.java
projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/context/zip/ZipWrapper.java
projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/copy/AbstractCopyMechanism.java
projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/spi/VirtualFileHandler.java
projects/vfs/branches/Branch_2_1/src/test/java/org/jboss/test/virtual/test/ZipReleaseAfterCopyTestCase.java
Log:
Be more careful with zip streams
Slightly less hacky
Modified: projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java
===================================================================
--- projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java 2009-08-14 06:41:59 UTC (rev 92337)
+++ projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/context/AbstractVirtualFileHandler.java 2009-08-14 06:49:42 UTC (rev 92338)
@@ -46,7 +46,7 @@
/**
* AbstractVirtualFileHandler.
- *
+ *
* @author <a href="ales.justin at jboss.com">Ales Justin</a>
* @author <a href="adrian at jboss.com">Adrian Brock</a>
* @author Scott.Stark at jboss.org
@@ -74,7 +74,7 @@
* @serialField rootURI URI the VFS context rootURI
*/
private VFSContext context;
-
+
/**
* The parent
*
@@ -116,7 +116,7 @@
/**
* Create a new handler
- *
+ *
* @param context the context
* @param parent the parent
* @param name the name
@@ -394,7 +394,7 @@
/**
* Initialise the path into the path name
- *
+ *
* @param pathName the path name
* @return whether it added anything
*/
@@ -536,7 +536,7 @@
/**
* Increment the reference count
- *
+ *
* @return the resulting count
*/
protected int increment()
@@ -546,7 +546,7 @@
/**
* Decrement the reference count
- *
+ *
* @return the resulting count
*/
protected int decrement()
@@ -556,10 +556,10 @@
/**
* Check whether we are closed
- *
+ *
* @throws IllegalStateException when closed
*/
- protected void checkClosed() throws IllegalStateException
+ protected void checkClosed() throws IllegalStateException
{
if (references < 0)
throw new IllegalStateException("Closed " + toStringLocal());
@@ -578,7 +578,7 @@
public void cleanup()
{
}
-
+
/**
* Is the handler temporary.
*
@@ -612,6 +612,14 @@
}
/**
+ * Temporarily release file handles, if possible
+ */
+ public void releaseHandles()
+ {
+ // nothing
+ }
+
+ /**
* Delete the file represented by this handler.
*
* File deletion is comprised of two parts:
@@ -696,7 +704,7 @@
/**
* Simple implementation of findChild
- *
+ *
* @param path the path
* @return the handler
* @throws IOException for any error accessing the virtual file system
@@ -797,10 +805,10 @@
close();
}
*/
-
+
/**
* Safely get a url version of the string
- *
+ *
* @return the string or unknown if there is an error
*/
private String safeToURLString()
Modified: projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/context/zip/ZipBytesWrapper.java
===================================================================
--- projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/context/zip/ZipBytesWrapper.java 2009-08-14 06:41:59 UTC (rev 92337)
+++ projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/context/zip/ZipBytesWrapper.java 2009-08-14 06:49:42 UTC (rev 92338)
@@ -130,6 +130,11 @@
zipBytes = null;
}
+ void releaseHandles()
+ {
+ // No file handles to release
+ }
+
boolean delete(int gracePeriod) throws IOException
{
close();
Modified: projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java
===================================================================
--- projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java 2009-08-14 06:41:59 UTC (rev 92337)
+++ projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java 2009-08-14 06:49:42 UTC (rev 92338)
@@ -872,7 +872,7 @@
}
/**
- * Close the handler, if it's root.
+ * Clean the handler's resources, if it's root.
*
* @param handler the handler to close
*/
@@ -881,16 +881,23 @@
VirtualFileHandler rootHandler = getRoot();
if (rootHandler.equals(handler))
{
- ZipWrapper source = zipSource;
- if (source != null)
- {
- source.close(); // close == cleanup in zip source impl
- zipSource = null;
- }
+ getZipSource().close();
}
}
/**
+ * Temporarily release file handles if possible
+ */
+ void releaseHandles(ZipEntryHandler handler)
+ {
+ VirtualFileHandler rootHandler = getRoot();
+ if (rootHandler.equals(handler) && zipSource != null)
+ {
+ zipSource.releaseHandles();
+ }
+ }
+
+ /**
* Returns lastModified timestamp for a given handler
*
* @param handler a handler
Modified: projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryHandler.java
===================================================================
--- projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryHandler.java 2009-08-14 06:41:59 UTC (rev 92337)
+++ projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryHandler.java 2009-08-14 06:49:42 UTC (rev 92338)
@@ -262,7 +262,7 @@
else
return realUrl;
}
-
+
throw new RuntimeException("Operation not supported for handler: " + this);
}
}
Modified: projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/context/zip/ZipFileWrapper.java
===================================================================
--- projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/context/zip/ZipFileWrapper.java 2009-08-14 06:41:59 UTC (rev 92337)
+++ projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/context/zip/ZipFileWrapper.java 2009-08-14 06:49:42 UTC (rev 92338)
@@ -214,7 +214,7 @@
InputStream is = zipFile.getInputStream(ent);
if (is == null)
throw new IOException("Entry no longer available: " + ent.getName() + " in file " + file);
-
+
ZipEntryInputStream zis = new ZipEntryInputStream(this, is);
// debugging code
@@ -288,6 +288,17 @@
file.delete();
}
+ void releaseHandles()
+ {
+ try
+ {
+ closeZipFile();
+ }
+ catch(Exception ignored)
+ {
+ }
+ }
+
void deleteFile(ZipFileWrapper wrapper) throws IOException
{
if (file.equals(wrapper.file))
Modified: projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/context/zip/ZipWrapper.java
===================================================================
--- projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/context/zip/ZipWrapper.java 2009-08-14 06:41:59 UTC (rev 92337)
+++ projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/context/zip/ZipWrapper.java 2009-08-14 06:49:42 UTC (rev 92338)
@@ -185,6 +185,11 @@
abstract void close();
/**
+ * Temporarily release handles if possible
+ */
+ abstract void releaseHandles();
+
+ /**
* Delete this archive
*
* @param gracePeriod maximum time to wait for any locks
Modified: projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/copy/AbstractCopyMechanism.java
===================================================================
--- projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/copy/AbstractCopyMechanism.java 2009-08-14 06:41:59 UTC (rev 92337)
+++ projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/copy/AbstractCopyMechanism.java 2009-08-14 06:49:42 UTC (rev 92338)
@@ -159,8 +159,8 @@
if (parent != null && replaceOldHandler(parent, handler, newHandler))
parent.replaceChild(handler, newHandler);
- // Release underlying file, so that Windows won't lock it
- handler.cleanup();
+ // Release underlying file, so that Windows won't lock it.
+ handler.releaseHandles();
return newHandler.getVirtualFile();
}
Modified: projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/spi/VirtualFileHandler.java
===================================================================
--- projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/spi/VirtualFileHandler.java 2009-08-14 06:41:59 UTC (rev 92337)
+++ projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/spi/VirtualFileHandler.java 2009-08-14 06:49:42 UTC (rev 92338)
@@ -34,7 +34,7 @@
/**
* A virtual file handler
- *
+ *
* @author Scott.Stark at jboss.org
* @author Adrian.Brock
* @author Ales.Justin at jboss.org
@@ -44,14 +44,14 @@
{
/**
* Get the simple VF name (X.java)
- *
+ *
* @return the simple file name
*/
String getName();
/**
* Get the VFS relative path name (org/jboss/X.java)
- *
+ *
* @return the VFS relative path name
*/
String getPathName();
@@ -72,7 +72,7 @@
* @throws MalformedURLException for any error
*/
URL toVfsUrl() throws MalformedURLException, URISyntaxException;
-
+
/**
* Get a file: or jar:file: URL representing a resource as precisely as possible.
* file: urls can represent files in the file system (i.e.: file:/classes/MyClass.class)
@@ -92,24 +92,24 @@
/**
* Get the VF URI (file://root/org/jboss/X.java)
- *
+ *
* @return the full URI to the VF in the VFS.
- * @throws URISyntaxException for an error parsing the URI
+ * @throws URISyntaxException for an error parsing the URI
*/
URI toURI() throws URISyntaxException;
/**
* Get the VF URL (file://root/org/jboss/X.java)
- *
+ *
* @return the full URL to the VF in the VFS.
- * @throws URISyntaxException for an error parsing the URI
+ * @throws URISyntaxException for an error parsing the URI
* @throws MalformedURLException for any error
*/
URL toURL() throws MalformedURLException, URISyntaxException;
/**
* When the file was last modified
- *
+ *
* @return the last modified time
* @throws IOException for any problem accessing the virtual file system
* @throws IllegalStateException if closed
@@ -124,10 +124,10 @@
* @throws IOException for any error
*/
boolean hasBeenModified() throws IOException;
-
+
/**
* Get the size
- *
+ *
* @return the size
* @throws IOException for any problem accessing the virtual file system
* @throws IllegalStateException if closed
@@ -144,13 +144,13 @@
/**
* Whether it is a simple leaf of the VFS,
* i.e. whether it can contain other files
- *
+ *
* @return true if a simple file.
* @throws IOException for any problem accessing the virtual file system
* @throws IllegalStateException if the file is closed
*/
boolean isLeaf() throws IOException;
-
+
/**
* Does this represent an archive.
* e.g. zip, tar, ...
@@ -162,7 +162,7 @@
/**
* Whether it is hidden
- *
+ *
* @return true if hidden.
* @throws IOException for any problem accessing the virtual file system
* @throws IllegalStateException if closed
@@ -171,7 +171,7 @@
/**
* Access the file contents.
- *
+ *
* @return An InputStream for the file contents.
* @throws IOException for any problem accessing the virtual file system
* @throws IllegalStateException if closed
@@ -180,7 +180,7 @@
/**
* Get the parent
- *
+ *
* @return the parent
* @throws IOException for an error accessing the file system
* @throws IllegalStateException if closed
@@ -189,7 +189,7 @@
/**
* Get the children
- *
+ *
* @param ignoreErrors whether to ignore errors
* @return the children
* @throws IOException for an error accessing the file system
@@ -219,7 +219,7 @@
/**
* Get the VFSContext this file belongs to
- *
+ *
* @return the context
* @throws IllegalStateException if closed
*/
@@ -227,7 +227,7 @@
/**
* Get the virtual file wrapper
- *
+ *
* @return the wrapper
* @throws IllegalStateException if closed
*/
@@ -244,6 +244,11 @@
void close();
/**
+ * Temporarily release file handles
+ */
+ void releaseHandles();
+
+ /**
* Replace child.
*
* @param original the original
Modified: projects/vfs/branches/Branch_2_1/src/test/java/org/jboss/test/virtual/test/ZipReleaseAfterCopyTestCase.java
===================================================================
--- projects/vfs/branches/Branch_2_1/src/test/java/org/jboss/test/virtual/test/ZipReleaseAfterCopyTestCase.java 2009-08-14 06:41:59 UTC (rev 92337)
+++ projects/vfs/branches/Branch_2_1/src/test/java/org/jboss/test/virtual/test/ZipReleaseAfterCopyTestCase.java 2009-08-14 06:49:42 UTC (rev 92338)
@@ -170,7 +170,11 @@
Field field = ZipEntryContext.class.getDeclaredField("zipSource");
field.setAccessible(true);
Object object = field.get(method.invoke(h));
- assertNull(object);
+
+ field = object.getClass().getDeclaredField("zipFile");
+ field.setAccessible(true);
+
+ assertNull(field.get(object));
assertNotNull(root.openStream());
root.cleanup();
More information about the jboss-cvs-commits
mailing list