From c3999d2ed67aa2dd03c4a3e8234d948e5a0979a8 Mon Sep 17 00:00:00 2001 From: Nicholas Stock Date: Thu, 16 Mar 2017 00:20:20 +0100 Subject: [PATCH 1/2] allow for copying symlinks when copying tree to create zip --- lambda_uploader/utils.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lambda_uploader/utils.py b/lambda_uploader/utils.py index 053dcb0..4ccd0a8 100644 --- a/lambda_uploader/utils.py +++ b/lambda_uploader/utils.py @@ -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, os.path.join(pkg_path, filename)) + else: + shutil.copy(path, pkg_path) # Iterate through every item in ignore From 48024b9fe5f9aaf88223f25327956b865fec008b Mon Sep 17 00:00:00 2001 From: Nicholas Stock Date: Sun, 19 Mar 2017 23:52:37 +0100 Subject: [PATCH 2/2] add test fix bug --- lambda_uploader/utils.py | 2 +- tests/test_utils.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lambda_uploader/utils.py b/lambda_uploader/utils.py index 4ccd0a8..040f6a9 100644 --- a/lambda_uploader/utils.py +++ b/lambda_uploader/utils.py @@ -53,7 +53,7 @@ def copy_tree(src, dest, ignore=None, include_parent=False): LOG.debug("Copying %s to %s" % (path, pkg_path)) if os.path.islink(path): linkto = os.readlink(path) - os.symlink(linkto, os.path.join(pkg_path, filename)) + os.symlink(linkto.replace(src, dest, 1), os.path.join(pkg_path, filename)) else: shutil.copy(path, pkg_path) diff --git a/tests/test_utils.py b/tests/test_utils.py index 1424821..d87352c 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -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)