[Lldb-commits] [lldb] r238239 - On Windows, delete existing log file before renaming temp file.

Zachary Turner zturner at google.com
Tue May 26 12:52:24 PDT 2015


Author: zturner
Date: Tue May 26 14:52:24 2015
New Revision: 238239

URL: http://llvm.org/viewvc/llvm-project?rev=238239&view=rev
Log:
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().

Modified:
    lldb/trunk/test/lldbtest.py

Modified: lldb/trunk/test/lldbtest.py
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/test/lldbtest.py?rev=238239&r1=238238&r2=238239&view=diff
==============================================================================
--- lldb/trunk/test/lldbtest.py (original)
+++ lldb/trunk/test/lldbtest.py Tue May 26 14:52:24 2015
@@ -1567,6 +1567,13 @@ class Base(unittest2.TestCase):
             dst_log_basename = self.getLogBasenameForCurrentTest(prefix)
             for src in log_files_for_this_test:
                 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)
         else:
             # success!  (and we don't want log files) delete log files





More information about the lldb-commits mailing list