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.
pull/27962/head
Will Rouesnel 7 years ago committed by Brian Coca
parent 01dda25e0f
commit 1685338603

@ -526,8 +526,9 @@ 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:
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())
@ -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)

Loading…
Cancel
Save