Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merged revisions 1145887 via svnmerge from
https://svn.apache.org/repos/asf/camel/trunk

........
  r1145887 | davsclaus | 2011-07-13 03:06:34 -0400 (Wed, 13 Jul 2011) | 1 line
  
  CAMEL-4215: camel-ftp will now honor stepwise option when deleting files. Thanks to dsmw for the patch.
........


git-svn-id: https://svn.apache.org/repos/asf/camel/branches/camel-2.7.x@1146092 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
dkulp committed Jul 13, 2011
1 parent 1cb90e8 commit daa886f
Showing 1 changed file with 35 additions and 7 deletions.
Expand Up @@ -48,7 +48,7 @@
* FTP remote file operations
*/
public class FtpOperations implements RemoteFileOperations<FTPFile> {

protected final transient Logger log = LoggerFactory.getLogger(getClass());
protected final FTPClient client;
protected final FTPClientConfig clientConfig;
Expand Down Expand Up @@ -218,11 +218,39 @@ public boolean deleteFile(String name) throws GenericFileOperationFailedExceptio
if (log.isDebugEnabled()) {
log.debug("Deleting file: " + name);
}

boolean result;
String target = name;
String currentDir = null;

try {
return this.client.deleteFile(name);
if (endpoint.getConfiguration().isStepwise()) {
// remember current directory
currentDir = getCurrentDirectory();
target = FileUtil.stripPath(name);

try {
changeCurrentDirectory(FileUtil.onlyPath(name));
} catch (GenericFileOperationFailedException e) {
// we could not change directory, try to change back before
changeCurrentDirectory(currentDir);
throw e;
}
}

// delete the file
result = client.deleteFile(target);

// change back to previous directory
if (currentDir != null) {
changeCurrentDirectory(currentDir);
}

} catch (IOException e) {
throw new GenericFileOperationFailedException(client.getReplyCode(), client.getReplyString(), e.getMessage(), e);
}

return result;
}

public boolean renameFile(String from, String to) throws GenericFileOperationFailedException {
Expand Down Expand Up @@ -330,15 +358,15 @@ private boolean retrieveFileToStreamInBody(String name, Exchange exchange) throw

@SuppressWarnings("unchecked")
private boolean retrieveFileToFileInLocalWorkDirectory(String name, Exchange exchange) throws GenericFileOperationFailedException {
File temp;
File temp;
File local = new File(FileUtil.normalizePath(endpoint.getLocalWorkDirectory()));
OutputStream os;
try {
// use relative filename in local work directory
GenericFile<FTPFile> target = (GenericFile<FTPFile>) exchange.getProperty(FileComponent.FILE_EXCHANGE_FILE);
ObjectHelper.notNull(target, "Exchange should have the " + FileComponent.FILE_EXCHANGE_FILE + " set");
String relativeName = target.getRelativeFilePath();

temp = new File(local, relativeName + ".inprogress");
local = new File(local, relativeName);

Expand All @@ -354,7 +382,7 @@ private boolean retrieveFileToFileInLocalWorkDirectory(String name, Exchange exc
if (local.exists()) {
if (!FileUtil.deleteFile(local)) {
throw new GenericFileOperationFailedException("Cannot delete existing local work file: " + local);
}
}
}

// create new temp local work file
Expand All @@ -368,7 +396,7 @@ private boolean retrieveFileToFileInLocalWorkDirectory(String name, Exchange exc
// set header with the path to the local work file
exchange.getIn().setHeader(Exchange.FILE_LOCAL_WORK_PATH, local.getPath());

} catch (Exception e) {
} catch (Exception e) {
throw new GenericFileOperationFailedException("Cannot create new local work file: " + local);
}

Expand All @@ -395,7 +423,7 @@ private boolean retrieveFileToFileInLocalWorkDirectory(String name, Exchange exc
}

result = client.retrieveFile(remoteName, os);

// change back to current directory
if (endpoint.getConfiguration().isStepwise()) {
changeCurrentDirectory(currentDir);
Expand Down

0 comments on commit daa886f

Please sign in to comment.