[jboss-cvs] JBossAS SVN: r101477 - in projects/vfs/trunk/src: main/java/org/jboss/vfs/spi and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Feb 25 10:15:47 EST 2010


Author: alesj
Date: 2010-02-25 10:15:47 -0500 (Thu, 25 Feb 2010)
New Revision: 101477

Modified:
   projects/vfs/trunk/src/main/java/org/jboss/vfs/VFS.java
   projects/vfs/trunk/src/main/java/org/jboss/vfs/spi/JavaZipFileSystem.java
   projects/vfs/trunk/src/test/java/org/jboss/test/vfs/SymlinkTestCase.java
Log:
[JBVFS-138]; force canonical path lookup.

Modified: projects/vfs/trunk/src/main/java/org/jboss/vfs/VFS.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/vfs/VFS.java	2010-02-25 15:03:19 UTC (rev 101476)
+++ projects/vfs/trunk/src/main/java/org/jboss/vfs/VFS.java	2010-02-25 15:15:47 UTC (rev 101477)
@@ -64,6 +64,7 @@
     private static final Logger log = Logger.getLogger("org.jboss.vfs");
 
     public static final boolean LEAK_DEBUGGING;
+    public static final boolean FORCE_CANONICAL;
 
     private static final ConcurrentMap<VirtualFile, Map<String, Mount>> mounts = new ConcurrentHashMap<VirtualFile, Map<String, Mount>>();
     private static final VirtualFile rootVirtualFile = new VirtualFile("", null);
@@ -77,7 +78,15 @@
             public Boolean run() {
                 return Boolean.valueOf(System.getProperty("jboss.vfs.leakDebugging", "true"));
             }
-        }).booleanValue();
+        });
+        FORCE_CANONICAL = AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
+            public Boolean run() {
+                return Boolean.getBoolean("jboss.vfs.forceCanonical");
+            }
+        });
+
+        if (FORCE_CANONICAL)
+           log.info("Canonical path lookup enabled.");
     }
 
     /**
@@ -185,9 +194,33 @@
     public static VirtualFile getChild(String path) {
         if (path == null)
             throw new IllegalArgumentException("Null path");
-        return getRootVirtualFile().getChild(path);
+        return getRootVirtualFile().getChild(canonicalize(path));
     }
 
+   /**
+    * Canonicalize path.
+    *
+    * @param path the path to canonicalize
+    * @return canonical path of given @param path
+    */
+    private static String canonicalize(String path)
+    {
+       if (FORCE_CANONICAL)
+       {
+          File file = new File(path);
+          try
+          {
+             file = file.getCanonicalFile();
+          }
+          catch (IOException e)
+          {
+             throw new RuntimeException("Cannot get canonical file for path: " + path, e);
+          }
+          return file.getPath();
+       }
+       return path;
+    }
+
     /**
      * Get the root virtual file for this VFS instance.
      *

Modified: projects/vfs/trunk/src/main/java/org/jboss/vfs/spi/JavaZipFileSystem.java
===================================================================
--- projects/vfs/trunk/src/main/java/org/jboss/vfs/spi/JavaZipFileSystem.java	2010-02-25 15:03:19 UTC (rev 101476)
+++ projects/vfs/trunk/src/main/java/org/jboss/vfs/spi/JavaZipFileSystem.java	2010-02-25 15:15:47 UTC (rev 101477)
@@ -268,11 +268,7 @@
     }
 
     private ZipNode getZipNode(VirtualFile mountPoint, VirtualFile target) {
-        final ZipNode zipNode = rootNode.find(mountPoint, target);
-        if (zipNode == null) {
-            return null;
-        }
-        return zipNode;
+        return rootNode.find(mountPoint, target);
     }
 
     private ZipNode getExistingZipNode(VirtualFile mountPoint, VirtualFile target)

Modified: projects/vfs/trunk/src/test/java/org/jboss/test/vfs/SymlinkTestCase.java
===================================================================
--- projects/vfs/trunk/src/test/java/org/jboss/test/vfs/SymlinkTestCase.java	2010-02-25 15:03:19 UTC (rev 101476)
+++ projects/vfs/trunk/src/test/java/org/jboss/test/vfs/SymlinkTestCase.java	2010-02-25 15:15:47 UTC (rev 101477)
@@ -70,6 +70,9 @@
    {
       super.setUp();
 
+      // set force canonical
+      System.setProperty("jboss.vfs.forceCanonical", Boolean.TRUE.toString());
+
       // setup symlink dir and test path!
 
 //      System.setProperty("test.dir", "/Users/alesj/projects/jboss6/trunk"); // plain path
@@ -84,7 +87,9 @@
    @Override
    protected void tearDown() throws Exception
    {
+      System.clearProperty("jboss.vfs.forceCanonical");
       System.clearProperty("test.dir");
+
       testOuterJar = null;
       testInnerJar = null;
       testInnerFile = null;
@@ -134,7 +139,7 @@
          URL directRootURL = new URL("file://" + rootText + testOuterJar + "/" + testInnerJar + "/" + testInnerFile);
          conn = directRootURL.openConnection();
          long actual2 = conn.getLastModified();
-         assertEquals(expected, actual2); // TODO -- FIXME -- underlying file system is Real
+         assertEquals(expected, actual2);
       }
       finally
       {




More information about the jboss-cvs-commits mailing list