about summary refs log tree commit diff
path: root/src/nix-store
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2005-02-01T15·05+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2005-02-01T15·05+0000
commit65b6c8ab4c7832abdad46a29ce2ef18d289b2471 (patch)
tree3038d7ed1f60efdf2e2dad43cfec93023d7c699f /src/nix-store
parent630ae0c9d7f65a2d6bef85a5194b4d704e54eded (diff)
* Move root finding from `nix-collect-garbage' to `nix-store --gc'.
  This was necessary becase root finding must be done after
  acquisition of the global GC lock.

  This makes `nix-collect-garbage' obsolete; it is now just a wrapper
  around `nix-store --gc'.

* Automatically remove stale GC roots (i.e., indirect GC roots that
  point to non-existent paths).

Diffstat (limited to 'src/nix-store')
-rw-r--r--src/nix-store/main.cc20
1 files changed, 5 insertions, 15 deletions
diff --git a/src/nix-store/main.cc b/src/nix-store/main.cc
index 3edcff7eeef0..d473475b821a 100644
--- a/src/nix-store/main.cc
+++ b/src/nix-store/main.cc
@@ -38,9 +38,7 @@ static Path followSymlinks(Path & path)
     while (!isStorePath(path)) {
         if (!isLink(path)) return path;
         string target = readLink(path);
-        path = canonPath(string(target, 0, 1) == "/"
-            ? target
-            : path + "/" + target);
+        path = absPath(target, dirOf(path));
     }
     return path;
 }
@@ -308,27 +306,19 @@ static void opIsValid(Strings opFlags, Strings opArgs)
 
 static void opGC(Strings opFlags, Strings opArgs)
 {
-    GCAction action;
+    GCAction action = gcDeleteDead;
     
     /* Do what? */
     for (Strings::iterator i = opFlags.begin();
          i != opFlags.end(); ++i)
-        if (*i == "--print-live") action = gcReturnLive;
+        if (*i == "--print-roots") action = gcReturnRoots;
+        else if (*i == "--print-live") action = gcReturnLive;
         else if (*i == "--print-dead") action = gcReturnDead;
         else if (*i == "--delete") action = gcDeleteDead;
         else throw UsageError(format("bad sub-operation `%1%' in GC") % *i);
 
-    /* Read the roots. */
-    PathSet roots;
-    while (1) {
-        Path root;
-        getline(cin, root);
-        if (cin.eof()) break;
-        roots.insert(root);
-    }
-
     PathSet result;
-    collectGarbage(roots, action, result);
+    collectGarbage(action, result);
 
     if (action != gcDeleteDead) {
         for (PathSet::iterator i = result.begin(); i != result.end(); ++i)