Commit 81b7354c authored by Iustin Pop's avatar Iustin Pop
Browse files

Small optimisation in utils.WriteFile

Currently we always try to remove the new file, even if the rename
succeeded. This patch tracks the existence of the new file and doesn't
try to remove it if we managed to rename it.
Signed-off-by: default avatarIustin Pop <>
Reviewed-by: default avatarGuido Trotter <>
parent dd36d829
......@@ -1284,6 +1284,7 @@ def WriteFile(file_name, fn=None, data=None,
dir_name, base_name = os.path.split(file_name)
fd, new_name = tempfile.mkstemp('.new', base_name, dir_name)
do_remove = True
# here we need to make sure we remove the temp file, if any error
# leaves it in place
......@@ -1304,12 +1305,14 @@ def WriteFile(file_name, fn=None, data=None,
os.utime(new_name, (atime, mtime))
if not dry_run:
os.rename(new_name, file_name)
do_remove = False
if close:
result = None
result = fd
if do_remove:
return result
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment