Skip to content

Commit c28b940

Browse files
authored
fix: Skip broken symlinks on hash computing (#639)
1 parent 00a7172 commit c28b940

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

package.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,12 +272,16 @@ def update_hash(hash_obj, file_root, file_path):
272272
relative_path = os.path.join(file_root, file_path)
273273
hash_obj.update(relative_path.encode())
274274

275-
with open(relative_path, "rb") as open_file:
276-
while True:
277-
data = open_file.read(1024 * 8)
278-
if not data:
279-
break
280-
hash_obj.update(data)
275+
try:
276+
with open(relative_path, "rb") as open_file:
277+
while True:
278+
data = open_file.read(1024 * 8)
279+
if not data:
280+
break
281+
hash_obj.update(data)
282+
# ignore broken symlinks content to don't fail on `terraform destroy` command
283+
except FileNotFoundError:
284+
pass
281285

282286

283287
class ZipWriteStream:
@@ -939,7 +943,15 @@ def execute(self, build_plan, zip_stream, query):
939943
with tempfile.NamedTemporaryFile(mode="w+t", delete=True) as temp_file:
940944
path, script = action[1:]
941945
# NOTE: Execute `pwd` to determine the subprocess shell's working directory after having executed all other commands.
942-
script = f"{script} && pwd >{temp_file.name}"
946+
script = "\n".join(
947+
(
948+
script,
949+
"retcode=$?",
950+
f"pwd >{temp_file.name}",
951+
"exit $retcode",
952+
)
953+
)
954+
943955
p = subprocess.Popen(
944956
script,
945957
shell=True,

0 commit comments

Comments
 (0)