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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Feb 19 12:20:09 EST 2010


Author: alesj
Date: 2010-02-19 12:20:08 -0500 (Fri, 19 Feb 2010)
New Revision: 101180

Modified:
   projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/VFSUtils.java
   projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/registry/DefaultVFSRegistry.java
   projects/vfs/branches/Branch_2_2/src/test/java/org/jboss/test/virtual/test/SymlinkTestCase.java
Log:
[JBVFS-136]; handle symlinks.

Modified: projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/VFSUtils.java
===================================================================
--- projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/VFSUtils.java	2010-02-19 17:00:44 UTC (rev 101179)
+++ projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/VFSUtils.java	2010-02-19 17:20:08 UTC (rev 101180)
@@ -105,6 +105,11 @@
    public static final String CASE_SENSITIVE_QUERY = "caseSensitive";
 
    /**
+    * Key used to force canonical lookup
+    */
+   public static final String FORCE_CANONICAL_LOOKUP = "jboss.vfs.forceCanonicalLookup";
+
+   /**
     * Key used to turn on memory optimizations - less cache use at the expense of performance
     */
    public static final String OPTIMIZE_FOR_MEMORY_KEY = "jboss.vfs.optimizeForMemory";

Modified: projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/registry/DefaultVFSRegistry.java
===================================================================
--- projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/registry/DefaultVFSRegistry.java	2010-02-19 17:00:44 UTC (rev 101179)
+++ projects/vfs/branches/Branch_2_2/src/main/java/org/jboss/virtual/plugins/registry/DefaultVFSRegistry.java	2010-02-19 17:20:08 UTC (rev 101180)
@@ -21,13 +21,7 @@
  */
 package org.jboss.virtual.plugins.registry;
 
-import java.io.IOException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.util.List;
-import java.util.Set;
-
+import org.jboss.logging.Logger;
 import org.jboss.virtual.VFSUtils;
 import org.jboss.virtual.VirtualFile;
 import org.jboss.virtual.spi.TempInfo;
@@ -38,6 +32,15 @@
 import org.jboss.virtual.spi.cache.VFSCacheFactory;
 import org.jboss.virtual.spi.registry.VFSRegistry;
 
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.List;
+import java.util.Set;
+
 /**
  * Default vfs registry.
  *
@@ -45,6 +48,17 @@
  */
 public class DefaultVFSRegistry extends VFSRegistry
 {
+   /** Do we force canonical lookup */
+   private static boolean forceCanonical;
+
+   static
+   {
+      forceCanonical = AccessController.doPrivileged(new CheckForceCanonical());
+
+      if (forceCanonical)
+         Logger.getLogger(DefaultVFSRegistry.class).info("VFS force canonical lookup is enabled.");
+   }
+
    /**
     * Get vfs cache.
     *
@@ -83,8 +97,46 @@
       }
    }
 
+   /**
+    * Canonicalize uri.
+    *
+    * @param uri the uri
+    * @return canonical uri
+    * @throws IOException for any IO error
+    */
+   protected static URI canonicalize(URI uri) throws IOException
+   {
+      // TODO -- this file "recursion" needs more testing ...
+      if (forceCanonical)
+      {
+         String path = "";
+         File file = new File(uri.getPath());
+         while(file.exists() == false)
+         {
+            path = File.separator + file.getName() + path;
+            file = file.getParentFile();
+         }
+         file = file.getCanonicalFile();
+         try
+         {
+            return new URI(uri.getScheme(), uri.getHost(), file.getPath() + path, uri.getQuery(), uri.getFragment());
+         }
+         catch (URISyntaxException e)
+         {
+            IOException ioe = new IOException();
+            ioe.initCause(e);
+            throw ioe;
+         }
+      }
+      return uri;
+   }
+
    public VFSContext getContext(URI uri) throws IOException
    {
+      if (uri == null)
+         throw new IllegalArgumentException("Null uri");
+
+      uri = canonicalize(uri);
       VFSContext context = getCache().findContext(uri);
       if (context != null)
       {
@@ -100,6 +152,7 @@
       if (uri == null)
          throw new IllegalArgumentException("Null uri");
 
+      uri = canonicalize(uri);
       VFSContext context = getCache().findContext(uri);
       if (context != null)
       {
@@ -141,4 +194,16 @@
       }
       return child;
    }
+
+   /**
+    * <tt>PriviligedAction</tt> class for checking a system property
+    */
+   private static class CheckForceCanonical implements PrivilegedAction<Boolean>
+   {
+      public Boolean run()
+      {
+         String forceString = System.getProperty(VFSUtils.FORCE_CANONICAL_LOOKUP, "false");
+         return Boolean.valueOf(forceString);
+      }
+   }
 }

Modified: projects/vfs/branches/Branch_2_2/src/test/java/org/jboss/test/virtual/test/SymlinkTestCase.java
===================================================================
--- projects/vfs/branches/Branch_2_2/src/test/java/org/jboss/test/virtual/test/SymlinkTestCase.java	2010-02-19 17:00:44 UTC (rev 101179)
+++ projects/vfs/branches/Branch_2_2/src/test/java/org/jboss/test/virtual/test/SymlinkTestCase.java	2010-02-19 17:20:08 UTC (rev 101180)
@@ -76,6 +76,9 @@
    {
       super.setUp();
 
+      // enable force canonical
+      System.setProperty(VFSUtils.FORCE_CANONICAL_LOOKUP, "true");
+
       // setup symlink dir and test path!
 
 //      System.setProperty("test.dir", "/Users/alesj/projects/jboss6/trunk"); // plain path




More information about the jboss-cvs-commits mailing list