From 88b1d1e0c1b4f125ef5fe1d3b12b1e6bd5d50ea0 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Wed, 2 Oct 2024 09:50:35 +0300 Subject: [PATCH] [PR #8925/7c913b23 backport][stable-7] Pass absolute paths to atomic_move() (#8957) Pass absolute paths to atomic_move() (#8925) Pass absolute paths to atmoic_move(). (cherry picked from commit 7c913b239a6ec26bb92cfbb185499f5fb9a2c841) Co-authored-by: Felix Fontein --- changelogs/fragments/8925-atomic.yml | 6 ++++++ plugins/modules/ini_file.py | 2 +- plugins/modules/java_keystore.py | 2 +- plugins/modules/jenkins_plugin.py | 4 ++-- plugins/modules/kdeconfig.py | 2 +- plugins/modules/pam_limits.py | 2 +- 6 files changed, 12 insertions(+), 6 deletions(-) create mode 100644 changelogs/fragments/8925-atomic.yml diff --git a/changelogs/fragments/8925-atomic.yml b/changelogs/fragments/8925-atomic.yml new file mode 100644 index 0000000000..75e48a1dba --- /dev/null +++ b/changelogs/fragments/8925-atomic.yml @@ -0,0 +1,6 @@ +bugfixes: + - "ini_file - pass absolute paths to ``module.atomic_move()`` (https://github.com/ansible/ansible/issues/83950, https://github.com/ansible-collections/community.general/pull/8925)." + - "java_keystore - pass absolute paths to ``module.atomic_move()`` (https://github.com/ansible/ansible/issues/83950, https://github.com/ansible-collections/community.general/pull/8925)." + - "jenkins_plugin - pass absolute paths to ``module.atomic_move()`` (https://github.com/ansible/ansible/issues/83950, https://github.com/ansible-collections/community.general/pull/8925)." + - "kdeconfig - pass absolute paths to ``module.atomic_move()`` (https://github.com/ansible/ansible/issues/83950, https://github.com/ansible-collections/community.general/pull/8925)." + - "pam_limits - pass absolute paths to ``module.atomic_move()`` (https://github.com/ansible/ansible/issues/83950, https://github.com/ansible-collections/community.general/pull/8925)." diff --git a/plugins/modules/ini_file.py b/plugins/modules/ini_file.py index a8c3caa4b3..3a26fbd15f 100644 --- a/plugins/modules/ini_file.py +++ b/plugins/modules/ini_file.py @@ -450,7 +450,7 @@ def do_ini(module, filename, section=None, option=None, values=None, module.fail_json(msg="Unable to create temporary file %s", traceback=traceback.format_exc()) try: - module.atomic_move(tmpfile, target_filename) + module.atomic_move(tmpfile, os.path.abspath(target_filename)) except IOError: module.ansible.fail_json(msg='Unable to move temporary \ file %s to %s, IOError' % (tmpfile, target_filename), traceback=traceback.format_exc()) diff --git a/plugins/modules/java_keystore.py b/plugins/modules/java_keystore.py index 7da52cc057..0a8e3398d5 100644 --- a/plugins/modules/java_keystore.py +++ b/plugins/modules/java_keystore.py @@ -470,7 +470,7 @@ class JavaKeystore: if self.keystore_type == 'pkcs12': # Preserve properties of the destination file, if any. - self.module.atomic_move(keystore_p12_path, self.keystore_path) + self.module.atomic_move(os.path.abspath(keystore_p12_path), os.path.abspath(self.keystore_path)) self.update_permissions() self.result['changed'] = True return self.result diff --git a/plugins/modules/jenkins_plugin.py b/plugins/modules/jenkins_plugin.py index 13a804a508..8834e0a2b2 100644 --- a/plugins/modules/jenkins_plugin.py +++ b/plugins/modules/jenkins_plugin.py @@ -685,7 +685,7 @@ class JenkinsPlugin(object): # Move the updates file to the right place if we could read it if tmp_updates_file != updates_file: - self.module.atomic_move(tmp_updates_file, updates_file) + self.module.atomic_move(os.path.abspath(tmp_updates_file), os.path.abspath(updates_file)) # Check if we have the plugin data available if not data.get('plugins', {}).get(self.params['name']): @@ -718,7 +718,7 @@ class JenkinsPlugin(object): details=to_native(e)) # Move the file onto the right place - self.module.atomic_move(tmp_f, f) + self.module.atomic_move(os.path.abspath(tmp_f), os.path.abspath(f)) def uninstall(self): changed = False diff --git a/plugins/modules/kdeconfig.py b/plugins/modules/kdeconfig.py index 4e8d395215..96d7df8b8d 100644 --- a/plugins/modules/kdeconfig.py +++ b/plugins/modules/kdeconfig.py @@ -214,7 +214,7 @@ def run_module(module, tmpdir, kwriteconfig): if module.params['backup'] and os.path.exists(b_path): result['backup_file'] = module.backup_local(result['path']) try: - module.atomic_move(b_tmpfile, b_path) + module.atomic_move(b_tmpfile, os.path.abspath(b_path)) except IOError: module.ansible.fail_json(msg='Unable to move temporary file %s to %s, IOError' % (tmpfile, result['path']), traceback=traceback.format_exc()) diff --git a/plugins/modules/pam_limits.py b/plugins/modules/pam_limits.py index f97ea6602b..4ed037a6ff 100644 --- a/plugins/modules/pam_limits.py +++ b/plugins/modules/pam_limits.py @@ -339,7 +339,7 @@ def main(): pass # Move tempfile to newfile - module.atomic_move(nf.name, limits_conf) + module.atomic_move(os.path.abspath(nf.name), os.path.abspath(limits_conf)) try: nf.close()