diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2013-07-17 03:33:41 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2013-07-17 03:33:41 +0000 |
commit | b6fea4c618241650ae4539128087b3d29ea30d6b (patch) | |
tree | 20b099d076cdd366169da8b7e74ebaaf01e8f2f4 /llvm/lib/Support/Unix | |
parent | 9fdc70e846efed70cd25cacc0e08d2b2531647ee (diff) | |
download | bcm5719-llvm-b6fea4c618241650ae4539128087b3d29ea30d6b.tar.gz bcm5719-llvm-b6fea4c618241650ae4539128087b3d29ea30d6b.zip |
Don't fallback to copy + delete in rename.
Rename's documentation says "Files are renamed as if by POSIX rename()". and it
is used for atomically updating output files from a temporary. Having rename
fallback to a non atomic copy has the potential to hide bugs, like using
a temporary file in /tmp instead of a unique name next to the final destination.
llvm-svn: 186483
Diffstat (limited to 'llvm/lib/Support/Unix')
-rw-r--r-- | llvm/lib/Support/Unix/Path.inc | 13 |
1 files changed, 2 insertions, 11 deletions
diff --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc index 9795b6e34b1..0c1623acdc7 100644 --- a/llvm/lib/Support/Unix/Path.inc +++ b/llvm/lib/Support/Unix/Path.inc @@ -456,17 +456,8 @@ 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) { - // 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()); - } + if (::rename(f.begin(), t.begin()) == -1) + return error_code(errno, system_category()); return error_code::success(); } |