Skip to content

Commit 76181c3

Browse files
committed
Don't execute untar_to() subprocesses through the shell
1 parent a571f95 commit 76181c3

4 files changed

Lines changed: 25 additions & 15 deletions

File tree

planemo/commands/cmd_project_init.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414

1515
SOURCE_HOST = "https://codeload.github.com"
1616
DOWNLOAD_URL = "%s/galaxyproject/planemo/tar.gz/master" % SOURCE_HOST
17-
UNTAR_FILTER = "--strip-components=2"
18-
UNTAR_ARGS = " -C %s -zxf - " + UNTAR_FILTER
1917

2018

2119
@click.command("project_init")
@@ -38,9 +36,9 @@ def cli(ctx, path, template=None, **kwds):
3836
return
3937

4038
tempdir = tempfile.mkdtemp()
39+
tar_args = ['-zxf', '-', '--strip-components=2']
4140
try:
42-
untar_args = UNTAR_ARGS % (tempdir)
43-
untar_to(DOWNLOAD_URL, tempdir, untar_args)
41+
untar_to(DOWNLOAD_URL, tar_args=tar_args, dest_dir=tempdir)
4442
template_dir = os.path.join(tempdir, template)
4543
for entry in os.listdir(template_dir):
4644
shutil.move(os.path.join(template_dir, entry), path)

planemo/github_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def _try_download_hub(planemo_hub_path):
104104
link = _hub_link()
105105
# Strip URL base and .tgz at the end.
106106
basename = link.split("/")[-1].rsplit(".", 1)[0]
107-
untar_to(link, tar_args="-Ozxvf - %s/bin/hub > '%s'" % (basename, planemo_hub_path))
107+
untar_to(link, tar_args=['-zxvf', '-', "%s/bin/hub" % basename], path=planemo_hub_path)
108108
communicate(["chmod", "+x", planemo_hub_path])
109109

110110

planemo/io.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import fnmatch
77
import os
88
import shutil
9+
import subprocess
910
import sys
1011
import tempfile
1112
import time
@@ -96,17 +97,28 @@ def write_file(path, content, force=True):
9697
f.write(content)
9798

9899

99-
def untar_to(url, path=None, tar_args=None):
100-
download_cmd = " ".join(download_command(url, quote_url=True))
100+
def untar_to(url, tar_args=None, path=None, dest_dir=None):
101101
if tar_args:
102+
assert not (path and dest_dir)
103+
if dest_dir:
104+
if not os.path.exists(dest_dir):
105+
os.makedirs(dest_dir)
106+
tar_args.extend(['-C', dest_dir])
102107
if path:
103-
if not os.path.exists(path):
104-
os.makedirs(path)
108+
tar_args.append('-O')
105109

106-
untar_cmd = "tar %s" % tar_args
107-
shell("%s | %s" % (download_cmd, untar_cmd))
110+
download_cmd = download_command(url)
111+
download_p = commands.shell_process(download_cmd, stdout=subprocess.PIPE)
112+
untar_cmd = ['tar'] + tar_args
113+
if path:
114+
with open(path, 'wb') as fh:
115+
shell(untar_cmd, stdin=download_p.stdout, stdout=fh)
116+
else:
117+
shell(untar_cmd, stdin=download_p.stdout)
118+
download_p.wait()
108119
else:
109-
shell("%s > '%s'" % (download_cmd, path))
120+
cmd = download_command(url, to=path)
121+
shell(cmd)
110122

111123

112124
def find_matching_directories(path, pattern, recursive):

planemo/shed/interface.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ def download_tar(tsi, repo_id, destination, to_directory):
105105
base_url += "/"
106106
download_url = REPOSITORY_DOWNLOAD_TEMPLATE % (base_url, repo_id)
107107
if to_directory:
108-
untar_args = "-xzf - -C %s --strip-components 1" % destination
108+
tar_args = ['-xzf', '-', '--strip-components=1']
109+
untar_to(download_url, tar_args=tar_args, dest_dir=destination)
109110
else:
110-
untar_args = None
111-
untar_to(download_url, destination, untar_args)
111+
untar_to(download_url, path=destination)
112112

113113

114114
def _user(tsi):

0 commit comments

Comments
 (0)