Skip to content
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

Add copy_tree_with_update method for efficient directory copy #1355

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
20 changes: 19 additions & 1 deletion zappa/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,24 @@ def __init__(
self.cf_api_resources = []
self.cf_parameters = {}

def copy_tree_with_update(self, src, dest):
src_path = Path(src)
dest_path = Path(dest)

# Ensure destination path exists
dest_path.mkdir(parents=True, exist_ok=True)

for item in src_path.rglob('*'):
dest_item = dest_path / item.relative_to(src_path)

# Check if the item is a directory
if item.is_dir():
dest_item.mkdir(parents=True, exist_ok=True)
else:
# Copy file if it does not exist in destination or is newer
if not dest_item.exists() or os.path.getmtime(item) > os.path.getmtime(dest_item):
shutil.copy2(item, dest_item)

def configure_boto_session_method_kwargs(self, service, kw):
"""Allow for custom endpoint urls for non-AWS (testing and bootleg cloud) deployments"""
if service in self.endpoint_urls and "endpoint_url" not in kw:
Expand Down Expand Up @@ -686,7 +704,7 @@ def splitpath(path):
if egg_links:
self.copy_editable_packages(egg_links, temp_package_path)

copytree(temp_package_path, temp_project_path, metadata=False, symlinks=False)
self.copy_tree_with_update(temp_package_path, temp_project_path)

# Then the pre-compiled packages..
if use_precompiled_packages:
Expand Down