New tests for copy recursive with absolute paths

Absolute path trailing slash handling in absolute directories

find_needle() isn't passing a trailing slash through verbatim.  Since
copy uses that to determine if it should copy a directory or just the
files inside of it, we have to detect that and restore it after calling
find_needle()

Fixes #27439
This commit is contained in:
Toshio Kuratomi 2017-07-28 19:36:23 -07:00
parent 7cfd02097c
commit 0a2cdb2585
2 changed files with 94 additions and 2 deletions

View file

@ -442,8 +442,14 @@ class ActionModule(ActionBase):
elif remote_src:
result.update(self._execute_module(task_vars=task_vars))
return result
else: # find in expected paths
else:
# find_needle returns a path that may not have a trailing slash on
# a directory so we need to determine that now (we use it just
# like rsync does to figure out whether to include the directory
# or only the files inside the directory
trailing_slash = source.endswith(os.path.sep)
try:
# find in expected paths
source = self._find_needle('files', source)
except AnsibleError as e:
result['failed'] = True
@ -451,6 +457,12 @@ class ActionModule(ActionBase):
result['exception'] = traceback.format_exc()
return result
if trailing_slash != source.endswith(os.path.sep):
if source[-1] == os.path.sep:
source = source[:-1]
else:
source = source + os.path.sep
# A list of source file tuples (full_path, relative_path) which will try to copy to the destination
source_files = {'files': [], 'directories': [], 'symlinks': []}