You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2011/08/29 04:19:46 UTC

svn commit: r1162635 - in /camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote: FtpOperations.java SftpOperations.java

Author: ningjiang
Date: Mon Aug 29 02:19:46 2011
New Revision: 1162635

URL: http://svn.apache.org/viewvc?rev=1162635&view=rev
Log:
CAMEL-4356 faster way of testing for file existence

Modified:
    camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
    camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java

Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java?rev=1162635&r1=1162634&r2=1162635&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java (original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java Mon Aug 29 02:19:46 2011
@@ -507,29 +507,12 @@ public class FtpOperations implements Re
 
     public boolean existsFile(String name) throws GenericFileOperationFailedException {
         log.trace("existsFile({})", name);
-
-        // check whether a file already exists
-        String directory = FileUtil.onlyPath(name);
-        String onlyName = FileUtil.stripPath(name);
-        try {
-            String[] names;
-            if (directory != null) {
-                names = client.listNames(directory);
-            } else {
-                names = client.listNames();
-            }
-            // can return either null or an empty list depending on FTP servers
+        try {
+            String[] names = client.listNames(name);
             if (names == null) {
                 return false;
             }
-            for (String existing : names) {
-                log.trace("Existing file: {}, target file: {}", existing, name);
-                existing = FileUtil.stripPath(existing);
-                if (existing != null && existing.equals(onlyName)) {
-                    return true;
-                }
-            }
-            return false;
+            return (names.length >= 1);
         } catch (IOException e) {
             throw new GenericFileOperationFailedException(client.getReplyCode(), client.getReplyString(), e.getMessage(), e);
         }

Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java?rev=1162635&r1=1162634&r2=1162635&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java (original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java Mon Aug 29 02:19:46 2011
@@ -678,31 +678,12 @@ public class SftpOperations implements R
 
     public boolean existsFile(String name) throws GenericFileOperationFailedException {
         LOG.trace("existsFile({})", name);
-
-        // check whether a file already exists
-        String directory = FileUtil.onlyPath(name);
-        if (directory == null) {
-            // assume current dir if no path could be extracted
-            directory = ".";
-        }
-        String onlyName = FileUtil.stripPath(name);
-
         try {
-            Vector files = channel.ls(directory);
-            // can return either null or an empty list depending on FTP servers
+            Vector files = channel.ls(name);
             if (files == null) {
                 return false;
             }
-            for (Object file : files) {
-                ChannelSftp.LsEntry entry = (ChannelSftp.LsEntry) file;
-                String existing = entry.getFilename();
-                LOG.trace("Existing file: {}, target file: {}", existing, name);
-                existing = FileUtil.stripPath(existing);
-                if (existing != null && existing.equals(onlyName)) {
-                    return true;
-                }
-            }
-            return false;
+            return (files.size() >= 1);
         } catch (SftpException e) {
             // or an exception can be thrown with id 2 which means file does not exists
             if (ChannelSftp.SSH_FX_NO_SUCH_FILE == e.id) {
@@ -711,6 +692,7 @@ public class SftpOperations implements R
             // otherwise its a more serious error so rethrow
             throw new GenericFileOperationFailedException(e.getMessage(), e);
         }
+
     }
 
     public boolean sendNoop() throws GenericFileOperationFailedException {