about summary refs log tree commit diff
path: root/src/nix-store/main.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2005-01-25T21·28+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2005-01-25T21·28+0000
commita24b78e9f1a7326badb6c38d5d63aeb6ccdf9970 (patch)
treef1d9a3fde9ab4f70e78152263d69afc29da6e393 /src/nix-store/main.cc
parent2a2756b85643de6355b7b9e3cc47574e7df82303 (diff)
* Maintain the references/referers relation also for derivations.
  This simplifies garbage collection and `nix-store --query
  --requisites' since we no longer need to treat derivations
  specially.

* Better maintaining of the invariants, e.g., setReferences() can only
  be called on a valid/substitutable path.

Diffstat (limited to 'src/nix-store/main.cc')
-rw-r--r--src/nix-store/main.cc37
1 files changed, 36 insertions, 1 deletions
diff --git a/src/nix-store/main.cc b/src/nix-store/main.cc
index ed93f2065790..ea8d398f1a2d 100644
--- a/src/nix-store/main.cc
+++ b/src/nix-store/main.cc
@@ -74,6 +74,41 @@ static void opAdd(Strings opFlags, Strings opArgs)
 }
 
 
+/* Place in `paths' the set of paths that are required to `realise'
+   the given store path, i.e., all paths necessary for valid
+   deployment of the path.  For a derivation, this is the union of
+   requisites of the inputs, plus the derivation; for other store
+   paths, it is the set of paths in the FS closure of the path.  If
+   `includeOutputs' is true, include the requisites of the output
+   paths of derivations as well.
+
+   Note that this function can be used to implement three different
+   deployment policies:
+
+   - Source deployment (when called on a derivation).
+   - Binary deployment (when called on an output path).
+   - Source/binary deployment (when called on a derivation with
+     `includeOutputs' set to true).
+*/
+static void storePathRequisites(const Path & storePath,
+    bool includeOutputs, PathSet & paths)
+{
+    computeFSClosure(storePath, paths);
+
+    if (includeOutputs) {
+        for (PathSet::iterator i = paths.begin();
+             i != paths.end(); ++i)
+            if (isDerivation(*i)) {
+                Derivation drv = derivationFromPath(*i);
+                for (DerivationOutputs::iterator j = drv.outputs.begin();
+                     j != drv.outputs.end(); ++j)
+                    if (isValidPath(j->second.path))
+                        computeFSClosure(j->second.path, paths);
+            }
+    }
+}
+
+
 static Path maybeUseOutput(const Path & storePath, bool useOutput, bool forceRealise)
 {
     if (forceRealise) realisePath(storePath);
@@ -221,7 +256,7 @@ static void opValidPath(Strings opFlags, Strings opArgs)
     createStoreTransaction(txn);
     for (Strings::iterator i = opArgs.begin();
          i != opArgs.end(); ++i)
-        registerValidPath(txn, *i, hashPath(htSHA256, *i));
+        registerValidPath(txn, *i, hashPath(htSHA256, *i), PathSet());
     txn.commit();
 }