From 884646593488bfacd851bec72b7ac1a4841bf458 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 29 Jul 2003 14:28:17 +0000 Subject: * Get garbage collection and cache population to work *properly*. Renamed `fstateRefs' to `fstateRequisites'. The semantics of this function is that it returns a list of all paths necessary to realise a given expression. For a derive expression, this is the union of requisites of the inputs; for a slice expression, it is the path of each element in the slice. Also included are the paths of the expressions themselves. Optionally, one can also include the requisites of successor expressions (to recycle intermediate results). * `nix-switch' now distinguishes between an expression and its normal form. Usually, only the normal form is registered as a root of the garbage collector. With the `--source-root' flag, it will also register the original expression as a root. * `nix-collect-garbage' now has a flag `--keep-successors' which causes successors not to be included in the list of garbage paths. * `nix-collect-garbage' now has a flag `--invert' which will print all paths that should *not* be garbage collected. --- src/normalise.cc | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'src/normalise.cc') diff --git a/src/normalise.cc b/src/normalise.cc index eefb790b6f98..5ef4d82ac139 100644 --- a/src/normalise.cc +++ b/src/normalise.cc @@ -244,7 +244,8 @@ Strings fstatePaths(const FSId & id) } -static void fstateRefsSet(const FSId & id, StringSet & paths) +static void fstateRequisitesSet(const FSId & id, + bool includeExprs, bool includeSuccessors, StringSet & paths) { FState fs = parseFState(termFromId(id)); @@ -257,17 +258,28 @@ static void fstateRefsSet(const FSId & id, StringSet & paths) else if (fs.type == FState::fsDerive) { for (FSIds::iterator i = fs.derive.inputs.begin(); i != fs.derive.inputs.end(); i++) - fstateRefsSet(*i, paths); + fstateRequisitesSet(*i, + includeExprs, includeSuccessors, paths); } else abort(); + + if (includeExprs) + paths.insert(expandId(id)); + + string idSucc; + if (includeSuccessors && + queryDB(nixDB, dbSuccessors, id, idSucc)) + fstateRequisitesSet(parseHash(idSucc), + includeExprs, includeSuccessors, paths); } -Strings fstateRefs(const FSId & id) +Strings fstateRequisites(const FSId & id, + bool includeExprs, bool includeSuccessors) { StringSet paths; - fstateRefsSet(id, paths); + fstateRequisitesSet(id, includeExprs, includeSuccessors, paths); return Strings(paths.begin(), paths.end()); } -- cgit 1.4.1