Skip to content

Commit

Permalink
Fix traceback in case source file does not exist.
Browse files Browse the repository at this point in the history
Also use f"" syntax instead of .format

Signed-off-by: Petr "Stone" Hracek <phracek@redhat.com>
  • Loading branch information
phracek committed Mar 25, 2024
1 parent e4bd791 commit cd787c3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
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

0 comments on commit cd787c3

Please sign in to comment.