From b54e323741335e57814219d1c32db1c11211e666 Mon Sep 17 00:00:00 2001 From: Jeff Bradberry Date: Wed, 23 Jun 2021 14:42:24 -0400 Subject: [PATCH 1/2] Directories that are symlinks need to be treated as if they are a symlink file Note that we are now also writing the bare directory entries into the zipfile, where we weren't doing that before. This is fine. --- ansible_runner/utils/streaming.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ansible_runner/utils/streaming.py b/ansible_runner/utils/streaming.py index 8ae632a49..9f686e887 100644 --- a/ansible_runner/utils/streaming.py +++ b/ansible_runner/utils/streaming.py @@ -19,7 +19,7 @@ def stream_dir(source_directory, stream): relpath = os.path.relpath(dirpath, source_directory) if relpath == ".": relpath = "" - for fname in files: + for fname in files + dirs: full_path = os.path.join(dirpath, fname) # Magic to preserve symlinks if os.path.islink(full_path): From 085f6f4c0c805ab2ec5d65dccb81484bb85c22bf Mon Sep 17 00:00:00 2001 From: Alan Rominger Date: Wed, 23 Jun 2021 15:29:30 -0400 Subject: [PATCH 2/2] Expand the transmit symlink test --- test/unit/test_utils.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/test/unit/test_utils.py b/test/unit/test_utils.py index c2bcc83a9..75275d94a 100644 --- a/test/unit/test_utils.py +++ b/test/unit/test_utils.py @@ -227,16 +227,24 @@ def test_sanitize_container_name(container_name, expected_name): sanitize_container_name(str(container_name)) == expected_name -@pytest.mark.parametrize('symlink_dest', [ - '/proc/cpuinfo', - 'ordinary_file.txt', - 'filedoesnotexist.txt' -], ids=['global', 'local', 'bad']) -def test_transmit_symlink(tmpdir, symlink_dest): +@pytest.mark.parametrize('symlink_dest,check_content', [ + ('/proc/cpuinfo', []), + ('ordinary_file.txt', ['my_link']), + ('ordinary_directory', ['my_link/dir_file.txt']), + ('.', ['my_link/ordinary_directory/dir_file.txt', 'my_link/my_link/ordinary_file.txt']), + ('filedoesnotexist.txt', []) +], ids=['global', 'local', 'directory', 'recursive', 'bad']) +def test_transmit_symlink(tmpdir, symlink_dest, check_content): # prepare the input private_data_dir directory to zip pdd = tmpdir.mkdir('symlink_zip_test') + + # Create some basic shared demo content with open(os.path.join(pdd, 'ordinary_file.txt'), 'w') as f: f.write('hello world') + os.mkdir(os.path.join(pdd, 'ordinary_directory')) + with open(os.path.join(pdd, 'ordinary_directory', 'dir_file.txt'), 'w') as f: + f.write('hello world') + old_symlink_path = os.path.join(pdd, 'my_link') os.symlink(symlink_dest, old_symlink_path) @@ -266,6 +274,12 @@ def test_transmit_symlink(tmpdir, symlink_dest): assert os.path.islink(new_symlink_path) os.readlink(new_symlink_path) == symlink_dest + for fname in check_content: + abs_path = os.path.join(dest_dir, fname) + assert os.path.exists(abs_path), f'Expected "{fname}" in target dir to be a file with content.' + with open(abs_path, 'r') as f: + assert f.read() == 'hello world' + @pytest.mark.parametrize('fperm', [ 0o777,