summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJack Neus <jackneus@google.com>2021-10-25 22:38:44 +0000
committerJack Neus <jackneus@google.com>2021-10-26 22:18:28 +0000
commit198838599c5d4eaaa3bd68ff903925eeb4a09da9 (patch)
tree2c7f8e448acb0881397f97a71e205b613aa747e5
parent282d0cae8913e9d20f526e7fb2633bb4e2a21fbf (diff)
downloadgit-repo-198838599c5d4eaaa3bd68ff903925eeb4a09da9.tar.gz
fetch: Fix stderr handling for gsutil
Previously gsutil stderr was getting piped into stdout, which yields bad results if there are non-fatal warnings in stderr. Additionally, we should fail outright if gsutil fails (by adding `check = True`) rather than fail later on when we try to sync to a manifest that is in fact just a stderr dump. BUG=none TEST=manual runs with bad gs urls Change-Id: Id71791d0c3f180bd0601ef2c783a8e8e4afa8f59 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/321935 Tested-by: Jack Neus <jackneus@google.com> Reviewed-by: Mike Frysinger <vapier@google.com>
-rw-r--r--fetch.py10
-rw-r--r--subcmds/init.py2
2 files changed, 8 insertions, 4 deletions
diff --git a/fetch.py b/fetch.py
index 91d40cda..d79f9479 100644
--- a/fetch.py
+++ b/fetch.py
@@ -18,7 +18,7 @@ import subprocess
18import sys 18import sys
19from urllib.parse import urlparse 19from urllib.parse import urlparse
20 20
21def fetch_file(url): 21def fetch_file(url, verbose=False):
22 """Fetch a file from the specified source using the appropriate protocol. 22 """Fetch a file from the specified source using the appropriate protocol.
23 23
24 Returns: 24 Returns:
@@ -29,10 +29,14 @@ def fetch_file(url):
29 cmd = ['gsutil', 'cat', url] 29 cmd = ['gsutil', 'cat', url]
30 try: 30 try:
31 result = subprocess.run( 31 result = subprocess.run(
32 cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) 32 cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
33 check=True)
34 if result.stderr and verbose:
35 print('warning: non-fatal error running "gsutil": %s' % result.stderr,
36 file=sys.stderr)
33 return result.stdout 37 return result.stdout
34 except subprocess.CalledProcessError as e: 38 except subprocess.CalledProcessError as e:
35 print('fatal: error running "gsutil": %s' % e.output, 39 print('fatal: error running "gsutil": %s' % e.stderr,
36 file=sys.stderr) 40 file=sys.stderr)
37 sys.exit(1) 41 sys.exit(1)
38 if scheme == 'file': 42 if scheme == 'file':
diff --git a/subcmds/init.py b/subcmds/init.py
index 853cbe68..a3f3241a 100644
--- a/subcmds/init.py
+++ b/subcmds/init.py
@@ -298,7 +298,7 @@ to update the working directory files.
298 if standalone_manifest: 298 if standalone_manifest:
299 if is_new: 299 if is_new:
300 manifest_name = 'default.xml' 300 manifest_name = 'default.xml'
301 manifest_data = fetch.fetch_file(opt.manifest_url) 301 manifest_data = fetch.fetch_file(opt.manifest_url, verbose=opt.verbose)
302 dest = os.path.join(m.worktree, manifest_name) 302 dest = os.path.join(m.worktree, manifest_name)
303 os.makedirs(os.path.dirname(dest), exist_ok=True) 303 os.makedirs(os.path.dirname(dest), exist_ok=True)
304 with open(dest, 'wb') as f: 304 with open(dest, 'wb') as f: