FTPSERVER-375 - use canonicalPath rather than File to implement equals and hashcode
authorSebastian Bazley <sebb@apache.org>
Wed, 22 Jun 2011 21:08:23 +0000 (21:08 +0000)
committerSebastian Bazley <sebb@apache.org>
Wed, 22 Jun 2011 21:08:23 +0000 (21:08 +0000)
git-svn-id: https://svn.apache.org/repos/asf/mina/ftpserver/trunk@1138635 13f79535-47bb-0310-9956-ffa450edef68

core/src/main/java/org/apache/ftpserver/filesystem/nativefs/impl/NativeFtpFile.java

index 4052ff6..3d1bf3c 100644 (file)
@@ -394,21 +394,25 @@ public class NativeFtpFile implements FtpFile {
         };
     }
 
+    /**
+     * Implements equals by comparing getCanonicalPath() for the underlying file instabnce.
+     * Ignores the fileName and User fields
+     */
     @Override
     public boolean equals(Object obj) {
         if (obj instanceof NativeFtpFile) {
-            File thisCanonicalFile;
-            File otherCanonicalFile;
+            String thisCanonicalPath;
+            String otherCanonicalPath;
             try {
-                thisCanonicalFile = this.file.getCanonicalFile();
-                otherCanonicalFile = ((NativeFtpFile) obj).file
-                        .getCanonicalFile();
+                thisCanonicalPath = this.file.getCanonicalPath();
+                otherCanonicalPath = ((NativeFtpFile) obj).file
+                        .getCanonicalPath();
             } catch (IOException e) {
                 throw new RuntimeException("Failed to get the canonical path",
                         e);
             }
 
-            return thisCanonicalFile.equals(otherCanonicalFile);
+            return thisCanonicalPath.equals(otherCanonicalPath);
         }
         return false;
     }
@@ -416,7 +420,7 @@ public class NativeFtpFile implements FtpFile {
        @Override
        public int hashCode() {
                try {
-                       return file.getCanonicalFile().hashCode();
+                       return file.getCanonicalPath().hashCode();
                } catch (IOException e) {
                        return 0;
                }