Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(834)

Unified Diff: scripts/slave/robust_tempdir.py

Issue 1869053002: kitchen_run: initial CL (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: fixes Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « scripts/slave/kitchen_run.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: scripts/slave/robust_tempdir.py
diff --git a/scripts/slave/robust_tempdir.py b/scripts/slave/robust_tempdir.py
index 5a3198d873a2e25e309674c551dc166f5265fd22..22f848b52ee22ee6069aa34e4cfbe2f862de623f 100644
--- a/scripts/slave/robust_tempdir.py
+++ b/scripts/slave/robust_tempdir.py
@@ -43,8 +43,20 @@ class RobustTempdir(object):
self._prefix = prefix
self._leak = leak
- def cleanup(self, path):
- self._tempdirs.append(path)
+ def cleanup(self, base=None):
+ """Explicitly remove ALL temporary directories under "<base>/<prefix>".
+
+ This can be used e.g. to reduce chances of running out of disk space
+ when temporary directories are leaked.
+ """
+ base = base or tempfile.gettempdir()
+ path = os.path.join(base, self._prefix)
+ try:
+ if os.path.isdir(path):
+ LOGGER.info('Cleaning up temporary directory [%s].', path)
+ chromium_utils.RemoveDirectory(path)
+ except BaseException:
+ LOGGER.exception('Failed to clean up temporary directory [%s].', path)
def tempdir(self, base=None):
"""Creates a temporary working directory and yields it.
@@ -62,10 +74,8 @@ class RobustTempdir(object):
If None, the default temporary directory root will be used.
"""
base = base or tempfile.gettempdir()
- # TODO(phajdan.jr): Clean up leaked directories at the beginning.
- # Doing so should automatically prevent more out-of-disk-space scenarios.
basedir = _ensure_directory(base, self._prefix)
- self.cleanup(basedir)
+ self._tempdirs.append(basedir)
tdir = tempfile.mkdtemp(dir=basedir)
return tdir
« no previous file with comments | « scripts/slave/kitchen_run.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698