From c1fd44b01a571e82dea1aa16d9174c7c73f30118 Mon Sep 17 00:00:00 2001 From: Josip Sokcevic Date: Mon, 20 Sep 2021 22:31:37 +0000 Subject: [PATCH] Set cache-control when uploading to google storage R=gavinmak@google.com Bug: 585752 Change-Id: I25ece89abd09ad509807a7db0403bac0f5ebdd4e Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3171825 Auto-Submit: Josip Sokcevic Commit-Queue: Gavin Mak Reviewed-by: Gavin Mak --- gsutil.py | 3 ++- tests/upload_to_google_storage_unittest.py | 14 ++++++-------- upload_to_google_storage.py | 2 +- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/gsutil.py b/gsutil.py index 59a0e1466..52bd5199f 100755 --- a/gsutil.py +++ b/gsutil.py @@ -177,7 +177,8 @@ def run_gsutil(target, args, clean=False): def parse_args(): bin_dir = os.environ.get('DEPOT_TOOLS_GSUTIL_BIN_DIR', DEFAULT_BIN_DIR) - parser = argparse.ArgumentParser() + # Help is disabled as it conflicts with gsutil -h, which controls headers. + parser = argparse.ArgumentParser(add_help=False) parser.add_argument('--clean', action='store_true', help='Clear any existing gsutil package, forcing a new download.') diff --git a/tests/upload_to_google_storage_unittest.py b/tests/upload_to_google_storage_unittest.py index 4d9bf69dc..5fac9bddd 100755 --- a/tests/upload_to_google_storage_unittest.py +++ b/tests/upload_to_google_storage_unittest.py @@ -68,8 +68,8 @@ class UploadTests(unittest.TestCase): [('check_call', ('ls', '%s/%s' % (self.base_url, self.lorem_ipsum_sha1))), ('check_call', - ('cp', '-z', 'txt', filenames[0], - '%s/%s' % (self.base_url, self.lorem_ipsum_sha1)))]) + ('-h', 'Cache-Control:public, max-age=31536000', 'cp', '-z', 'txt', + filenames[0], '%s/%s' % (self.base_url, self.lorem_ipsum_sha1)))]) self.assertTrue(os.path.exists(output_filename)) self.assertEqual( open(output_filename, 'rb').read().decode(), @@ -157,12 +157,10 @@ class UploadTests(unittest.TestCase): filenames, self.base_url, self.gsutil, False, False, 1, True, None) self.assertEqual( self.gsutil.history, - [('check_call', - ('ls', '%s/%s' % (self.base_url, fake_hash))), - ('check_call', - ('ls', '-L', '%s/%s' % (self.base_url, fake_hash))), - ('check_call', - ('cp', filenames[0], '%s/%s' % (self.base_url, fake_hash)))]) + [('check_call', ('ls', '%s/%s' % (self.base_url, fake_hash))), + ('check_call', ('ls', '-L', '%s/%s' % (self.base_url, fake_hash))), + ('check_call', ('-h', 'Cache-Control:public, max-age=31536000', 'cp', + filenames[0], '%s/%s' % (self.base_url, fake_hash)))]) self.assertEqual( open(output_filename, 'rb').read().decode(), fake_hash) os.remove(output_filename) diff --git a/upload_to_google_storage.py b/upload_to_google_storage.py index 332bb9a47..9b1933d14 100755 --- a/upload_to_google_storage.py +++ b/upload_to_google_storage.py @@ -100,7 +100,7 @@ def _upload_worker( continue stdout_queue.put('%d> Uploading %s...' % ( thread_num, filename)) - gsutil_args = ['cp'] + gsutil_args = ['-h', 'Cache-Control:public, max-age=31536000', 'cp'] if gzip: gsutil_args.extend(['-z', gzip]) gsutil_args.extend([filename, file_url])