[llvm] r186483 - Don't fallback to copy + delete in rename.
Rafael Espindola
rafael.espindola at gmail.com
Tue Jul 16 20:33:41 PDT 2013
Author: rafael
Date: Tue Jul 16 22:33:41 2013
New Revision: 186483
URL: http://llvm.org/viewvc/llvm-project?rev=186483&view=rev
Log:
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.
Modified:
llvm/trunk/lib/Support/Unix/Path.inc
Modified: llvm/trunk/lib/Support/Unix/Path.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/Path.inc?rev=186483&r1=186482&r2=186483&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Unix/Path.inc (original)
+++ llvm/trunk/lib/Support/Unix/Path.inc Tue Jul 16 22:33:41 2013
@@ -456,17 +456,8 @@ error_code rename(const Twine &from, con
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();
}
More information about the llvm-commits
mailing list