mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
made copy atomic by creating tmp file in dest location (ensures same partition)
uses pid and epoch to prevent collisions, good enough for most cases Signed-off-by: Brian Coca <briancoca+ansible@gmail.com>
This commit is contained in:
parent
e7eab93243
commit
f5481621f8
1 changed files with 6 additions and 1 deletions
|
@ -20,6 +20,7 @@
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
import time
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
||||||
|
@ -64,7 +65,11 @@ 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(src, dest)
|
#TODO:pid + epoch should avoid most collisions, hostname/mac for those using nfs?
|
||||||
|
# might be an issue with exceeding path length
|
||||||
|
dest_tmp = "%s.%s.%s.tmp" % (dest,os.getpid(),time.gmtime)
|
||||||
|
shutil.copyfile(src, dest_tmp)
|
||||||
|
shutil.copyfile(dest_tmp, dest)
|
||||||
except shutil.Error:
|
except shutil.Error:
|
||||||
module.fail_json(msg="failed to copy: %s and %s are the same" % (src, dest))
|
module.fail_json(msg="failed to copy: %s and %s are the same" % (src, dest))
|
||||||
except IOError:
|
except IOError:
|
||||||
|
|
Loading…
Reference in a new issue