From 1685338603bc68b6af062aba223632bb72293edc Mon Sep 17 00:00:00 2001 From: Will Rouesnel Date: Tue, 8 Aug 2017 09:59:16 +1000 Subject: [PATCH] get_url: Use atomic_move with get_url rather then shutil.copyfile This brings get_url inline with the other internal file handling modules, and allows replacement of in-use files. --- lib/ansible/modules/net_tools/basics/get_url.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/ansible/modules/net_tools/basics/get_url.py b/lib/ansible/modules/net_tools/basics/get_url.py index 88c765f4f8f..aa15d768e9b 100644 --- a/lib/ansible/modules/net_tools/basics/get_url.py +++ b/lib/ansible/modules/net_tools/basics/get_url.py @@ -526,9 +526,10 @@ def main(): if backup: if os.path.exists(dest): backup_file = module.backup_local(dest) - shutil.copyfile(tmpsrc, dest) + module.atomic_move(tmpsrc, dest) except Exception as e: - os.remove(tmpsrc) + if os.path.exists(tmpsrc): + os.remove(tmpsrc) module.fail_json(msg="failed to copy %s to %s: %s" % (tmpsrc, dest, to_native(e)), exception=traceback.format_exc()) changed = True @@ -542,8 +543,6 @@ def main(): os.remove(dest) module.fail_json(msg="The checksum for %s did not match %s; it was %s." % (dest, checksum, destination_checksum)) - os.remove(tmpsrc) - # allow file attribute changes module.params['path'] = dest file_args = module.load_file_common_arguments(module.params)