Add a directory walker to copy

* We need a directory walker that can handle symlinks, empty directories,
  and some other odd needs.  This commit contains a directory walker that
  can do all that.  The walker returns information about the files in the
  directories that we can then use to implement different strategies for
  copying the files to the remote machines.
* Add local_follow parameter to copy that follows local symlinks (follow
  is for remote symlinks)
* Refactor the copying of files out of run into its own method
* Add new integration tests for copy

Fixes #24949
Fixes #21513
This commit is contained in:
Toshio Kuratomi 2017-05-08 22:19:54 -07:00
parent 753a3a03d0
commit f86ce0975d
12 changed files with 1054 additions and 271 deletions

View file

@ -29,7 +29,7 @@ from yaml import YAMLError
from ansible.errors import AnsibleFileNotFound, AnsibleParserError
from ansible.errors.yaml_strings import YAML_SYNTAX_ERROR
from ansible.module_utils.basic import is_executable
from ansible.module_utils.six import text_type, string_types
from ansible.module_utils.six import binary_type, text_type
from ansible.module_utils._text import to_bytes, to_native, to_text
from ansible.parsing.vault import VaultLib, b_HEADER, is_encrypted, is_encrypted_file
from ansible.parsing.quoting import unquote
@ -184,7 +184,7 @@ class DataLoader:
Reads the file contents from the given file name, and will decrypt them
if they are found to be vault-encrypted.
'''
if not file_name or not isinstance(file_name, string_types):
if not file_name or not isinstance(file_name, (binary_type, text_type)):
raise AnsibleParserError("Invalid filename: '%s'" % str(file_name))
b_file_name = to_bytes(file_name)
@ -380,7 +380,7 @@ class DataLoader:
break
if result is None:
raise AnsibleFileNotFound(file_name=source, paths=search)
raise AnsibleFileNotFound(file_name=source, paths=[to_text(p) for p in search])
return result
@ -405,7 +405,7 @@ class DataLoader:
Temporary files are cleanup in the destructor
"""
if not file_path or not isinstance(file_path, string_types):
if not file_path or not isinstance(file_path, (binary_type, text_type)):
raise AnsibleParserError("Invalid filename: '%s'" % to_native(file_path))
b_file_path = to_bytes(file_path, errors='surrogate_or_strict')