From 753a3a03d0b1ce13562aa9d9283c3095c7293d3d Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Mon, 1 May 2017 09:06:38 -0700 Subject: [PATCH] Revert "Fix for recursive copy slowness" This reverts commit 78ced5318f25593bf0163fb85a5f8f81cdacfcb0. The fix for copy slowness did not handle circular symlinks. --- lib/ansible/plugins/action/copy.py | 22 +++++++++- test/integration/targets/copy/tasks/main.yml | 45 -------------------- 2 files changed, 21 insertions(+), 46 deletions(-) diff --git a/lib/ansible/plugins/action/copy.py b/lib/ansible/plugins/action/copy.py index 3708e0c9d42..7d45196acb7 100644 --- a/lib/ansible/plugins/action/copy.py +++ b/lib/ansible/plugins/action/copy.py @@ -110,7 +110,7 @@ class ActionModule(ActionBase): sz = len(source.rsplit('/', 1)[0]) + 1 # Walk the directory and append the file tuples to source_files. - for base_path, sub_folders, files in os.walk(to_bytes(source), followlinks=True): + for base_path, sub_folders, files in os.walk(to_bytes(source)): for file in files: full_path = to_text(os.path.join(base_path, file), errors='surrogate_or_strict') rel_path = full_path[sz:] @@ -118,6 +118,10 @@ class ActionModule(ActionBase): rel_path = rel_path[1:] source_files.append((full_path, rel_path)) + # recurse into subdirs + for sf in sub_folders: + source_files += self._get_recursive_files(os.path.join(source, to_text(sf)), sz=sz) + # If it's recursive copy, destination is always a dir, # explicitly mark it so (note - copy module relies on this). if not self._connection._shell.path_has_trailing_slash(dest): @@ -327,6 +331,22 @@ class ActionModule(ActionBase): return result + def _get_recursive_files(self, topdir, sz=0): + ''' Recursively create file tuples for sub folders ''' + r_files = [] + for base_path, sub_folders, files in os.walk(to_bytes(topdir)): + for fname in files: + full_path = to_text(os.path.join(base_path, fname), errors='surrogate_or_strict') + rel_path = full_path[sz:] + if rel_path.startswith('/'): + rel_path = rel_path[1:] + r_files.append((full_path, rel_path)) + + for sf in sub_folders: + r_files += self._get_recursive_files(os.path.join(topdir, to_text(sf)), sz=sz) + + return r_files + def _create_content_tempfile(self, content): ''' Create a tempfile containing defined content ''' fd, content_tempfile = tempfile.mkstemp() diff --git a/test/integration/targets/copy/tasks/main.yml b/test/integration/targets/copy/tasks/main.yml index 096ae5481ca..af95facfbe4 100644 --- a/test/integration/targets/copy/tasks/main.yml +++ b/test/integration/targets/copy/tasks/main.yml @@ -258,48 +258,3 @@ assert: that: - replace_follow_result.checksum == target_file_result.stdout - -- name: create a test dir to copy - file: - path: '{{ output_dir }}/top_dir' - state: directory - -- name: create a test dir to symlink to - file: - path: '{{ output_dir }}/linked_dir' - state: directory - -- name: create a file in the test dir - copy: - dest: '{{ output_dir }}/linked_dir/file1' - content: 'hello world' - -- name: create a link to the test dir - file: - path: '{{ output_dir }}/top_dir/follow_link_dir' - src: '{{ output_dir }}/linked_dir' - state: link - -- name: copy the directory's link - copy: - src: '{{ output_dir }}/top_dir' - dest: '{{ output_dir }}/new_dir' - follow: True - -- name: stat the copied path - stat: - path: '{{ output_dir }}/new_dir/top_dir/follow_link_dir' - register: stat_dir_result - -- name: stat the copied path - stat: - path: '{{ output_dir }}/new_dir/top_dir/follow_link_dir/file1' - register: stat_file_in_dir_result - -- name: assert that the directory exists - assert: - that: - - stat_dir_result.stat.exists - - stat_dir_result.stat.isdir - - stat_file_in_dir_result.stat.exists - - stat_file_in_dir_result.stat.isreg