You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2010/09/29 21:31:23 UTC
svn commit: r1002821 - in /camel/trunk:
camel-core/src/main/java/org/apache/camel/component/file/
components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/
Author: davsclaus
Date: Wed Sep 29 19:31:23 2010
New Revision: 1002821
URL: http://svn.apache.org/viewvc?rev=1002821&view=rev
Log:
CAMEL-3174: Changing dir with ftp must do one dir at a time.
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java
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/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java?rev=1002821&r1=1002820&r2=1002821&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFile.java Wed Sep 29 19:31:23 2010
@@ -163,7 +163,11 @@ public class GenericFile<T> {
// for relative then we should avoid having the endpoint path duplicated so clip it
if (ObjectHelper.isNotEmpty(endpointPath) && newFileName.startsWith(endpointPath)) {
// clip starting endpoint in case it was added
- newFileName = ObjectHelper.after(newFileName, endpointPath + getFileSeparator());
+ if (endpointPath.endsWith("" + getFileSeparator())) {
+ newFileName = ObjectHelper.after(newFileName, endpointPath);
+ } else {
+ newFileName = ObjectHelper.after(newFileName, endpointPath + getFileSeparator());
+ }
// reconstruct file with clipped name
file = new File(newFileName);
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=1002821&r1=1002820&r2=1002821&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 Wed Sep 29 19:31:23 2010
@@ -496,14 +496,39 @@ public class FtpOperations implements Re
}
public void changeCurrentDirectory(String path) throws GenericFileOperationFailedException {
+ if (ObjectHelper.isEmpty(path)) {
+ return;
+ }
+
+ // split into multiple dirs
+ final String[] dirs = path.split("/|\\\\");
+
+ if (dirs == null || dirs.length == 0) {
+ // this is the root path
+ doChangeDirectory(path);
+ return;
+ }
+
+ // there are multiple dirs so do this in chunks
+ for (String dir : dirs) {
+ doChangeDirectory(dir);
+ }
+ }
+
+ private void doChangeDirectory(String path) {
if (log.isTraceEnabled()) {
- log.trace("changeWorkingDirectory(" + path + ")");
+ log.trace("Changing directory: " + path);
}
+
+ boolean success;
try {
- client.changeWorkingDirectory(path);
+ success = client.changeWorkingDirectory(path);
} catch (IOException e) {
throw new GenericFileOperationFailedException(client.getReplyCode(), client.getReplyString(), e.getMessage(), e);
}
+ if (!success) {
+ throw new GenericFileOperationFailedException(client.getReplyCode(), client.getReplyString(), "Cannot change directory to: " + path);
+ }
}
public List<FTPFile> listFiles() throws GenericFileOperationFailedException {
@@ -593,4 +618,25 @@ public class FtpOperations implements Re
return success;
}
+ private boolean changeDirectoryChunks(String dirName) throws GenericFileOperationFailedException {
+ final String[] dirs = dirName.split("/|\\\\");
+
+ boolean success = false;
+ for (String dir : dirs) {
+ if (log.isTraceEnabled()) {
+ log.trace("Changing to directory: " + dir);
+ }
+ try {
+ success = client.changeWorkingDirectory(dir);
+ } catch (IOException e) {
+ throw new GenericFileOperationFailedException(client.getReplyCode(), client.getReplyString(), e.getMessage(), e);
+ }
+ if (!success) {
+ return false;
+ }
+ }
+
+ return success;
+ }
+
}
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=1002821&r1=1002820&r2=1002821&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 Wed Sep 29 19:31:23 2010
@@ -343,13 +343,33 @@ public class SftpOperations implements R
}
public void changeCurrentDirectory(String path) throws GenericFileOperationFailedException {
+ if (ObjectHelper.isEmpty(path)) {
+ return;
+ }
+
+ // split into multiple dirs
+ final String[] dirs = path.split("/|\\\\");
+
+ if (dirs == null || dirs.length == 0) {
+ // this is the root path
+ doChangeDirectory(path);
+ return;
+ }
+
+ // there are multiple dirs so do this in chunks
+ for (String dir : dirs) {
+ doChangeDirectory(dir);
+ }
+ }
+
+ private void doChangeDirectory(String path) {
if (LOG.isTraceEnabled()) {
- LOG.trace("Changing current directory to: " + path);
+ LOG.trace("Changing directory: " + path);
}
try {
channel.cd(path);
} catch (SftpException e) {
- throw new GenericFileOperationFailedException("Cannot change current directory to: " + path, e);
+ throw new GenericFileOperationFailedException("Cannot change directory to: " + path, e);
}
}