You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by dk...@apache.org on 2011/09/20 00:58:29 UTC

svn commit: r1172883 - in /camel/branches/camel-2.8.x: ./ components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java

Author: dkulp
Date: Mon Sep 19 22:58:29 2011
New Revision: 1172883

URL: http://svn.apache.org/viewvc?rev=1172883&view=rev
Log:
Merged revisions 1162635 via svnmerge from 
https://svn.apache.org/repos/asf/camel/trunk

........
  r1162635 | ningjiang | 2011-08-28 22:19:46 -0400 (Sun, 28 Aug 2011) | 1 line
  
  CAMEL-4356 faster way of testing for file existence
........

Modified:
    camel/branches/camel-2.8.x/   (props changed)
    camel/branches/camel-2.8.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
    camel/branches/camel-2.8.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java

Propchange: camel/branches/camel-2.8.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: camel/branches/camel-2.8.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java?rev=1172883&r1=1172882&r2=1172883&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java (original)
+++ camel/branches/camel-2.8.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java Mon Sep 19 22:58:29 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/branches/camel-2.8.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java?rev=1172883&r1=1172882&r2=1172883&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java (original)
+++ camel/branches/camel-2.8.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java Mon Sep 19 22:58:29 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 {