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

Fix traceback in case source file does not exist. #79

Merged
merged 1 commit into from
Mar 26, 2024
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
17 changes: 10 additions & 7 deletions container_workflow_tool/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,17 @@ def copy_upstream2downstream(self, src_parent, dest_parent):
src = os.path.join(src_parent, f)
# First remove the dest
if os.path.isdir(dest):
self.logger.debug("rmtree {}".format(dest))
self.logger.debug(f"rmtree {dest}")
shutil.rmtree(dest)
else:
_remove_file(dest, self.logger)

# Now copy the src to dest
if os.path.islink(src) or not os.path.isdir(src):
self.logger.debug("cp {} {}".format(src, dest))
self.logger.debug(f"cp {src} {dest}")
shutil.copy2(src, dest, follow_symlinks=False)
else:
self.logger.debug("cp -r {} {}".format(src, dest))
self.logger.debug(f"cp -r {src} {dest}")
shutil.copytree(src, dest, symlinks=True)

def handle_dangling_symlinks(self, src_parent, dest_parent):
Expand Down Expand Up @@ -95,17 +95,20 @@ def handle_dangling_symlinks(self, src_parent, dest_parent):
dest_file
)
src_path_content = os.path.join(src_parent, dest_path_rel)
self.logger.debug("unlink {dest}".format(dest=dest_file))
self.logger.debug(f"unlink {dest_file}")
os.unlink(dest_file)
src_full = os.path.join(os.path.dirname(src_path_content),
os.readlink(src_path_content))
if os.path.isdir(src_full):
# In this case, when the source directory includes another symlinks outside
# of this directory, those wouldn't be fixed, so let's run the same function
# to fix dangling symlinks recursively.
self.logger.debug("cp -r {src} {dest}".format(src=src_full, dest=dest_file))
self.logger.debug(f"cp -r {src_full} {dest_file}")
shutil.copytree(src_full, dest_file, symlinks=True)
self.handle_dangling_symlinks(src_parent, dest_parent)
else:
self.logger.debug("cp {src} {dest}".format(src=src_full, dest=dest_file))
shutil.copy2(src_full, dest_file, follow_symlinks=False)
try:
self.logger.debug(f"cp {src_full} {dest_file}")
shutil.copy2(src_full, dest_file, follow_symlinks=False)
except FileNotFoundError:
self.logger.debug(f"Source file {src_full} does not exist")
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def get_dir(system_path=None, virtual_path=None):

setup(
name='container-workflow-tool',
version="1.5.5",
version="1.5.6",
description='A python3 tool to make rebuilding images easier by automating several steps of the process.',
long_description=long_description,
long_description_content_type='text/markdown',
Expand Down