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: Skip broken symlinks on hash computing #639

Merged
merged 3 commits into from
Nov 17, 2024
Merged
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
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