Repository: activemq
Updated Branches:
  refs/heads/master 0c846cf8f -> 938aa626c


https://issues.apache.org/jira/browse/AMQ-6039

If the rename option fails, then we must try a complete copy since the
move can cross file systems.

Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/938aa626
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/938aa626
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/938aa626

Branch: refs/heads/master
Commit: 938aa626c2b6a4d285f0a481be32eb6eecb26333
Parents: 0c846cf
Author: Timothy Bish <[email protected]>
Authored: Tue Nov 10 11:07:18 2015 -0500
Committer: Timothy Bish <[email protected]>
Committed: Tue Nov 10 11:12:50 2015 -0500

----------------------------------------------------------------------
 .../java/org/apache/activemq/util/IOHelper.java     | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/938aa626/activemq-broker/src/main/java/org/apache/activemq/util/IOHelper.java
----------------------------------------------------------------------
diff --git 
a/activemq-broker/src/main/java/org/apache/activemq/util/IOHelper.java 
b/activemq-broker/src/main/java/org/apache/activemq/util/IOHelper.java
index a1ba3ec..fb0784c 100644
--- a/activemq-broker/src/main/java/org/apache/activemq/util/IOHelper.java
+++ b/activemq-broker/src/main/java/org/apache/activemq/util/IOHelper.java
@@ -23,12 +23,15 @@ import java.io.FilenameFilter;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Stack;
 
 /**
- *
+ * Collection of File and Folder utility methods.
  */
 public final class IOHelper {
 
@@ -186,7 +189,16 @@ public final class IOHelper {
 
     public static void moveFile(File src, File targetDirectory) throws 
IOException {
         if (!src.renameTo(new File(targetDirectory, src.getName()))) {
-            throw new IOException("Failed to move " + src + " to " + 
targetDirectory);
+
+            // If rename fails we must do a true deep copy instead.
+            Path sourcePath = src.toPath();
+            Path targetDirPath = targetDirectory.toPath();
+
+            try {
+                Files.move(sourcePath, 
targetDirPath.resolve(sourcePath.getFileName()), 
StandardCopyOption.REPLACE_EXISTING);
+            } catch (IOException ex) {
+                throw new IOException("Failed to move " + src + " to " + 
targetDirectory + " - " + ex.getMessage());
+            }
         }
     }
 

Reply via email to