db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r753251 - /db/derby/code/trunk/java/engine/org/apache/derby/impl/io/VFMemoryStorageFactory.java
Date Fri, 13 Mar 2009 13:49:56 GMT
Author: kristwaa
Date: Fri Mar 13 13:49:56 2009
New Revision: 753251

URL: http://svn.apache.org/viewvc?rev=753251&view=rev
Log:
DERBY-4094: Enforce absolute paths in the in-memory back end internal storage structure.
Makes all paths going into the internal storage structure be absolute paths. 
Patch file: derby-4094-1a-enforce_absolute_paths.diff

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/io/VFMemoryStorageFactory.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/io/VFMemoryStorageFactory.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/io/VFMemoryStorageFactory.java?rev=753251&r1=753250&r2=753251&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/io/VFMemoryStorageFactory.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/io/VFMemoryStorageFactory.java Fri
Mar 13 13:49:56 2009
@@ -65,7 +65,7 @@
         }
     }
 
-    /** The canonical (unique) name of the database. */
+    /** The canonical (unique) name of the database (absolute path). */
     private String canonicalName;
     /** The data directory of the database. */
     private StorageFile dataDirectory;
@@ -125,7 +125,7 @@
             }
             // Specify the data directory and the temp directory.
             dataDirectory = new VirtualFile(canonicalName, dbData);
-            tempDir = new VirtualFile(PathUtil.join(canonicalName, "tmp"),
+            tempDir = new VirtualFile(normalizePath(canonicalName, "tmp"),
                                       dbData);
 
         // Handle cases where the database name is null, but a system home
@@ -180,7 +180,7 @@
             // Return the database directory as described by StorageFactory.
             return dataDirectory;
         }
-        return new VirtualFile(path, dbData);
+        return new VirtualFile(normalizePath(path), dbData);
     }
 
     /**
@@ -191,7 +191,8 @@
      * @return A path handle.
      */
     public StorageFile newStorageFile(String directoryName, String fileName) {
-        return new VirtualFile(PathUtil.join(directoryName, fileName), dbData);
+            return new VirtualFile(
+                                normalizePath(directoryName, fileName), dbData);
     }
 
     /**
@@ -203,7 +204,9 @@
      */
     public StorageFile newStorageFile(StorageFile directoryName,
                                       String fileName) {
-        return newStorageFile(directoryName.getPath(), fileName);
+        return newStorageFile(directoryName == null ? null
+                                                    : directoryName.getPath(),
+                              fileName);
     }
 
     /**
@@ -291,4 +294,40 @@
         // TODO: What will give us the best performance here?
         return true;
     }
+
+    /**
+     * Returns a normalized absolute path.
+     *
+     * @param dir parent directory, if {@code null} the {@code dataDirectory}
+     *      will be used
+     * @param file the file name ({@code null} not allowed)
+     * @return A path.
+     * @throws NullPointerException if {@code file} is {@code null}
+     */
+    private String normalizePath(String dir, String file) {
+        if (dir == null || dir.equals("")) {
+            dir = dataDirectory.getPath();
+        } else if (dir.charAt(0) != getSeparator()) {
+            dir = new File(dataDirectory.getPath(), dir).getPath();
+        }
+        // We now have an absolute path for the directory.
+        // Use java.io.File to get consistent behavior.
+        return (new File(dir, file).getPath());
+    }
+
+    /**
+     * Returns a normalized absolute path.
+     *
+     * @param path path, if {@code null} the {@code dataDirectory} will be used
+     * @return A path.
+     */
+    private String normalizePath(String path) {
+        if (path == null || path.equals("")) {
+            return dataDirectory.getPath();
+        } else if (path.charAt(0) == getSeparator()) {
+            return path;
+        } else {
+            return new File(dataDirectory.getPath(), path).getPath();
+        }
+    }
 }



Mime
View raw message