Don't check bucket permissions if --no-auth.
Checking bucket permissions takes ~400ms. We don't
need to do this if --no-auth because we know we
won't get a 403 and the 404 check will be handled
later when we try to actually download the file.
Also, remove the check for a null bucket. This
can't happen since we will throw a parser error
in the main function before we get to this code.
R=iannucci@chromium.org
Review URL: https://codereview.chromium.org/772203002
git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@293250 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/download_from_google_storage.py b/download_from_google_storage.py
index ffdd4ee..4545a95 100755
--- a/download_from_google_storage.py
+++ b/download_from_google_storage.py
@@ -110,12 +110,7 @@
return (code, out, err)
-def check_bucket_permissions(bucket, gsutil):
- if not bucket:
- print >> sys.stderr, 'Missing bucket %s.'
- return (None, 1)
- base_url = 'gs://%s' % bucket
-
+def check_bucket_permissions(base_url, gsutil):
code, _, ls_err = gsutil.check_call('ls', base_url)
if code != 0:
print >> sys.stderr, ls_err
@@ -457,10 +452,13 @@
parser.error('Output file %s exists and --no_resume is specified.'
% options.output)
+ base_url = 'gs://%s' % options.bucket
+
# Check we have a valid bucket with valid permissions.
- base_url, code = check_bucket_permissions(options.bucket, gsutil)
- if code:
- return code
+ if not options.no_auth:
+ code = check_bucket_permissions(base_url, gsutil, options.no_auth)
+ if code:
+ return code
return download_from_google_storage(
input_filename, base_url, gsutil, options.num_threads, options.directory,