[jboss-cvs] JBossAS SVN: r91123 - in projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual: spi and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Jul 10 21:58:38 EDT 2009


Author: david.lloyd at jboss.com
Date: 2009-07-10 21:58:38 -0400 (Fri, 10 Jul 2009)
New Revision: 91123

Modified:
   projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/TempFileProvider.java
   projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/VFS.java
   projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/spi/ZipFileSystem.java
Log:
Case sensitivity fixes; fix temp directory creation; handle missing mount nodes properly

Modified: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/TempFileProvider.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/TempFileProvider.java	2009-07-11 00:24:20 UTC (rev 91122)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/TempFileProvider.java	2009-07-11 01:58:38 UTC (rev 91123)
@@ -29,6 +29,8 @@
 import java.io.FileOutputStream;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
+import java.util.Random;
+import java.security.SecureRandom;
 
 /**
  * A provider for temporary physical files and directories.
@@ -42,10 +44,10 @@
       final String configTmpDir = System.getProperty(TMP_DIR_PROPERTY);
       try
       {
-         TMP_ROOT = configTmpDir == null ? File.createTempFile("jboss-vfs-temp", "") : new File(configTmpDir, "vfs");
+         TMP_ROOT = new File(configTmpDir, "vfs");
          TMP_ROOT.mkdirs();
       }
-      catch (IOException e)
+      catch (Exception e)
       {
          throw new RuntimeException("Can't set up temp file provider", e);
       }
@@ -60,7 +62,7 @@
     */
    public static TempFileProvider create(String providerType, ScheduledExecutorService executor) throws IOException
    {
-      return new TempFileProvider(File.createTempFile(providerType, "", TMP_ROOT), 0, executor);
+      return new TempFileProvider(createTempDir(providerType, "", TMP_ROOT), 0, executor);
    }
 
    /**
@@ -74,7 +76,7 @@
     */
    public static TempFileProvider create(String providerType, int hashDepth, ScheduledExecutorService executor) throws IOException
    {
-      return new TempFileProvider(File.createTempFile(providerType, "", TMP_ROOT), hashDepth, executor);
+      return new TempFileProvider(createTempDir(providerType, "", TMP_ROOT), hashDepth, executor);
    }
 
    private final File providerRoot;
@@ -118,7 +120,7 @@
          root.mkdir();
          hashCode >>= 7;
       }
-      return File.createTempFile("", "-" + originalName, root);
+      return createTempFile("tmp", "-" + originalName, root);
    }
 
    /**
@@ -152,6 +154,38 @@
       }
    }
 
+   private static final Random rng = new SecureRandom();
+
+   private static File createTempDir(String prefix, String suffix, File root) throws IOException
+   {
+      for (int i = 0; i < 100; i ++) {
+         final File f = new File(root, createTempName(prefix, suffix));
+         if (f.mkdir())
+            return f;
+      }
+      final IOException eo = new IOException("Could not create directory after 100 attempts");
+      throw eo;
+   }
+
+   private static File createTempFile(String prefix, String suffix, File root) throws IOException
+   {
+      IOException e = null;
+      for (int i = 0; i < 100; i ++) try {
+         final File f = new File(root, createTempName(prefix, suffix));
+         f.createNewFile();
+         return f;
+      } catch (IOException e2) {
+         e = e2;
+      }
+      final IOException eo = new IOException("Could not create file after 100 attempts");
+      eo.initCause(e);
+      throw eo;
+   }
+
+   private static String createTempName(String prefix, String suffix) {
+      return prefix + Long.toHexString(rng.nextLong()) + suffix;
+   }
+
    /**
     * Close this provider and delete any temp files associated with it.
     */

Modified: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/VFS.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/VFS.java	2009-07-11 00:24:20 UTC (rev 91122)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/VFS.java	2009-07-11 01:58:38 UTC (rev 91123)
@@ -305,7 +305,11 @@
          }
       }
       final List<String> list = new ArrayList<String>();
-      for (Map.Entry<String, MountNode> entry : mountNode.nodeMap.entrySet())
+      final Map<String, MountNode> childMap = mountNode.nodeMap;
+      if (childMap == null) {
+         return Collections.<String>emptySet().iterator();
+      }
+      for (Map.Entry<String, MountNode> entry : childMap.entrySet())
       {
          final MountNode subNode = entry.getValue();
          if (subNode.mount != null) {

Modified: projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/spi/ZipFileSystem.java
===================================================================
--- projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/spi/ZipFileSystem.java	2009-07-11 00:24:20 UTC (rev 91122)
+++ projects/vfs/branches/dml-zip-rework/src/main/java/org/jboss/virtual/spi/ZipFileSystem.java	2009-07-11 01:58:38 UTC (rev 91123)
@@ -218,12 +218,36 @@
 
    public Iterator<String> getDirectoryEntries(List<String> directoryPathComponents) throws IOException
    {
-      return null;
+      final ZipNode zipNode = rootNode.find(directoryPathComponents.iterator());
+      if (zipNode != null) {
+         final Map<String, ZipNode> children = zipNode.children;
+         if (children != null) {
+            final Iterator<ZipNode> it = children.values().iterator();
+            return new Iterator<String>()
+            {
+               public boolean hasNext()
+               {
+                  return it.hasNext();
+               }
+
+               public String next()
+               {
+                  return it.next().name;
+               }
+
+               public void remove()
+               {
+                  throw new UnsupportedOperationException();
+               }
+            };
+         }
+      }
+      throw new FileNotFoundException(join(directoryPathComponents));
    }
 
    public void close() throws IOException
    {
-      
+      tempFileProvider.close();
    }
 
    private static final class ZipNode {




More information about the jboss-cvs-commits mailing list