1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Refining the fix made in #5885.

It turns out that some of the assumptions in #5885 were slightly off. The previous fix relied on a call to the module to creat a tmp_path. This is insufficent as there are few cases that we need to have the tmp directory before we make the module call. If we don't have a tmp_path before we do a recursive call or when we find a file that does not match the remote md5 hash we need to create a tmp directory. Also we are not more percise when we will need to clean up the remote tmp_path.
This commit is contained in:
Richard C Isaacson 2014-02-08 02:25:42 -06:00
parent 1609dfbca4
commit 786e3d2fd2

View file

@ -129,8 +129,17 @@ class ActionModule(object):
diffs = [] diffs = []
module_result = {"changed": False} module_result = {"changed": False}
# Don't remove the directory if there are more than 1 source file. # A register for if we executed a module.
delete_remote_tmp = not (len(source_files) < 1) # Used to cut down on command calls when not recursive.
module_executed = False
# Tell _execute_module to delete the file if there is one file.
delete_remote_tmp = (len(source_files) == 1)
# If this is a recursive action create a tmp_path that we can share as the _exec_module create is too late.
if not delete_remote_tmp:
if "-tmp-" not in tmp_path:
tmp_path = self.runner._make_tmp_path(conn)
for source_full, source_rel in source_files: for source_full, source_rel in source_files:
# Generate the MD5 hash of the local file. # Generate the MD5 hash of the local file.
@ -172,6 +181,12 @@ class ActionModule(object):
# The MD5 hashes don't match and we will change or error out. # The MD5 hashes don't match and we will change or error out.
changed = True changed = True
# Create a tmp_path if missing only if this is not recursive.
# If this is recursive we already have a tmp_path.
if delete_remote_tmp:
if "-tmp-" not in tmp_path:
tmp_path = self.runner._make_tmp_path(conn)
if self.runner.diff and not raw: if self.runner.diff and not raw:
diff = self._get_diff_data(conn, tmp_path, inject, dest_file, source_full) diff = self._get_diff_data(conn, tmp_path, inject, dest_file, source_full)
else: else:
@ -210,6 +225,7 @@ class ActionModule(object):
module_args_tmp = "%s src=%s dest=%s original_basename=%s" % (module_args, module_args_tmp = "%s src=%s dest=%s original_basename=%s" % (module_args,
pipes.quote(tmp_src), pipes.quote(dest), pipes.quote(source_rel)) pipes.quote(tmp_src), pipes.quote(dest), pipes.quote(source_rel))
module_return = self.runner._execute_module(conn, tmp_path, 'copy', module_args_tmp, inject=inject, complex_args=complex_args, delete_remote_tmp=delete_remote_tmp) module_return = self.runner._execute_module(conn, tmp_path, 'copy', module_args_tmp, inject=inject, complex_args=complex_args, delete_remote_tmp=delete_remote_tmp)
module_executed = True
else: else:
# no need to transfer the file, already correct md5, but still need to call # no need to transfer the file, already correct md5, but still need to call
@ -233,9 +249,7 @@ class ActionModule(object):
# Execute the file module. # Execute the file module.
module_return = self.runner._execute_module(conn, tmp_path, 'file', module_args_tmp, inject=inject, complex_args=complex_args, delete_remote_tmp=delete_remote_tmp) module_return = self.runner._execute_module(conn, tmp_path, 'file', module_args_tmp, inject=inject, complex_args=complex_args, delete_remote_tmp=delete_remote_tmp)
module_executed = True
if not C.DEFAULT_KEEP_REMOTE_FILES and not delete_remote_tmp:
self.runner._remove_tmp_path(conn, tmp_path)
module_result = module_return.result module_result = module_return.result
if module_result.get('failed') == True: if module_result.get('failed') == True:
@ -243,6 +257,11 @@ class ActionModule(object):
if module_result.get('changed') == True: if module_result.get('changed') == True:
changed = True changed = True
# Delete tmp_path if we were recursive or if we did not execute a module.
if (not C.DEFAULT_KEEP_REMOTE_FILES and not delete_remote_tmp) \
or (not C.DEFAULT_KEEP_REMOTE_FILES and delete_remote_tmp and not module_executed):
self.runner._remove_tmp_path(conn, tmp_path)
# TODO: Support detailed status/diff for multiple files # TODO: Support detailed status/diff for multiple files
if len(source_files) == 1: if len(source_files) == 1:
result = module_result result = module_result