Skip to content

Commit

Permalink
Merge pull request #736 from jbradberry/fix-symlink-dirs
Browse files Browse the repository at this point in the history
Directories that are symlinks need to be treated as if they are a sym…
  • Loading branch information
jbradberry authored Jun 23, 2021
2 parents 9d798ee + 2f9bc3f commit ee8e927
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion ansible_runner/utils/streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
26 changes: 20 additions & 6 deletions test/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit ee8e927

Please sign in to comment.