Skip to content

Commit b746163

Browse files
authored
Merge pull request #134 from nicholasjstock/master
allow for copying symlinks when copying tree to create zip
2 parents 5150fe7 + 48024b9 commit b746163

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lambda_uploader/utils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,11 @@ def copy_tree(src, dest, ignore=None, include_parent=False):
5151
os.makedirs(pkg_path)
5252

5353
LOG.debug("Copying %s to %s" % (path, pkg_path))
54-
shutil.copy(path, pkg_path)
54+
if os.path.islink(path):
55+
linkto = os.readlink(path)
56+
os.symlink(linkto.replace(src, dest, 1), os.path.join(pkg_path, filename))
57+
else:
58+
shutil.copy(path, pkg_path)
5559

5660

5761
# Iterate through every item in ignore

tests/test_utils.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,25 @@ def test_copy_tree():
5252
rmtree(TESTING_TEMP_DIR)
5353
rmtree(copy_dir)
5454

55+
def test_copy_tree_with_symlink():
56+
os.mkdir(TESTING_TEMP_DIR)
57+
filename = 'foo.py'
58+
symlink_filename = "sym-{}".format(filename)
59+
with open(path.join(TESTING_TEMP_DIR, filename), 'w') as tfile:
60+
tfile.write(filename)
61+
os.symlink(path.join(TESTING_TEMP_DIR,filename), path.join(TESTING_TEMP_DIR,symlink_filename))
62+
copy_dir = '.copy_of_test'
63+
64+
utils.copy_tree(TESTING_TEMP_DIR, copy_dir)
65+
66+
assert os.path.islink(path.join(copy_dir,symlink_filename))
67+
linkto = os.readlink(path.join(copy_dir,symlink_filename))
68+
assert linkto == path.join(copy_dir, filename)
69+
70+
rmtree(TESTING_TEMP_DIR)
71+
rmtree(copy_dir)
72+
73+
5574

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

0 commit comments

Comments
 (0)