diff --git a/package.py b/package.py index 94863e26..b0376846 100644 --- a/package.py +++ b/package.py @@ -916,35 +916,33 @@ def execute(self, build_plan, zip_stream, query): # XXX: timestamp=0 - what actually do with it? zs.write_dirs(rd, prefix=prefix, timestamp=0) elif cmd == "sh": - r, w = os.pipe() - side_ch = os.fdopen(r) - path, script = action[1:] - script = "{} && pwd >&{}".format(script, w) - p = subprocess.Popen( - script, - shell=True, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - cwd=path, - pass_fds=(w,), - ) + with tempfile.NamedTemporaryFile(mode="w+t", delete=True) as temp_file: + path, script = action[1:] + script = f"{script} && pwd >{temp_file.name}" + p = subprocess.Popen( + script, + shell=True, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + cwd=path, + ) - os.close(w) - sh_work_dir = side_ch.read().strip() - p.wait() - log.info("WD: %s", sh_work_dir) - side_ch.close() - call_stdout, call_stderr = p.communicate() - exit_code = p.returncode - log.info("exit_code: %s", exit_code) - if exit_code != 0: - raise RuntimeError( - "Script did not run successfully, exit code {}: {} - {}".format( - exit_code, - call_stdout.decode("utf-8").strip(), - call_stderr.decode("utf-8").strip(), + p.wait() + temp_file.seek(0) + sh_work_dir = temp_file.read().strip() + log.info("WD: %s", sh_work_dir) + + call_stdout, call_stderr = p.communicate() + exit_code = p.returncode + log.info("exit_code: %s", exit_code) + if exit_code != 0: + raise RuntimeError( + "Script did not run successfully, exit code {}: {} - {}".format( + exit_code, + call_stdout.decode("utf-8").strip(), + call_stderr.decode("utf-8").strip(), + ) ) - ) elif cmd == "set:filter": patterns = action[1] pf = ZipContentFilter(args=self._args)