camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1146092 - in /camel/branches/camel-2.7.x: ./ components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
Date Wed, 13 Jul 2011 15:12:06 GMT
Author: dkulp
Date: Wed Jul 13 15:12:06 2011
New Revision: 1146092

URL: http://svn.apache.org/viewvc?rev=1146092&view=rev
Log:
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.
........

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

Propchange: camel/branches/camel-2.7.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Wed Jul 13 15:12:06 2011
@@ -1 +1 @@
-/camel/trunk:1083696,1083723-1083724,1084150,1085277,1085543,1085549,1085905,1085909,1086165,1086231,1087005,1087276,1087612,1087620,1087856,1088583,1088916-1088917,1089275,1089348,1090166,1090204,1090564,1090960-1090969,1091082,1091518,1091771,1091799,1092034,1092068,1092577,1092667,1093978,1093980,1093999,1094123,1094147,1094156,1095405,1095469,1095471,1095475-1095476,1096346,1096736,1097761,1097909,1097912,1097978,1098032,1098628,1098630,1099228,1099417,1100711,1100975,1102162,1102177,1102181,1104076,1124497,1127744,1127988,1128315,1128970,1131411,1132961,1134252,1134260,1134404,1134441,1134501,1134626,1134681,1134714-1134911,1135223,1135364,1136065,1136290,1137696,1138285,1139163,1139747,1139749,1140096-1140102,1141783,1142500,1142654,1142721,1143332,1143925,1144248,1144324,1145994,1146057
+/camel/trunk:1083696,1083723-1083724,1084150,1085277,1085543,1085549,1085905,1085909,1086165,1086231,1087005,1087276,1087612,1087620,1087856,1088583,1088916-1088917,1089275,1089348,1090166,1090204,1090564,1090960-1090969,1091082,1091518,1091771,1091799,1092034,1092068,1092577,1092667,1093978,1093980,1093999,1094123,1094147,1094156,1095405,1095469,1095471,1095475-1095476,1096346,1096736,1097761,1097909,1097912,1097978,1098032,1098628,1098630,1099228,1099417,1100711,1100975,1102162,1102177,1102181,1104076,1124497,1127744,1127988,1128315,1128970,1131411,1132961,1134252,1134260,1134404,1134441,1134501,1134626,1134681,1134714-1134911,1135223,1135364,1136065,1136290,1137696,1138285,1139163,1139747,1139749,1140096-1140102,1141783,1142500,1142654,1142721,1143332,1143925,1144248,1144324,1145887,1145994,1146057

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

Modified: camel/branches/camel-2.7.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.7.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java?rev=1146092&r1=1146091&r2=1146092&view=diff
==============================================================================
--- camel/branches/camel-2.7.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
(original)
+++ camel/branches/camel-2.7.x/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
Wed Jul 13 15:12:06 2011
@@ -48,7 +48,7 @@ import org.slf4j.LoggerFactory;
  * 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;
@@ -218,11 +218,39 @@ public class FtpOperations implements Re
         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
{
@@ -330,7 +358,7 @@ public class FtpOperations implements Re
 
     @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 {
@@ -338,7 +366,7 @@ public class FtpOperations implements Re
             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);
 
@@ -354,7 +382,7 @@ public class FtpOperations implements Re
             if (local.exists()) {
                 if (!FileUtil.deleteFile(local)) {
                     throw new GenericFileOperationFailedException("Cannot delete existing
local work file: " + local);
-                }                
+                }
             }
 
             // create new temp local work file
@@ -368,7 +396,7 @@ public class FtpOperations implements Re
             // 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);
         }
 
@@ -395,7 +423,7 @@ public class FtpOperations implements Re
             }
 
             result = client.retrieveFile(remoteName, os);
-            
+
             // change back to current directory
             if (endpoint.getConfiguration().isStepwise()) {
                 changeCurrentDirectory(currentDir);



Mime
View raw message