forked from OSchip/llvm-project
On Windows, delete existing log file before renaming temp file.
On non-Windows platforms, os.rename() will silently replace the destination file if it already exists. On Windows, it doesn't do this, and the filesystem has no mechanism to simulate the same type of atomic rename operation. So on Windows, delete the file first before calling os.rename(). llvm-svn: 238239
This commit is contained in:
parent
674cf26892
commit
5de068bf31
|
@ -1567,6 +1567,13 @@ class Base(unittest2.TestCase):
|
||||||
dst_log_basename = self.getLogBasenameForCurrentTest(prefix)
|
dst_log_basename = self.getLogBasenameForCurrentTest(prefix)
|
||||||
for src in log_files_for_this_test:
|
for src in log_files_for_this_test:
|
||||||
dst = src.replace(self.log_basename, dst_log_basename)
|
dst = src.replace(self.log_basename, dst_log_basename)
|
||||||
|
if os.name == "nt":
|
||||||
|
# On Windows, renaming a -> b will throw an exception if b exists. On non-Windows platforms
|
||||||
|
# it silently replaces the destination. Ultimately this means that atomic renames are not
|
||||||
|
# guaranteed to be possible on Windows, but we need this to work anyway, so just remove the
|
||||||
|
# destination first if it already exists.
|
||||||
|
os.remove(dst)
|
||||||
|
|
||||||
os.rename(src, dst)
|
os.rename(src, dst)
|
||||||
else:
|
else:
|
||||||
# success! (and we don't want log files) delete log files
|
# success! (and we don't want log files) delete log files
|
||||||
|
|
Loading…
Reference in New Issue