Clean up temp dirs when breaking locks.

A number of bots have been running out of disk space because they
are accumulating temp dirs and temp pack files.  Be more careful
to clean up temp dirs whenever UnlockAll() is called.

R=hinoka@chromium.org,agable@chromium.org
BUG=

Review URL: https://codereview.chromium.org/335253002

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@277812 0039d316-1c4b-4281-b951-d872f2087c98
changes/01/332501/1
szager@chromium.org 11 years ago
parent 3dc5cb77d8
commit 1cbf1048a6

@ -278,7 +278,7 @@ class Mirror(object):
# Download zip file to a temporary directory. # Download zip file to a temporary directory.
try: try:
tempdir = tempfile.mkdtemp() tempdir = tempfile.mkdtemp(prefix='_cache_tmp', dir=self.GetCachePath())
self.print('Downloading %s' % latest_checkout) self.print('Downloading %s' % latest_checkout)
code = gsutil.call('cp', latest_checkout, tempdir) code = gsutil.call('cp', latest_checkout, tempdir)
if code: if code:
@ -344,7 +344,7 @@ class Mirror(object):
len(pack_files) > GC_AUTOPACKLIMIT) len(pack_files) > GC_AUTOPACKLIMIT)
if should_bootstrap: if should_bootstrap:
tempdir = tempfile.mkdtemp( tempdir = tempfile.mkdtemp(
suffix=self.basedir, dir=self.GetCachePath()) prefix='_cache_tmp', suffix=self.basedir, dir=self.GetCachePath())
bootstrapped = not depth and bootstrap and self.bootstrap_repo(tempdir) bootstrapped = not depth and bootstrap and self.bootstrap_repo(tempdir)
if bootstrapped: if bootstrapped:
# Bootstrap succeeded; delete previous cache, if any. # Bootstrap succeeded; delete previous cache, if any.
@ -408,8 +408,8 @@ class Mirror(object):
except OSError: except OSError:
logging.warn('Unable to delete temporary pack file %s' % f) logging.warn('Unable to delete temporary pack file %s' % f)
@staticmethod @classmethod
def BreakLocks(path): def BreakLocks(cls, path):
did_unlock = False did_unlock = False
lf = Lockfile(path) lf = Lockfile(path)
if lf.break_lock(): if lf.break_lock():
@ -420,6 +420,7 @@ class Mirror(object):
if os.path.exists(lf): if os.path.exists(lf):
os.remove(lf) os.remove(lf)
did_unlock = True did_unlock = True
cls.DeleteTmpPackFiles(path)
return did_unlock return did_unlock
def unlock(self): def unlock(self):
@ -432,7 +433,9 @@ class Mirror(object):
repo_dirs = set([os.path.join(cachepath, path) for path in dirlist repo_dirs = set([os.path.join(cachepath, path) for path in dirlist
if os.path.isdir(os.path.join(cachepath, path))]) if os.path.isdir(os.path.join(cachepath, path))])
for dirent in dirlist: for dirent in dirlist:
if (dirent.endswith('.lock') and if dirent.startswith('_cache_tmp') or dirent.startswith('tmp'):
gclient_utils.rmtree(os.path.join(cachepath, dirent))
elif (dirent.endswith('.lock') and
os.path.isfile(os.path.join(cachepath, dirent))): os.path.isfile(os.path.join(cachepath, dirent))):
repo_dirs.add(os.path.join(cachepath, dirent[:-5])) repo_dirs.add(os.path.join(cachepath, dirent[:-5]))

Loading…
Cancel
Save