From 2dfb58d370a1e0201b809b7c3dc665a9820793eb Mon Sep 17 00:00:00 2001 From: "Petr \"Stone\" Hracek" Date: Mon, 11 Nov 2024 09:39:29 +0100 Subject: [PATCH 1/2] The commit fixes corner case if in upstream PR is deleted file. The downstream file is properly deleted by `os.unlink` code, it is still present. But the code that is now in Exception fixes the problem, because upstream file is not present and 'os.readlink(src_path_content)' failed with traceback FileNotFoundError. The traceback is mentioned below in the commit message. See real error: rh_cwt.main.distgit - DEBUG: unlink nginx-124/results/test/run-openshift Traceback (most recent call last): File "/usr/local/bin/rhcwt", line 8, in sys.exit(run()) ^^^^^ File "/home/phracek/.local/lib/python3.12/site-packages/rh_cwt/cli.py", line 169, in run cli.run() File "/home/phracek/.local/lib/python3.12/site-packages/rh_cwt/cli.py", line 163, in run run_function() File "/home/phracek/.local/lib/python3.12/site-packages/rh_cwt/main.py", line 369, in dist_git_merge_changes super(RhelImageRebuilder, self).dist_git_merge_changes(rebase) File "/home/phracek/.local/lib/python3.12/site-packages/container_workflow_tool/main.py", line 578, in dist_git_merge_changes self.distgit.dist_git_merge_changes(images, rebase) File "/home/phracek/.local/lib/python3.12/site-packages/container_workflow_tool/distgit.py", line 99, in dist_git_merge_changes self.pull_upstream(component, path, url, repo, ups_name, commands) File "/home/phracek/.local/lib/python3.12/site-packages/container_workflow_tool/git_operations.py", line 259, in pull_upstream self.sync_handler.handle_dangling_symlinks(cp_path, component) File "/home/phracek/.local/lib/python3.12/site-packages/container_workflow_tool/sync.py", line 101, in handle_dangling_symlinks os.readlink(src_path_content)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FileNotFoundError: [Errno 2] No such file or directory: 'upstreams/nginx/1.24/results/test/run-openshift' Signed-off-by: Petr "Stone" Hracek --- .github/workflows/build-and-push.yml | 2 +- container_workflow_tool/sync.py | 10 ++++++++-- setup.py | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build-and-push.yml b/.github/workflows/build-and-push.yml index a0ad5d8..73af180 100644 --- a/.github/workflows/build-and-push.yml +++ b/.github/workflows/build-and-push.yml @@ -20,7 +20,7 @@ jobs: with: dockerfiles: ./Dockerfile.generator image: cwt-generator - tags: latest 1 ${{ github.sha }} 1.5.9 + tags: latest 1 ${{ github.sha }} 1.5.10 - name: Push cwt-generator image to Quay.io id: push-to-quay diff --git a/container_workflow_tool/sync.py b/container_workflow_tool/sync.py index 5e833c4..e5923a9 100644 --- a/container_workflow_tool/sync.py +++ b/container_workflow_tool/sync.py @@ -97,8 +97,14 @@ def handle_dangling_symlinks(self, src_parent, dest_parent): src_path_content = os.path.join(src_parent, dest_path_rel) 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)) + # Catch exception in case of 'os.readlink(src_path_content)' does not exist. + try: + src_full = os.path.join(os.path.dirname(src_path_content), + os.readlink(src_path_content)) + except FileNotFoundError: + self.logger.debug(f"Source file {src_path_content} does not exist." + f"It was deleted by upstream PR") + continue 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 diff --git a/setup.py b/setup.py index f9ade30..4c5be62 100755 --- a/setup.py +++ b/setup.py @@ -58,7 +58,7 @@ def get_dir(system_path=None, virtual_path=None): setup( name='container-workflow-tool', - version="1.5.9", + version="1.5.10", 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', From 92964fd6112f3fa4a6f55884978c065a6370a054 Mon Sep 17 00:00:00 2001 From: "Petr \"Stone\" Hracek" Date: Tue, 12 Nov 2024 09:34:29 +0100 Subject: [PATCH 2/2] Update documentation in code why exception is used. Update also debug log message, why the file does not exist Signed-off-by: Petr "Stone" Hracek --- container_workflow_tool/sync.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/container_workflow_tool/sync.py b/container_workflow_tool/sync.py index e5923a9..30d6159 100644 --- a/container_workflow_tool/sync.py +++ b/container_workflow_tool/sync.py @@ -98,6 +98,9 @@ def handle_dangling_symlinks(self, src_parent, dest_parent): self.logger.debug(f"unlink {dest_file}") os.unlink(dest_file) # Catch exception in case of 'os.readlink(src_path_content)' does not exist. + # This code is used during update upstream -> downstream. + # The row `os.unlink` above delete dest_file in case we delete it in upstream PR + # But `os.readlink(src_path_content)` fail with traceback because of file does not exist try: src_full = os.path.join(os.path.dirname(src_path_content), os.readlink(src_path_content))