From 6fc60e2060be5958c2aad1c859ee60bae5e23980 Mon Sep 17 00:00:00 2001 From: Michael Raskin <7c6f434c@mail.ru> Date: Thu, 15 Nov 2007 03:47:12 +0000 Subject: [PATCH] Added possibility to specify garbage collection levels for store paths; so packages can share intermediate results of compilation and GC will collect it automatically while never touching tarballs, for example. --- src/libstore/gc.cc | 19 +++++++++++++++---- src/libstore/gc.hh | 6 ++++++ 2 files changed, 21 insertions(+), 4 deletions(-) create mode 100644 src/libstore/gc.hh diff --git a/src/libstore/gc.cc b/src/libstore/gc.cc index e2e6c23fd..53ee100f9 100644 --- a/src/libstore/gc.cc +++ b/src/libstore/gc.cc @@ -4,6 +4,7 @@ #include "local-store.hh" #include "db.hh" #include "util.hh" +#include "gc.hh" #include @@ -445,6 +446,8 @@ void LocalStore::collectGarbage(GCAction action, const PathSet & pathsToDelete, queryBoolSetting("gc-keep-outputs", false); bool gcKeepDerivations = queryBoolSetting("gc-keep-derivations", true); + unsigned int gcKeepOutputsThreshold = + queryIntSetting ("gc-keep-outputs-threshold", defaultGcLevel); /* Acquire the global GC root. This prevents a) New roots from being added. @@ -496,10 +499,18 @@ void LocalStore::collectGarbage(GCAction action, const PathSet & pathsToDelete, i != livePaths.end(); ++i) if (isDerivation(*i)) { Derivation drv = derivationFromPath(*i); - for (DerivationOutputs::iterator j = drv.outputs.begin(); - j != drv.outputs.end(); ++j) - if (store->isValidPath(j->second.path)) - computeFSClosure(j->second.path, livePaths); + + string gcLevelStr = drv.env["__gcLevel"]; + int gcLevel; + if (!string2Int(gcLevelStr,gcLevel)) { + gcLevel = defaultGcLevel; + } + + if (gcLevel >= gcKeepOutputsThreshold) + for (DerivationOutputs::iterator j = drv.outputs.begin(); + j != drv.outputs.end(); ++j) + if (store->isValidPath(j->second.path)) + computeFSClosure(j->second.path, livePaths); } } diff --git a/src/libstore/gc.hh b/src/libstore/gc.hh new file mode 100644 index 000000000..c86f7678b --- /dev/null +++ b/src/libstore/gc.hh @@ -0,0 +1,6 @@ +#ifndef __GC_H_INCLUDED +#define __GC_H_INCLUDED + +const unsigned int defaultGcLevel = 1000; + +#endif //__GC_H_INCLUDED