From: Joerg Behrmann Date: Thu, 31 Aug 2023 07:53:13 +0000 (+0200) Subject: Use shlex.join in more places X-Git-Tag: v16~27 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ca80c088cffc339cb99766f5901c3ca11c3a02c7;p=thirdparty%2Fmkosi.git Use shlex.join in more places --- diff --git a/mkosi/run.py b/mkosi/run.py index da28c4fad..7345253d8 100644 --- a/mkosi/run.py +++ b/mkosi/run.py @@ -163,11 +163,11 @@ def run( cwd: Optional[Path] = None, log: bool = True, ) -> CompletedProcess: - if ARG_DEBUG.get(): - logging.info(f"+ {' '.join(str(s) for s in cmdline)}") - cmdline = [os.fspath(x) for x in cmdline] + if ARG_DEBUG.get(): + logging.info(f"+ {shlex.join(cmdline)}") + if not stdout and not stderr: # Unless explicit redirection is done, print all subprocess # output on stderr, since we do so as well for mkosi's own @@ -210,7 +210,7 @@ def run( die(f"{cmdline[0]} not found in PATH.") except subprocess.CalledProcessError as e: if log: - logging.error(f"\"{' '.join(str(s) for s in cmdline)}\" returned non-zero exit code {e.returncode}.") + logging.error(f"\"{shlex.join(cmdline)}\" returned non-zero exit code {e.returncode}.") raise e finally: foreground(new_process_group=False) @@ -225,7 +225,7 @@ def spawn( group: Optional[int] = None, ) -> Popen: if ARG_DEBUG.get(): - logging.info(f"+ {' '.join(str(s) for s in cmdline)}") + logging.info(f"+ {shlex.join(os.fspath(s) for s in cmdline)}") if not stdout and not stderr: # Unless explicit redirection is done, print all subprocess @@ -247,7 +247,7 @@ def spawn( except FileNotFoundError: die(f"{cmdline[0]} not found in PATH.") except subprocess.CalledProcessError as e: - logging.error(f"\"{' '.join(str(s) for s in cmdline)}\" returned non-zero exit code {e.returncode}.") + logging.error(f"\"{shlex.join(os.fspath(s) for s in cmdline)}\" returned non-zero exit code {e.returncode}.") raise e @@ -338,7 +338,7 @@ def bwrap( result = run([*cmdline, *cmd], env=env, log=False, stdin=stdin, input=input) except subprocess.CalledProcessError as e: if log: - logging.error(f"\"{' '.join(str(s) for s in cmd)}\" returned non-zero exit code {e.returncode}.") + logging.error(f"\"{shlex.join(os.fspath(s) for s in cmd)}\" returned non-zero exit code {e.returncode}.") if ARG_DEBUG_SHELL.get(): run([*cmdline, "sh"], stdin=sys.stdin, check=False, env=env, log=False) raise e