unsafe writes! (#4314)

* unsafe writes!

* moved unsafe_write docs and args to file common

* added unsafe_writes option handling
reviewable/pr18780/r1
Brian Coca 8 years ago committed by GitHub
parent 3480561254
commit 9dde201d87

@ -235,7 +235,7 @@ def main():
if backup and dest_hash is not None: if backup and dest_hash is not None:
result['backup_file'] = module.backup_local(dest) result['backup_file'] = module.backup_local(dest)
module.atomic_move(path, dest) module.atomic_move(path, dest, unsafe_writes=module.params['unsafe_writes'])
changed = True changed = True
cleanup(path, result) cleanup(path, result)

@ -321,12 +321,11 @@ def main():
(rc,out,err) = module.run_command(validate % src) (rc,out,err) = module.run_command(validate % src)
if rc != 0: if rc != 0:
module.fail_json(msg="failed to validate", exit_status=rc, stdout=out, stderr=err) module.fail_json(msg="failed to validate", exit_status=rc, stdout=out, stderr=err)
mysrc = src
if remote_src: if remote_src:
_, tmpdest = tempfile.mkstemp(dir=os.path.dirname(dest)) _, mysrc = tempfile.mkstemp(dir=os.path.dirname(dest))
shutil.copy2(src, tmpdest) shutil.copy2(src, mysrc)
module.atomic_move(tmpdest, dest) module.atomic_move(mysrc, dest, unsafe_writes=module.params['unsafe_writes'])
else:
module.atomic_move(src, dest)
except IOError: except IOError:
module.fail_json(msg="failed to copy: %s to %s" % (src, dest), traceback=traceback.format_exc()) module.fail_json(msg="failed to copy: %s to %s" % (src, dest), traceback=traceback.format_exc())
changed = True changed = True

@ -165,7 +165,7 @@ def write_changes(module,lines,dest):
module.fail_json(msg='failed to validate: ' module.fail_json(msg='failed to validate: '
'rc:%s error:%s' % (rc,err)) 'rc:%s error:%s' % (rc,err))
if valid: if valid:
module.atomic_move(tmpfile, os.path.realpath(dest)) module.atomic_move(tmpfile, os.path.realpath(dest), unsafe_writes=module.params['unsafe_writes'])
def check_file_attrs(module, changed, message, diff): def check_file_attrs(module, changed, message, diff):

@ -102,7 +102,7 @@ def write_changes(module,contents,dest):
module.fail_json(msg='failed to validate: ' module.fail_json(msg='failed to validate: '
'rc:%s error:%s' % (rc,err)) 'rc:%s error:%s' % (rc,err))
if valid: if valid:
module.atomic_move(tmpfile, dest) module.atomic_move(tmpfile, dest, unsafe_writes=module.params['unsafe_writes'])
def check_file_attrs(module, changed, message): def check_file_attrs(module, changed, message):

Loading…
Cancel
Save