mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
copy action plugin: recurse into sub folders of the source (#17614)
* copy action plugin: recurse into sub folders of the source Fixes #13013 * Fix python3 bytes/strings * Fix py3 again * test
This commit is contained in:
parent
4e60f23198
commit
29fda4be1e
1 changed files with 20 additions and 0 deletions
|
@ -119,6 +119,10 @@ class ActionModule(ActionBase):
|
||||||
rel_path = rel_path[1:]
|
rel_path = rel_path[1:]
|
||||||
source_files.append((full_path, rel_path))
|
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,
|
# If it's recursive copy, destination is always a dir,
|
||||||
# explicitly mark it so (note - copy module relies on this).
|
# explicitly mark it so (note - copy module relies on this).
|
||||||
if not self._connection._shell.path_has_trailing_slash(dest):
|
if not self._connection._shell.path_has_trailing_slash(dest):
|
||||||
|
@ -308,6 +312,22 @@ class ActionModule(ActionBase):
|
||||||
|
|
||||||
return result
|
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):
|
def _create_content_tempfile(self, content):
|
||||||
''' Create a tempfile containing defined content '''
|
''' Create a tempfile containing defined content '''
|
||||||
fd, content_tempfile = tempfile.mkstemp()
|
fd, content_tempfile = tempfile.mkstemp()
|
||||||
|
|
Loading…
Reference in a new issue