Also don't try to copy a logfile if it doesn't exist.

In some cases no log file will be written, so don't attempt to
call os.rename() with a non-existent source path.

llvm-svn: 238248
This commit is contained in:
Zachary Turner 2015-05-26 20:26:29 +00:00
parent 3c36b324dc
commit 306278ff0d
1 changed files with 9 additions and 8 deletions

View File

@ -1566,15 +1566,16 @@ class Base(unittest2.TestCase):
# keep all log files, rename them to include prefix
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)
if os.path.isfile(src):
dst = src.replace(self.log_basename, dst_log_basename)
if os.name == "nt" and os.path.isfile(dst):
# 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:
# success! (and we don't want log files) delete log files
for log_file in log_files_for_this_test: