From 9dde201d87bb1c653659c02d240d2f397e9d4d66 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Tue, 9 Aug 2016 12:39:25 -0400 Subject: [PATCH] unsafe writes! (#4314) * unsafe writes! * moved unsafe_write docs and args to file common * added unsafe_writes option handling --- files/assemble.py | 2 +- files/copy.py | 9 ++++----- files/lineinfile.py | 2 +- files/replace.py | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/files/assemble.py b/files/assemble.py index 641c943026c..6eea02e547b 100644 --- a/files/assemble.py +++ b/files/assemble.py @@ -235,7 +235,7 @@ def main(): if backup and dest_hash is not None: 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 cleanup(path, result) diff --git a/files/copy.py b/files/copy.py index 74f7b28ed64..3b2c79be799 100644 --- a/files/copy.py +++ b/files/copy.py @@ -321,12 +321,11 @@ def main(): (rc,out,err) = module.run_command(validate % src) if rc != 0: module.fail_json(msg="failed to validate", exit_status=rc, stdout=out, stderr=err) + mysrc = src if remote_src: - _, tmpdest = tempfile.mkstemp(dir=os.path.dirname(dest)) - shutil.copy2(src, tmpdest) - module.atomic_move(tmpdest, dest) - else: - module.atomic_move(src, dest) + _, mysrc = tempfile.mkstemp(dir=os.path.dirname(dest)) + shutil.copy2(src, mysrc) + module.atomic_move(mysrc, dest, unsafe_writes=module.params['unsafe_writes']) except IOError: module.fail_json(msg="failed to copy: %s to %s" % (src, dest), traceback=traceback.format_exc()) changed = True diff --git a/files/lineinfile.py b/files/lineinfile.py index 8437345cb2e..5b7e6cd5d2b 100644 --- a/files/lineinfile.py +++ b/files/lineinfile.py @@ -165,7 +165,7 @@ def write_changes(module,lines,dest): module.fail_json(msg='failed to validate: ' 'rc:%s error:%s' % (rc,err)) 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): diff --git a/files/replace.py b/files/replace.py index a48e49f8dec..79cfa181d74 100644 --- a/files/replace.py +++ b/files/replace.py @@ -102,7 +102,7 @@ def write_changes(module,contents,dest): module.fail_json(msg='failed to validate: ' 'rc:%s error:%s' % (rc,err)) 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):