Skip to content

Commit aa2cb10

Browse files
committed
fix: make source_path blocks independent
The `source_path` blocks don't impact anymore to each other by workdir changes
1 parent 38d6715 commit aa2cb10

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

package.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,8 @@ def commands_step(path, commands):
776776
step("zip:embedded", _path, prefix)
777777
elif len(c) == 1:
778778
prefix = None
779-
step("zip:embedded", path, prefix)
779+
_path = None
780+
step("zip:embedded", _path, prefix)
780781
else:
781782
raise ValueError(
782783
":zip invalid call signature, use: "
@@ -788,6 +789,8 @@ def commands_step(path, commands):
788789
step("sh", path, "\n".join(batch))
789790
batch.clear()
790791

792+
step("reset:workdir")
793+
791794
for claim in claims:
792795
if isinstance(claim, str):
793796
path = claim
@@ -884,6 +887,8 @@ def commands_step(path, commands):
884887
return build_plan
885888

886889
def execute(self, build_plan, zip_stream, query):
890+
tf_work_dir = os.getcwd()
891+
887892
zs = zip_stream
888893
sh_work_dir = None
889894
pf = None
@@ -893,10 +898,14 @@ def execute(self, build_plan, zip_stream, query):
893898
if cmd.startswith("zip"):
894899
ts = 0 if cmd == "zip:embedded" else None
895900
source_path, prefix = action[1:]
896-
if sh_work_dir:
897-
if source_path != sh_work_dir:
898-
if not os.path.isfile(source_path):
899-
source_path = sh_work_dir
901+
if not sh_work_dir:
902+
sh_work_dir = tf_work_dir
903+
log.info("WORKDIR: %s", sh_work_dir)
904+
if source_path:
905+
if not os.path.isabs(source_path):
906+
source_path = os.path.join(sh_work_dir, source_path)
907+
else:
908+
source_path = sh_work_dir
900909
if os.path.isdir(source_path):
901910
if pf:
902911
self._zip_write_with_filter(
@@ -944,10 +953,17 @@ def execute(self, build_plan, zip_stream, query):
944953
elif cmd == "sh":
945954
with tempfile.NamedTemporaryFile(mode="w+t", delete=True) as temp_file:
946955
path, script = action[1:]
947-
# NOTE: Execute `pwd` to determine the subprocess shell's working directory after having executed all other commands.
956+
957+
if not path:
958+
path = tf_work_dir
959+
if not os.path.isabs(path):
960+
path = os.path.join(tf_work_dir, path)
961+
948962
script = "\n".join(
949963
(
950964
script,
965+
# NOTE: Execute `pwd` to determine the subprocess shell's
966+
# working directory after having executed all other commands.
951967
"retcode=$?",
952968
f"pwd >{temp_file.name}",
953969
"exit $retcode",
@@ -968,7 +984,7 @@ def execute(self, build_plan, zip_stream, query):
968984
# NOTE: This var `sh_work_dir` is consumed in cmd == "zip" loop
969985
sh_work_dir = temp_file.read().strip()
970986

971-
log.info("WD: %s", sh_work_dir)
987+
log.info("WORKDIR: %s", sh_work_dir)
972988

973989
call_stdout, call_stderr = p.communicate()
974990
exit_code = p.returncode
@@ -981,6 +997,8 @@ def execute(self, build_plan, zip_stream, query):
981997
call_stderr.decode("utf-8").strip(),
982998
)
983999
)
1000+
elif cmd == "reset:workdir":
1001+
sh_work_dir = tf_work_dir
9841002
elif cmd == "set:filter":
9851003
patterns = action[1]
9861004
pf = ZipContentFilter(args=self._args)

0 commit comments

Comments
 (0)