summary refs log tree commit diff
path: root/src/nix-store
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2005-12-23 21:08:42 +0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2005-12-23 21:08:42 +0000
commit4b9e7f59ca14c3de7b0cfdaebca98fa2639bbbf9 (patch)
treefa9a89816c430600b41d999f15e785e9a6ff7d3e /src/nix-store
parent3c5619c7e496b0ce7b7bc16cbcf11668cf7a69fb (diff)
downloadguix-4b9e7f59ca14c3de7b0cfdaebca98fa2639bbbf9.tar.gz
* Revived the old "nix-store --delete" operation that deletes the
  specified paths from the Nix store.  However, this operation is
  safe: it refuses to delete anything that the garbage collector
  wouldn't delete.

Diffstat (limited to 'src/nix-store')
-rw-r--r--src/nix-store/help.txt1
-rw-r--r--src/nix-store/main.cc23
2 files changed, 23 insertions, 1 deletions
diff --git a/src/nix-store/help.txt b/src/nix-store/help.txt
index 6288058357..074745813f 100644
--- a/src/nix-store/help.txt
+++ b/src/nix-store/help.txt
@@ -7,6 +7,7 @@ Operations:
   --realise / -r: ensure path validity; if a derivation, ensure that
       validity of the outputs
   --add / -A: copy a path to the Nix store
+  --delete: safely delete paths from the Nix store
   --query / -q: query information
 
   --register-substitutes: register a substitute expression (dangerous!)
diff --git a/src/nix-store/main.cc b/src/nix-store/main.cc
index 8bb1b12543..6f1fab13de 100644
--- a/src/nix-store/main.cc
+++ b/src/nix-store/main.cc
@@ -518,7 +518,7 @@ static void opGC(Strings opFlags, Strings opArgs)
 
     PathSet result;
     PrintFreed freed(action == gcDeleteDead);
-    collectGarbage(action, result, freed.bytesFreed);
+    collectGarbage(action, PathSet(), result, freed.bytesFreed);
 
     if (action != gcDeleteDead) {
         for (PathSet::iterator i = result.begin(); i != result.end(); ++i)
@@ -527,6 +527,25 @@ static void opGC(Strings opFlags, Strings opArgs)
 }
 
 
+/* Remove paths from the Nix store if possible (i.e., if they do not
+   have any remaining referrers and are not reachable from any GC
+   roots). */
+static void opDelete(Strings opFlags, Strings opArgs)
+{
+    if (!opFlags.empty()) throw UsageError("unknown flag");
+
+    PathSet pathsToDelete;
+    for (Strings::iterator i = opArgs.begin();
+         i != opArgs.end(); ++i)
+        pathsToDelete.insert(fixPath(*i));
+    
+    PathSet dummy;
+    PrintFreed freed(true);
+    collectGarbage(gcDeleteSpecific, pathsToDelete,
+        dummy, freed.bytesFreed);
+}
+
+
 /* A sink that writes dump output to stdout. */
 struct StdoutSink : DumpSink
 {
@@ -621,6 +640,8 @@ void run(Strings args)
             op = opAddFixed;
         else if (arg == "--print-fixed-path")
             op = opPrintFixedPath;
+        else if (arg == "--delete")
+            op = opDelete;
         else if (arg == "--query" || arg == "-q")
             op = opQuery;
         else if (arg == "--register-substitutes")