[camel] branch camel-2.22.x updated: CAMEL-12733. Check if directory exists via ls, so we don't need to return back to original dir later.

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[camel] branch camel-2.22.x updated: CAMEL-12733. Check if directory exists via ls, so we don't need to return back to original dir later.

acosentino
This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch camel-2.22.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-2.22.x by this push:
     new 3d80adf  CAMEL-12733. Check if directory exists via ls, so we don't need to return back to original dir later.
3d80adf is described below

commit 3d80adf2837bf03a83c4e55cc96d5071136893c9
Author: evilball <[hidden email]>
AuthorDate: Mon Sep 10 02:09:48 2018 +0300

    CAMEL-12733. Check if directory exists via ls, so we don't need to return back to original dir later.
---
 .../apache/camel/component/file/remote/SftpOperations.java  | 13 ++-----------
 1 file changed, 2 insertions(+), 11 deletions(-)

diff --git a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
index 1f58ea8..09cda57 100644
--- a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
+++ b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
@@ -476,11 +476,10 @@ public class SftpOperations implements RemoteFileOperations<SftpRemoteFile> {
         // ignore absolute as all dirs are relative with FTP
         boolean success = false;
 
-        String originalDirectory = getCurrentDirectory();
         try {
             // maybe the full directory already exists
             try {
-                channel.cd(directory);
+                channel.ls(directory);
                 success = true;
             } catch (SftpException e) {
                 // ignore, we could not change directory so try to create it instead
@@ -498,17 +497,9 @@ public class SftpOperations implements RemoteFileOperations<SftpRemoteFile> {
                     success = buildDirectoryChunks(directory);
                 }
             }
-        } catch (IOException e) {
-            throw new GenericFileOperationFailedException("Cannot build directory: " + directory, e);
-        } catch (SftpException e) {
+        } catch (IOException | SftpException e) {
             throw new GenericFileOperationFailedException("Cannot build directory: " + directory, e);
-        } finally {
-            // change back to original directory
-            if (originalDirectory != null) {
-                changeCurrentDirectory(originalDirectory);
-            }
         }
-
         return success;
     }