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.
This commit is contained in:
Will Rouesnel 2017-08-08 09:59:16 +10:00 committed by Brian Coca
parent 01dda25e0f
commit 1685338603

View file

@ -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)