You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@twill.apache.org by ch...@apache.org on 2015/12/05 09:26:56 UTC

incubator-twill git commit: (TWILL-156) use Files.move instead of File.renameTo so we can have options to replace existing files and perform atomic move, this allows us to support windows rename

Repository: incubator-twill
Updated Branches:
  refs/heads/master 87b063cac -> 359b12b90


(TWILL-156) use Files.move instead of File.renameTo so we can have options to replace existing files and perform atomic move, this allows us to support windows rename

This closes #72 on GitHub.

Signed-off-by: Terence Yim <ch...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/incubator-twill/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-twill/commit/359b12b9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-twill/tree/359b12b9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-twill/diff/359b12b9

Branch: refs/heads/master
Commit: 359b12b904e0c52c54453c6afc5ef578d484c0a5
Parents: 87b063c
Author: shankar <sh...@cask.co>
Authored: Fri Dec 4 15:46:59 2015 -0800
Committer: Terence Yim <ch...@apache.org>
Committed: Fri Dec 4 23:56:58 2015 -0800

----------------------------------------------------------------------
 .../java/org/apache/twill/filesystem/LocalLocation.java  | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-twill/blob/359b12b9/twill-common/src/main/java/org/apache/twill/filesystem/LocalLocation.java
----------------------------------------------------------------------
diff --git a/twill-common/src/main/java/org/apache/twill/filesystem/LocalLocation.java b/twill-common/src/main/java/org/apache/twill/filesystem/LocalLocation.java
index a560694..a873545 100644
--- a/twill-common/src/main/java/org/apache/twill/filesystem/LocalLocation.java
+++ b/twill-common/src/main/java/org/apache/twill/filesystem/LocalLocation.java
@@ -25,6 +25,9 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.net.URI;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Deque;
@@ -176,9 +179,11 @@ final class LocalLocation implements Location {
   @Override
   public Location renameTo(Location destination) throws IOException {
     // destination will always be of the same type as this location
-    boolean success = file.renameTo(((LocalLocation) destination).file);
-    if (success) {
-      return new LocalLocation(locationFactory, ((LocalLocation) destination).file);
+    Path target = Files.move(file.toPath(), ((LocalLocation) destination).file.toPath(),
+                             StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING);
+
+    if (target != null) {
+      return new LocalLocation(locationFactory, target.toFile());
     } else {
       return null;
     }