From c8444f3a2d94879eda073e2d0fd651d26073b05e Mon Sep 17 00:00:00 2001 From: "hinoka@chromium.org" Date: Wed, 18 Jun 2014 23:18:17 +0000 Subject: [PATCH] Allow pruning other files when uploading bootstrap tarball BUG=366748 Review URL: https://codereview.chromium.org/337763005 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@278190 0039d316-1c4b-4281-b951-d872f2087c98 --- git_cache.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/git_cache.py b/git_cache.py index 1b135d50b..f472a1ae6 100755 --- a/git_cache.py +++ b/git_cache.py @@ -381,7 +381,7 @@ class Mirror(object): if tempdir: os.rename(tempdir, self.mirror_path) - def update_bootstrap(self): + def update_bootstrap(self, prune=False): # The files are named .zip gen_number = subprocess.check_output( [self.git_exe, 'number', 'master'], cwd=self.mirror_path).strip() @@ -391,11 +391,19 @@ class Mirror(object): os.remove(tmp_zipfile) subprocess.call(['zip', '-r', tmp_zipfile, '.'], cwd=self.mirror_path) gsutil = Gsutil(path=self.gsutil_exe, boto_path=None) - dest_name = 'gs://%s/%s/%s.zip' % ( - self.bootstrap_bucket, self.basedir, gen_number) + gs_folder = 'gs://%s/%s' % (self.bootstrap_bucket, self.basedir) + dest_name = '%s/%s.zip' % (gs_folder, gen_number) gsutil.call('cp', tmp_zipfile, dest_name) os.remove(tmp_zipfile) + # Remove all other files in the same directory. + if prune: + _, ls_out, _ = gsutil.check_call('ls', gs_folder) + for filename in ls_out.splitlines(): + if filename == dest_name: + continue + gsutil.call('rm', filename) + @staticmethod def DeleteTmpPackFiles(path): pack_dir = os.path.join(path, 'objects', 'pack') @@ -473,16 +481,19 @@ def CMDupdate_bootstrap(parser, args): print('Sorry, update bootstrap will not work on Windows.', file=sys.stderr) return 1 + parser.add_option('--prune', action='store_true', + help='Prune all other cached zipballs of the same repo.') + # First, we need to ensure the cache is populated. populate_args = args[:] populate_args.append('--no_bootstrap') CMDpopulate(parser, populate_args) # Get the repo directory. - _, args = parser.parse_args(args) + options, args = parser.parse_args(args) url = args[0] mirror = Mirror(url) - mirror.update_bootstrap() + mirror.update_bootstrap(options.prune) return 0