diff options
| author | Mike Frysinger <vapier@google.com> | 2025-04-09 19:59:05 -0400 |
|---|---|---|
| committer | LUCI <gerrit-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2025-04-10 10:23:08 -0700 |
| commit | 0214730c9afaf732b3571f3f63416fea9f98a65c (patch) | |
| tree | 0feec359ea1c00d67f8d4f21c38c8fd6f4f528c9 | |
| parent | daebd6cbc2ae642021bcc209484e7249edc656ea (diff) | |
| download | git-repo-0214730c9afaf732b3571f3f63416fea9f98a65c.tar.gz | |
launcher: switch command quoting to shlex.quote
Minor fix, but just in case, provides properly quoted commands for
people to copy & paste.
Change-Id: Ia9fce5c0df9f51cbed9d49861adcf6821251e46f
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/466821
Tested-by: Mike Frysinger <vapier@google.com>
Commit-Queue: Mike Frysinger <vapier@google.com>
Reviewed-by: Gavin Mak <gavinmak@google.com>
| -rw-r--r-- | release/util.py | 8 | ||||
| -rwxr-xr-x | repo | 11 |
2 files changed, 10 insertions, 9 deletions
diff --git a/release/util.py b/release/util.py index df7a5638..c839b872 100644 --- a/release/util.py +++ b/release/util.py | |||
| @@ -16,6 +16,7 @@ | |||
| 16 | 16 | ||
| 17 | import os | 17 | import os |
| 18 | import re | 18 | import re |
| 19 | import shlex | ||
| 19 | import subprocess | 20 | import subprocess |
| 20 | import sys | 21 | import sys |
| 21 | 22 | ||
| @@ -35,12 +36,7 @@ KEYID_ECC = "E1F9040D7A3F6DAFAC897CD3D3B95DA243E48A39" | |||
| 35 | 36 | ||
| 36 | def cmdstr(cmd): | 37 | def cmdstr(cmd): |
| 37 | """Get a nicely quoted shell command.""" | 38 | """Get a nicely quoted shell command.""" |
| 38 | ret = [] | 39 | return " ".join(shlex.quote(x) for x in cmd) |
| 39 | for arg in cmd: | ||
| 40 | if not re.match(r"^[a-zA-Z0-9/_.=-]+$", arg): | ||
| 41 | arg = f'"{arg}"' | ||
| 42 | ret.append(arg) | ||
| 43 | return " ".join(ret) | ||
| 44 | 40 | ||
| 45 | 41 | ||
| 46 | def run(opts, cmd, check=True, **kwargs): | 42 | def run(opts, cmd, check=True, **kwargs): |
| @@ -57,9 +57,14 @@ class Trace: | |||
| 57 | trace = Trace() | 57 | trace = Trace() |
| 58 | 58 | ||
| 59 | 59 | ||
| 60 | def cmdstr(cmd): | ||
| 61 | """Get a nicely quoted shell command.""" | ||
| 62 | return " ".join(shlex.quote(x) for x in cmd) | ||
| 63 | |||
| 64 | |||
| 60 | def exec_command(cmd): | 65 | def exec_command(cmd): |
| 61 | """Execute |cmd| or return None on failure.""" | 66 | """Execute |cmd| or return None on failure.""" |
| 62 | trace.print(":", " ".join(cmd)) | 67 | trace.print(":", cmdstr(cmd)) |
| 63 | try: | 68 | try: |
| 64 | if platform.system() == "Windows": | 69 | if platform.system() == "Windows": |
| 65 | ret = subprocess.call(cmd) | 70 | ret = subprocess.call(cmd) |
| @@ -506,7 +511,7 @@ def run_command(cmd, **kwargs): | |||
| 506 | # Run & package the results. | 511 | # Run & package the results. |
| 507 | proc = subprocess.Popen(cmd, **kwargs) | 512 | proc = subprocess.Popen(cmd, **kwargs) |
| 508 | (stdout, stderr) = proc.communicate(input=cmd_input) | 513 | (stdout, stderr) = proc.communicate(input=cmd_input) |
| 509 | dbg = ": " + " ".join(cmd) | 514 | dbg = ": " + cmdstr(cmd) |
| 510 | if cmd_input is not None: | 515 | if cmd_input is not None: |
| 511 | dbg += " 0<|" | 516 | dbg += " 0<|" |
| 512 | if stdout == subprocess.PIPE: | 517 | if stdout == subprocess.PIPE: |
| @@ -843,7 +848,7 @@ def _GetRepoConfig(name): | |||
| 843 | return None | 848 | return None |
| 844 | else: | 849 | else: |
| 845 | print( | 850 | print( |
| 846 | f"repo: error: git {' '.join(cmd)} failed:\n{ret.stderr}", | 851 | f"repo: error: git {cmdstr(cmd)} failed:\n{ret.stderr}", |
| 847 | file=sys.stderr, | 852 | file=sys.stderr, |
| 848 | ) | 853 | ) |
| 849 | # This will raise subprocess.CalledProcessError for us. | 854 | # This will raise subprocess.CalledProcessError for us. |
