[gnome-ostree] build: Only keep 2 cached buildroots by default
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-ostree] build: Only keep 2 cached buildroots by default
- Date: Wed, 21 Nov 2012 16:04:10 +0000 (UTC)
commit fefa10570fca9f76fe903052e3c503e817ba69a4
Author: Colin Walters <walters verbum org>
Date: Wed Nov 21 11:02:09 2012 -0500
build: Only keep 2 cached buildroots by default
These can add up to quite a lot of space over time.
src/ostbuild/pyostbuild/builtin_build.py | 18 ++++++++++++++++++
1 files changed, 18 insertions(+), 0 deletions(-)
---
diff --git a/src/ostbuild/pyostbuild/builtin_build.py b/src/ostbuild/pyostbuild/builtin_build.py
index a345c73..ae62924 100755
--- a/src/ostbuild/pyostbuild/builtin_build.py
+++ b/src/ostbuild/pyostbuild/builtin_build.py
@@ -57,6 +57,21 @@ class OstbuildBuild(builtins.Builtin):
output = run_sync_get_output(args)
return output.split('\n')
+ def _clean_stale_buildroots(self, buildroot_cachedir, keep_root):
+ roots = os.listdir(buildroot_cachedir)
+ root_mtimes = {}
+ for root in roots:
+ path = os.path.join(buildroot_cachedir, root)
+ root_mtimes[root] = os.lstat(path).st_mtime
+ roots.sort(lambda a,b: cmp(root_mtimes[a], root_mtimes[b]))
+ remaining = roots[:-2]
+ for root in remaining:
+ path = os.path.join(buildroot_cachedir, root)
+ if path == keep_root:
+ continue
+ log("Removing old cached buildroot %s" % (root, ))
+ shutil.rmtree(path)
+
def _compose_buildroot(self, workdir, component_name, architecture):
starttime = time.time()
@@ -121,6 +136,7 @@ class OstbuildBuild(builtins.Builtin):
cached_root = os.path.join(buildroot_cachedir, new_root_cacheid)
if os.path.isdir(cached_root):
log("Reusing cached buildroot: %s" % (cached_root, ))
+ self._clean_stale_buildroots(buildroot_cachedir, os.path.basename(cached_root))
os.unlink(tmppath)
return cached_root
@@ -142,6 +158,8 @@ class OstbuildBuild(builtins.Builtin):
fileutil.ensure_dir(os.path.join(builddir_tmp, 'results'))
os.rename(cached_root_tmp, cached_root)
+ self._clean_stale_buildroots(buildroot_cachedir, os.path.basename(cached_root))
+
endtime = time.time()
log("Composed buildroot; %d seconds elapsed" % (int(endtime - starttime),))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]