aboutsummaryrefslogtreecommitdiff
path: root/lib/Support/Unix/PathV2.inc
diff options
context:
space:
mode:
authorMichael J. Spencer <bigcheesegs@gmail.com>2011-01-16 22:18:41 +0000
committerMichael J. Spencer <bigcheesegs@gmail.com>2011-01-16 22:18:41 +0000
commit283d49c7663dd1c2a73dbb18d6094d91f9555c72 (patch)
tree3ba74a48908592399837e0fd0407c0048ae1ef36 /lib/Support/Unix/PathV2.inc
parent33d84007b55b526c355e0c9e25abc450f2732bc7 (diff)
Fix rename.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123604 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support/Unix/PathV2.inc')
-rw-r--r--lib/Support/Unix/PathV2.inc13
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/Support/Unix/PathV2.inc b/lib/Support/Unix/PathV2.inc
index 056708a7b0..03ff28367e 100644
--- a/lib/Support/Unix/PathV2.inc
+++ b/lib/Support/Unix/PathV2.inc
@@ -230,8 +230,17 @@ error_code rename(const Twine &from, const Twine &to) {
StringRef f = from.toNullTerminatedStringRef(from_storage);
StringRef t = to.toNullTerminatedStringRef(to_storage);
- if (::rename(f.begin(), t.begin()) == -1)
- return error_code(errno, system_category());
+ if (::rename(f.begin(), t.begin()) == -1) {
+ // If it's a cross device link, copy then delete, otherwise return the error
+ if (errno == EXDEV) {
+ if (error_code ec = copy_file(from, to, copy_option::overwrite_if_exists))
+ return ec;
+ bool Existed;
+ if (error_code ec = remove(from, Existed))
+ return ec;
+ } else
+ return error_code(errno, system_category());
+ }
return success;
}