Skip to content

allow for copying symlinks when copying tree to create zip #134

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lambda_uploader/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ def copy_tree(src, dest, ignore=None, include_parent=False):
os.makedirs(pkg_path)

LOG.debug("Copying %s to %s" % (path, pkg_path))
shutil.copy(path, pkg_path)
if os.path.islink(path):
linkto = os.readlink(path)
os.symlink(linkto.replace(src, dest, 1), os.path.join(pkg_path, filename))
else:
shutil.copy(path, pkg_path)


# Iterate through every item in ignore
Expand Down
19 changes: 19 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,25 @@ def test_copy_tree():
rmtree(TESTING_TEMP_DIR)
rmtree(copy_dir)

def test_copy_tree_with_symlink():
os.mkdir(TESTING_TEMP_DIR)
filename = 'foo.py'
symlink_filename = "sym-{}".format(filename)
with open(path.join(TESTING_TEMP_DIR, filename), 'w') as tfile:
tfile.write(filename)
os.symlink(path.join(TESTING_TEMP_DIR,filename), path.join(TESTING_TEMP_DIR,symlink_filename))
copy_dir = '.copy_of_test'

utils.copy_tree(TESTING_TEMP_DIR, copy_dir)

assert os.path.islink(path.join(copy_dir,symlink_filename))
linkto = os.readlink(path.join(copy_dir,symlink_filename))
assert linkto == path.join(copy_dir, filename)

rmtree(TESTING_TEMP_DIR)
rmtree(copy_dir)



def test_ignore_file():
ignored = utils._ignore_file('ignore/foo.py', TEST_IGNORE)
Expand Down