[jboss-cvs] JBossAS SVN: r92336 - in projects/vfs/branches/Branch_2_1/src: main/java/org/jboss/virtual/plugins/copy and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Aug 14 01:47:30 EDT 2009


Author: jason.greene at jboss.com
Date: 2009-08-14 01:47:30 -0400 (Fri, 14 Aug 2009)
New Revision: 92336

Added:
   projects/vfs/branches/Branch_2_1/src/test/java/org/jboss/test/virtual/test/ZipReleaseAfterCopyTestCase.java
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/copy/AbstractCopyMechanism.java
Log:
Release zip file handles after they are copied to temp
Part of a fix for JBPAPP-2151


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 05:36:32 UTC (rev 92335)
+++ projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/context/zip/ZipEntryContext.java	2009-08-14 05:47:30 UTC (rev 92336)
@@ -881,7 +881,12 @@
       VirtualFileHandler rootHandler = getRoot();
       if (rootHandler.equals(handler))
       {
-         getZipSource().close(); // close == cleanup in zip source impl
+         ZipWrapper source = zipSource;
+         if (source != null)
+         {
+            source.close(); // close == cleanup in zip source impl
+            zipSource = null;
+         }
       }
    }
 

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 05:36:32 UTC (rev 92335)
+++ projects/vfs/branches/Branch_2_1/src/main/java/org/jboss/virtual/plugins/copy/AbstractCopyMechanism.java	2009-08-14 05:47:30 UTC (rev 92336)
@@ -159,6 +159,9 @@
       if (parent != null && replaceOldHandler(parent, handler, newHandler))
          parent.replaceChild(handler, newHandler);
 
+      // Release underlying file, so that Windows won't lock it
+      handler.cleanup();
+
       return newHandler.getVirtualFile();
    }
 
@@ -224,7 +227,7 @@
     */
    protected static void exactCopy(File copy, VirtualFileHandler root) throws IOException
    {
-      unpack(copy, root, COPY);   
+      unpack(copy, root, COPY);
    }
 
    /**
@@ -364,4 +367,4 @@
          }
       }
    }
-}
\ No newline at end of file
+}

Added: 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	                        (rev 0)
+++ projects/vfs/branches/Branch_2_1/src/test/java/org/jboss/test/virtual/test/ZipReleaseAfterCopyTestCase.java	2009-08-14 05:47:30 UTC (rev 92336)
@@ -0,0 +1,180 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.virtual.test;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.net.URI;
+import java.net.URL;
+
+import junit.framework.Test;
+
+import org.jboss.util.id.GUID;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VFSUtils;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.plugins.cache.LRUVFSCache;
+import org.jboss.virtual.plugins.context.DelegatingHandler;
+import org.jboss.virtual.plugins.context.zip.ZipEntryContext;
+import org.jboss.virtual.plugins.copy.AbstractCopyMechanism;
+import org.jboss.virtual.spi.VirtualFileHandler;
+import org.jboss.virtual.spi.cache.VFSCache;
+import org.jboss.virtual.spi.cache.VFSCacheFactory;
+import org.jboss.virtual.spi.registry.VFSRegistry;
+
+/**
+ * Verify a zip file is released after a temp copy is made.
+ *
+ * @author Jason T. Greene
+ */
+public class ZipReleaseAfterCopyTestCase extends AbstractVFSTest
+{
+   private File tempDir;
+
+   public ZipReleaseAfterCopyTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      VFS.init();
+      return suite(ZipReleaseAfterCopyTestCase.class);
+   }
+
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+
+      try
+      {
+         // nullify the temp dir
+         Class<?> clazz = AbstractCopyMechanism.class;
+         Field field = clazz.getDeclaredField("tempDir");
+         field.setAccessible(true);
+         field.set(null, null);
+
+         String tempDirKey = System.getProperty("vfs.temp.dir", "jboss.server.temp.dir");
+         String tempDirString = System.getProperty(tempDirKey, System.getProperty("java.io.tmpdir"));
+
+         tempDir = new File(new File(tempDirString), GUID.asString());
+         tempDir.deleteOnExit();
+         if (tempDir.exists())
+         {
+            deleteTempDir();
+         }
+         assertTrue("mkdir " + tempDir, tempDir.mkdir());
+
+         System.setProperty("jboss.server.temp.dir", tempDir.getCanonicalPath());
+
+         VFSCache cache = new LRUVFSCache(2, 5);
+         cache.start();
+         VFSCacheFactory.setInstance(cache);
+      }
+      catch (Exception e)
+      {
+         tearDown();
+         throw e;
+      }
+   }
+
+   protected String getProtocol()
+   {
+      return "vfszip:";
+   }
+
+   @Override
+   protected void tearDown() throws Exception
+   {
+      try
+      {
+         deleteTempDir();
+      }
+      catch (Throwable ignored)
+      {
+      }
+
+      try
+      {
+         VFSCacheFactory.getInstance().stop();
+         VFSCacheFactory.setInstance(null);
+
+         System.clearProperty("jboss.server.temp.dir");
+      }
+      catch (Throwable ignored)
+      {
+      }
+      finally
+      {
+         super.tearDown();
+      }
+   }
+
+   protected void deleteTempDir() throws IOException
+   {
+      // use vfs to disable possible reaper
+      VirtualFile td = VFS.getRoot(tempDir.toURI());
+      td.cleanup();
+      td.delete();
+   }
+
+
+   protected void assertNoRegistryEntry(URI uri) throws Exception
+   {
+      VFSRegistry registry = VFSRegistry.getInstance();
+      VirtualFile file = registry.getFile(uri);
+      assertNull("" + uri, file);
+   }
+
+   public void testReleaseAfterCopy() throws Exception
+   {
+      URL url = getResource("/vfs/test/nested/nested.jar");
+      VirtualFile root = VFS.getRoot(url);
+      assertNotNull(root);
+
+      VirtualFile copy = VFSUtils.temp(root);
+      assertNotNull(copy);
+      assertTrue(VFSUtils.isTemporaryFile(copy));
+
+      Method method = VirtualFile.class.getDeclaredMethod("getHandler");
+      method.setAccessible(true);
+      VirtualFileHandler h = (VirtualFileHandler)method.invoke(root);
+      if (h instanceof DelegatingHandler)
+         h = ((DelegatingHandler)h).getDelegate();
+
+      method = h.getClass().getDeclaredMethod("getZipEntryContext");
+      method.setAccessible(true);
+
+      Field field = ZipEntryContext.class.getDeclaredField("zipSource");
+      field.setAccessible(true);
+      Object object = field.get(method.invoke(h));
+      assertNull(object);
+      assertNotNull(root.openStream());
+
+      root.cleanup();
+      copy.cleanup();
+      assertNoRegistryEntry(root.toURI());
+   }
+}
\ No newline at end of file


Property changes on: projects/vfs/branches/Branch_2_1/src/test/java/org/jboss/test/virtual/test/ZipReleaseAfterCopyTestCase.java
___________________________________________________________________
Name: svn:keywords
   + Id Revision
Name: svn:eol-style
   + LF




More information about the jboss-cvs-commits mailing list