From cdfcd7cf83ccdd70e783c41dd7cf490f70fb372e Mon Sep 17 00:00:00 2001 From: "szager@chromium.org" Date: Tue, 10 Jun 2014 23:40:46 +0000 Subject: [PATCH] Clean up temporary git pack files when breaking locks. When a git-cache operation is interrupted, it can leave behind large temporary pack files. Over time, these pack files will fill up disks. R=agable@chromium.org,hinoka@chromium.org,iannucci@chromium.org BUG=352268 Review URL: https://codereview.chromium.org/326203003 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@276208 0039d316-1c4b-4281-b951-d872f2087c98 --- git_cache.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/git_cache.py b/git_cache.py index 086b479b8..9ade67463 100755 --- a/git_cache.py +++ b/git_cache.py @@ -361,6 +361,18 @@ class Mirror(object): gsutil.call('cp', tmp_zipfile, dest_name) os.remove(tmp_zipfile) + @staticmethod + def DeleteTmpPackFiles(path): + pack_dir = os.path.join(path, 'objects', 'pack') + pack_files = [f for f in os.listdir(pack_dir) if + f.startswith('.tmp-') or f.startswith('tmp_pack_')] + for f in pack_files: + f = os.path.join(pack_dir, f) + try: + os.remove(f) + logging.warn('Deleted stale temporary pack file %s' % f) + except OSError: + logging.warn('Unable to delete temporary pack file %s' % f) @staticmethod def BreakLocks(path):