Pass absolute paths to atmoic_move(). (#799)
parent
5a2dff7b74
commit
db871c2686
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- "various modules - pass absolute paths to ``module.atomic_move()`` (https://github.com/ansible/ansible/issues/83950, https://github.com/ansible-collections/community.crypto/pull/799)."
|
|
@ -92,7 +92,7 @@ def write_file(module, content, default_mode=None, path=None):
|
||||||
if os.path.exists(file_args['path']):
|
if os.path.exists(file_args['path']):
|
||||||
module.set_fs_attributes_if_different(file_args, False)
|
module.set_fs_attributes_if_different(file_args, False)
|
||||||
# Move tempfile to final destination
|
# Move tempfile to final destination
|
||||||
module.atomic_move(tmp_name, file_args['path'])
|
module.atomic_move(os.path.abspath(tmp_name), os.path.abspath(file_args['path']))
|
||||||
# Try to update permissions again
|
# Try to update permissions again
|
||||||
if not module.check_file_absent_if_check_mode(file_args['path']):
|
if not module.check_file_absent_if_check_mode(file_args['path']):
|
||||||
module.set_fs_attributes_if_different(file_args, False)
|
module.set_fs_attributes_if_different(file_args, False)
|
||||||
|
|
|
@ -28,7 +28,7 @@ def restore_on_failure(f):
|
||||||
f(module, path, *args, **kwargs)
|
f(module, path, *args, **kwargs)
|
||||||
except Exception:
|
except Exception:
|
||||||
if backup_file is not None:
|
if backup_file is not None:
|
||||||
module.atomic_move(backup_file, path)
|
module.atomic_move(os.path.abspath(backup_file), os.path.abspath(path))
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
module.add_cleanup_file(backup_file)
|
module.add_cleanup_file(backup_file)
|
||||||
|
@ -38,7 +38,7 @@ def restore_on_failure(f):
|
||||||
|
|
||||||
@restore_on_failure
|
@restore_on_failure
|
||||||
def safe_atomic_move(module, path, destination):
|
def safe_atomic_move(module, path, destination):
|
||||||
module.atomic_move(path, destination)
|
module.atomic_move(os.path.abspath(path), os.path.abspath(destination))
|
||||||
|
|
||||||
|
|
||||||
def _restore_all_on_failure(f):
|
def _restore_all_on_failure(f):
|
||||||
|
@ -49,7 +49,7 @@ def _restore_all_on_failure(f):
|
||||||
f(self, sources_and_destinations, *args, **kwargs)
|
f(self, sources_and_destinations, *args, **kwargs)
|
||||||
except Exception:
|
except Exception:
|
||||||
for destination, backup in backups:
|
for destination, backup in backups:
|
||||||
self.module.atomic_move(backup, destination)
|
self.module.atomic_move(os.path.abspath(backup), os.path.abspath(destination))
|
||||||
raise
|
raise
|
||||||
else:
|
else:
|
||||||
for destination, backup in backups:
|
for destination, backup in backups:
|
||||||
|
@ -138,7 +138,7 @@ class OpensshModule(object):
|
||||||
"""
|
"""
|
||||||
for source, destination in sources_and_destinations:
|
for source, destination in sources_and_destinations:
|
||||||
if os.path.exists(destination):
|
if os.path.exists(destination):
|
||||||
self.module.atomic_move(source, destination)
|
self.module.atomic_move(os.path.abspath(source), os.path.abspath(destination))
|
||||||
else:
|
else:
|
||||||
self.module.preserved_copy(source, destination)
|
self.module.preserved_copy(source, destination)
|
||||||
|
|
||||||
|
|
|
@ -284,7 +284,7 @@ class DHParameterOpenSSL(DHParameterBase):
|
||||||
if self.backup:
|
if self.backup:
|
||||||
self.backup_file = module.backup_local(self.path)
|
self.backup_file = module.backup_local(self.path)
|
||||||
try:
|
try:
|
||||||
module.atomic_move(tmpsrc, self.path)
|
module.atomic_move(os.path.abspath(tmpsrc), os.path.abspath(self.path))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
module.fail_json(msg="Failed to write to file %s: %s" % (self.path, str(e)))
|
module.fail_json(msg="Failed to write to file %s: %s" % (self.path, str(e)))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue