Merge "stx: Do not use shell for curl and wget"

This commit is contained in:
Zuul 2022-09-07 15:51:15 +00:00 committed by Gerrit Code Review
commit b4d55d8229
3 changed files with 17 additions and 8 deletions

View File

@ -187,10 +187,11 @@ def checksum(dl_file, checksum, cmd, logger):
def download(url, savepath, logger): def download(url, savepath, logger):
logger.info(f"Download {url} to {savepath}") logger.info(f"Download {url} to {savepath}")
download_cmd = "wget -t 5 --wait=15 %s -O %s"
run_shell_cmd(download_cmd % (url, savepath), logger) # Need to avoid using the shell as the URL may include '&' characters.
run_shell_cmd(["wget", "-t", "5", "--wait=15", url, "-O", savepath], logger)
return True return True

View File

@ -227,9 +227,9 @@ class DebDownloader(BaseDownloader):
dl_file = '_'.join([_name, _version, self.arch]) + '.deb' dl_file = '_'.join([_name, _version, self.arch]) + '.deb'
ret = os.path.join(self.dl_dir, dl_file) ret = os.path.join(self.dl_dir, dl_file)
tmp_file = ".".join([ret, "tmp"]) tmp_file = ".".join([ret, "tmp"])
dl_cmd = "rm -rf %s; curl -k -f %s -o %s" % (tmp_file, url, tmp_file) utils.run_shell_cmd(["rm", "-rf", tmp_file], logger)
utils.run_shell_cmd(dl_cmd, logger) utils.run_shell_cmd(["curl", "-k", "-f", url, "-o", tmp_file], logger)
utils.run_shell_cmd("mv %s %s" % (tmp_file, ret), logger) utils.run_shell_cmd(["mv", tmp_file, ret], logger)
return ret return ret
try: try:

View File

@ -122,11 +122,19 @@ def limited_walk(dir, max_depth=1):
def run_shell_cmd(cmd, logger): def run_shell_cmd(cmd, logger):
if type(cmd) is str:
shell = True
cmd_str = cmd
elif type(cmd) in (tuple, list):
shell = False
cmd_str = " ".join(cmd)
else:
raise Exception("Unrecognized 'cmd' type '%s'. Must be one of [str, list, tuple]." % (type(cmd)))
logger.info(f'[ Run - "{cmd}" ]') logger.info(f'[ Run - "{cmd_str}" ]')
try: try:
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
universal_newlines=True, shell=True) universal_newlines=True, shell=shell)
# process.wait() # process.wait()
outs, errs = process.communicate() outs, errs = process.communicate()
except Exception: except Exception: