mina-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n..@apache.org
Subject svn commit: r751388 - /mina/ftpserver/branches/1.0.x/core/src/main/java/org/apache/ftpserver/filesystem/nativefs/impl/NativeFtpFile.java
Date Sun, 08 Mar 2009 09:22:49 GMT
Author: ngn
Date: Sun Mar  8 09:22:47 2009
New Revision: 751388

URL: http://svn.apache.org/viewvc?rev=751388&view=rev
Log:
Fix for File.equals problem on OS X, we now use the canonical path instead which seems to
work. Thanks Sai Pullabhotla for the patch! (FTPSERVER-279)

Modified:
    mina/ftpserver/branches/1.0.x/core/src/main/java/org/apache/ftpserver/filesystem/nativefs/impl/NativeFtpFile.java

Modified: mina/ftpserver/branches/1.0.x/core/src/main/java/org/apache/ftpserver/filesystem/nativefs/impl/NativeFtpFile.java
URL: http://svn.apache.org/viewvc/mina/ftpserver/branches/1.0.x/core/src/main/java/org/apache/ftpserver/filesystem/nativefs/impl/NativeFtpFile.java?rev=751388&r1=751387&r2=751388&view=diff
==============================================================================
--- mina/ftpserver/branches/1.0.x/core/src/main/java/org/apache/ftpserver/filesystem/nativefs/impl/NativeFtpFile.java
(original)
+++ mina/ftpserver/branches/1.0.x/core/src/main/java/org/apache/ftpserver/filesystem/nativefs/impl/NativeFtpFile.java
Sun Mar  8 09:22:47 2009
@@ -49,7 +49,7 @@
 public class NativeFtpFile implements FtpFile {
 
     private final Logger LOG = LoggerFactory.getLogger(NativeFtpFile.class);
-    
+
     // the file name with respect to the user root.
     // The path separator character will be '/' and
     // it will always begin with '/'.
@@ -192,7 +192,7 @@
     public boolean setLastModified(long time) {
         return file.setLastModified(time);
     }
-    
+
     /**
      * Check read permission.
      */
@@ -215,7 +215,7 @@
             LOG.debug("Checking can write: " + file.canWrite());
             return file.canWrite();
         }
-        
+
         LOG.debug("Authorized");
         return true;
     }
@@ -225,7 +225,6 @@
      */
     public boolean isRemovable() {
 
-
         // root cannot be deleted
         if ("/".equals(fileName)) {
             return false;
@@ -235,25 +234,25 @@
          * we will check if the parent file has write permission as most systems consider
that a file can
          * be deleted when their parent directory is writable.
         */
-        String fullName=getAbsolutePath();
-        
+        String fullName = getAbsolutePath();
+
         // we check FTPServer's write permission for this file.
         if (user.authorize(new WriteRequest(fullName)) == null) {
             return false;
         }
         // In order to maintain consistency, when possible we delete the last '/' character
in the String
-        int indexOfSlash=fullName.lastIndexOf('/');
+        int indexOfSlash = fullName.lastIndexOf('/');
         String parentFullName;
-        if (indexOfSlash==0){
-         parentFullName="/";
-        }
-        else{
-         parentFullName=fullName.substring(0,indexOfSlash);
+        if (indexOfSlash == 0) {
+            parentFullName = "/";
+        } else {
+            parentFullName = fullName.substring(0, indexOfSlash);
         }
-        
+
         // we check if the parent FileObject is writable.
-        NativeFtpFile parentObject=new NativeFtpFile(parentFullName,file.getAbsoluteFile().getParentFile(),user);
-        return parentObject.isWritable(); 
+        NativeFtpFile parentObject = new NativeFtpFile(parentFullName, file
+                .getAbsoluteFile().getParentFile(), user);
+        return parentObject.isWritable();
     }
 
     /**
@@ -496,7 +495,7 @@
                 File[] matches = new File(resArg)
                         .listFiles(new NameEqualsFileFilter(tok, true));
 
-                if (matches.length > 0) {
+                if (matches != null && matches.length > 0) {
                     tok = matches[0].getName();
                 }
             }
@@ -517,12 +516,22 @@
 
         return resArg;
     }
-    
+
     @Override
     public boolean equals(Object obj) {
-    	if(obj != null && obj instanceof NativeFtpFile) {
-    		return this.file.equals(((NativeFtpFile) obj).file);
-    	}
-    	return false;
+        if (obj != null && obj instanceof NativeFtpFile) {
+            File thisCanonicalFile;
+            File otherCanonicalFile;
+            try {
+                thisCanonicalFile = this.file.getCanonicalFile();
+                otherCanonicalFile = ((NativeFtpFile) obj).file
+                        .getCanonicalFile();
+            } catch (IOException e) {
+                throw new RuntimeException("Failed to get the canonical path", e);
+            }
+
+            return thisCanonicalFile.equals(otherCanonicalFile);
+        }
+        return false;
     }
 }



Mime
View raw message