Skip to content

Commit

Permalink
fix: Skip broken symlinks on hash computing (#639)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahlinc authored Nov 17, 2024
1 parent 00a7172 commit c28b940
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit c28b940

Please sign in to comment.