[infinispan-commits] Infinispan SVN: r1736 - trunk/core/src/main/java/org/infinispan/io.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Tue May 4 09:41:39 EDT 2010


Author: galder.zamarreno at jboss.com
Date: 2010-05-04 09:41:39 -0400 (Tue, 04 May 2010)
New Revision: 1736

Modified:
   trunk/core/src/main/java/org/infinispan/io/GridFile.java
Log:
[ISPN-416] (GridFS generating OS-dependant cache keys) Fixed by making sure file paths used as keys always use the same kind of separator, regardless of the OS.

Modified: trunk/core/src/main/java/org/infinispan/io/GridFile.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/io/GridFile.java	2010-05-03 19:15:11 UTC (rev 1735)
+++ trunk/core/src/main/java/org/infinispan/io/GridFile.java	2010-05-04 13:41:39 UTC (rev 1736)
@@ -29,6 +29,8 @@
  */
 public class GridFile extends File {
    private static final long serialVersionUID = -6729548421029004260L;
+   private static final char SEPARATOR_CHAR = '/';
+   private static final String SEPARATOR = "" + SEPARATOR_CHAR;
    private final AdvancedCache<String, Metadata> metadataCache;
    private final GridFilesystem fs;
    private final String name;
@@ -66,11 +68,21 @@
       return name;
    }
 
+   /**
+    * Returns path of this file. To avoid issues arising from file separator differences between different
+    * operative systems, the path returned always uses Unix-like path separator, '/' character. Any client
+    * code calling this method should bear that if disecting the path.
+    *
+    * @return String containing path of file.
+    */
    @Override
    public String getPath() {
       String my_path = super.getPath();
-      if (my_path != null && my_path.endsWith(File.separator)) {
-         int index = my_path.lastIndexOf(File.separator);
+      // Regardless of platform, always use the same separator char, otherwise
+      // keys might not be found when transfering metadata between different OS
+      my_path = my_path.replace('\\', SEPARATOR_CHAR);
+      if (my_path != null && my_path.endsWith(SEPARATOR)) {
+         int index = my_path.lastIndexOf(SEPARATOR);
          if (index != -1)
             my_path = my_path.substring(0, index);
       }
@@ -281,7 +293,7 @@
     * @return
     */
    protected boolean checkParentDirs(String path, boolean create_if_absent) throws IOException {
-      String[] components = Util.components(path, File.separator);
+      String[] components = Util.components(path, SEPARATOR);
       if (components == null)
          return false;
       if (components.length == 1) // no parent directories to create, e.g. "data.txt"
@@ -292,11 +304,11 @@
 
       for (int i = 0; i < components.length - 1; i++) {
          String tmp = components[i];
-         if (!tmp.equals(File.separator)) {
+         if (!tmp.equals(SEPARATOR)) {
             if (first)
                first = false;
             else
-               sb.append(File.separator);
+               sb.append(SEPARATOR);
          }
          sb.append(tmp);
          String comp = sb.toString();



More information about the infinispan-commits mailing list