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:
parent
01dda25e0f
commit
1685338603
1 changed files with 3 additions and 4 deletions
|
@ -526,9 +526,10 @@ def main():
|
||||||
if backup:
|
if backup:
|
||||||
if os.path.exists(dest):
|
if os.path.exists(dest):
|
||||||
backup_file = module.backup_local(dest)
|
backup_file = module.backup_local(dest)
|
||||||
shutil.copyfile(tmpsrc, dest)
|
module.atomic_move(tmpsrc, dest)
|
||||||
except Exception as e:
|
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)),
|
module.fail_json(msg="failed to copy %s to %s: %s" % (tmpsrc, dest, to_native(e)),
|
||||||
exception=traceback.format_exc())
|
exception=traceback.format_exc())
|
||||||
changed = True
|
changed = True
|
||||||
|
@ -542,8 +543,6 @@ def main():
|
||||||
os.remove(dest)
|
os.remove(dest)
|
||||||
module.fail_json(msg="The checksum for %s did not match %s; it was %s." % (dest, checksum, destination_checksum))
|
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
|
# allow file attribute changes
|
||||||
module.params['path'] = dest
|
module.params['path'] = dest
|
||||||
file_args = module.load_file_common_arguments(module.params)
|
file_args = module.load_file_common_arguments(module.params)
|
||||||
|
|
Loading…
Reference in a new issue