From c28b940c8b8a8ea8b423728e05883942f5eaf661 Mon Sep 17 00:00:00 2001 From: Andrew Hlynskyi Date: Sun, 17 Nov 2024 23:17:37 +0200 Subject: [PATCH] fix: Skip broken symlinks on hash computing (#639) --- package.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/package.py b/package.py index 620be347..dfdbb65b 100644 --- a/package.py +++ b/package.py @@ -272,12 +272,16 @@ def update_hash(hash_obj, file_root, file_path): relative_path = os.path.join(file_root, file_path) hash_obj.update(relative_path.encode()) - with open(relative_path, "rb") as open_file: - while True: - data = open_file.read(1024 * 8) - if not data: - break - hash_obj.update(data) + try: + with open(relative_path, "rb") as open_file: + while True: + data = open_file.read(1024 * 8) + if not data: + break + hash_obj.update(data) + # ignore broken symlinks content to don't fail on `terraform destroy` command + except FileNotFoundError: + pass class ZipWriteStream: @@ -939,7 +943,15 @@ def execute(self, build_plan, zip_stream, query): with tempfile.NamedTemporaryFile(mode="w+t", delete=True) as temp_file: path, script = action[1:] # NOTE: Execute `pwd` to determine the subprocess shell's working directory after having executed all other commands. - script = f"{script} && pwd >{temp_file.name}" + script = "\n".join( + ( + script, + "retcode=$?", + f"pwd >{temp_file.name}", + "exit $retcode", + ) + ) + p = subprocess.Popen( script, shell=True,