1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-07 01:51:47 +02:00

* Put the garbage collector in nix-store: operation `--gc',

suboperations `--print-live', `--print-dead', and `--delete'.  The
  roots are not determined by nix-store; they are read from standard
  input.  This is to make it easy to customise what the roots are.

  The collector now no longer fails when store expressions are missing
  (which legally happens when using substitutes).  It never tries to
  fetch paths through substitutes.

  TODO: acquire a global lock on the store while garbage collecting.
  
* Removed `nix-store --delete'.
This commit is contained in:
Eelco Dolstra 2004-08-25 11:43:49 +00:00
parent 9994c1dd9f
commit 818047881e
6 changed files with 167 additions and 19 deletions

View file

@ -3,6 +3,7 @@
#include "globals.hh"
#include "normalise.hh"
#include "gc.hh"
#include "archive.hh"
#include "shared.hh"
#include "dotgraph.hh"
@ -32,17 +33,6 @@ static void opRealise(Strings opFlags, Strings opArgs)
}
/* Delete a path in the Nix store directory. */
static void opDelete(Strings opFlags, Strings opArgs)
{
if (!opFlags.empty()) throw UsageError("unknown flag");
for (Strings::iterator it = opArgs.begin();
it != opArgs.end(); it++)
deleteFromStore(*it);
}
/* Add paths to the Nix values directory and print the hashes of those
paths. */
static void opAdd(Strings opFlags, Strings opArgs)
@ -220,6 +210,60 @@ static void opIsValid(Strings opFlags, Strings opArgs)
}
static void opGC(Strings opFlags, Strings opArgs)
{
if (opFlags.size() != 1) throw UsageError("missing flag");
if (!opArgs.empty())
throw UsageError("no arguments expected");
/* Do what? */
string flag = opFlags.front();
enum { soPrintLive, soPrintDead, soDelete } subOp;
if (flag == "--print-live") subOp = soPrintLive;
else if (flag == "--print-dead") subOp = soPrintDead;
else if (flag == "--delete") subOp = soDelete;
else throw UsageError(format("bad sub-operation `%1% in GC") % flag);
Paths roots;
while (1) {
Path root;
getline(cin, root);
if (cin.eof()) break;
roots.push_back(root);
}
PathSet live = findLivePaths(roots);
if (subOp == soPrintLive) {
for (PathSet::iterator i = live.begin(); i != live.end(); ++i)
cout << *i << endl;
return;
}
PathSet dead = findDeadPaths(live);
if (subOp == soPrintDead) {
for (PathSet::iterator i = dead.begin(); i != dead.end(); ++i)
cout << *i << endl;
return;
}
if (subOp == soDelete) {
/* !!! What happens if the garbage collector run is aborted
halfway through? In particular, dead paths can always
become live again (through re-instantiation), and might
then refer to deleted paths. => check instantiation
invariants */
for (PathSet::iterator i = dead.begin(); i != dead.end(); ++i) {
printMsg(lvlInfo, format("deleting `%1%'") % *i);
deleteFromStore(*i);
}
}
}
/* A sink that writes dump output to stdout. */
struct StdoutSink : DumpSink
{
@ -298,8 +342,6 @@ void run(Strings args)
if (arg == "--realise" || arg == "-r")
op = opRealise;
else if (arg == "--delete" || arg == "-d")
op = opDelete;
else if (arg == "--add" || arg == "-A")
op = opAdd;
else if (arg == "--query" || arg == "-q")
@ -312,6 +354,8 @@ void run(Strings args)
op = opValidPath;
else if (arg == "--isvalid")
op = opIsValid;
else if (arg == "--gc")
op = opGC;
else if (arg == "--dump")
op = opDump;
else if (arg == "--restore")