about summary refs log tree commit diff
path: root/src/nix-store
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2004-06-20T19·17+0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2004-06-20T19·17+0000
commit112ee89501a936ad9c492780be6b63f53b2eb9ca (patch)
tree2070bc757fa986b062b7964619ad927b272fd1de /src/nix-store
parentbafb2357d1ab5f7aef8ce4495f5ab8b835359f63 (diff)
* Re-enable support for substitutes in the normaliser.
* A better substitute mechanism.

  Instead of generating a store expression for each store path for
  which we have a substitute, we can have a single store expression
  that builds a generic program that is invoked to build the desired
  store path, which is passed as an argument.

  This means that operations like `nix-pull' only produce O(1) files
  instead of O(N) files in the store when registering N substitutes.
  (It consumes O(N) database storage, of course, but that's not a
  performance problem).

* Added a test for the substitute mechanism.
  
* `nix-store --substitute' reads the substitutes from standard input,
  instead of from the command line.  This prevents us from running
  into the kernel's limit on command line length.

Diffstat (limited to 'src/nix-store')
-rw-r--r--src/nix-store/main.cc54
1 files changed, 31 insertions, 23 deletions
diff --git a/src/nix-store/main.cc b/src/nix-store/main.cc
index 4be8e8f4495b..79d65c4be5d5 100644
--- a/src/nix-store/main.cc
+++ b/src/nix-store/main.cc
@@ -18,12 +18,6 @@ void printHelp()
 }
 
 
-static Path checkPath(const Path & arg)
-{
-    return arg; /* !!! check that arg is in the store */
-}
-
-
 /* Realise paths from the given store expressions. */
 static void opRealise(Strings opFlags, Strings opArgs)
 {
@@ -32,7 +26,7 @@ static void opRealise(Strings opFlags, Strings opArgs)
     for (Strings::iterator i = opArgs.begin();
          i != opArgs.end(); i++)
     {
-        Path nfPath = normaliseStoreExpr(checkPath(*i));
+        Path nfPath = normaliseStoreExpr(*i);
         realiseClosure(nfPath);
         cout << format("%1%\n") % (string) nfPath;
     }
@@ -46,7 +40,7 @@ static void opDelete(Strings opFlags, Strings opArgs)
 
     for (Strings::iterator it = opArgs.begin();
          it != opArgs.end(); it++)
-        deleteFromStore(checkPath(*it));
+        deleteFromStore(*it);
 }
 
 
@@ -101,7 +95,7 @@ static void opQuery(Strings opFlags, Strings opArgs)
                  i != opArgs.end(); i++)
             {
                 StringSet paths = storeExprRoots(
-                    maybeNormalise(checkPath(*i), normalise, realise));
+                    maybeNormalise(*i, normalise, realise));
                 for (StringSet::iterator j = paths.begin(); 
                      j != paths.end(); j++)
                     cout << format("%s\n") % *j;
@@ -115,7 +109,7 @@ static void opQuery(Strings opFlags, Strings opArgs)
                  i != opArgs.end(); i++)
             {
                 StringSet paths2 = storeExprRequisites(
-                    maybeNormalise(checkPath(*i), normalise, realise),
+                    maybeNormalise(*i, normalise, realise),
                     includeExprs, includeSuccessors);
                 paths.insert(paths2.begin(), paths2.end());
             }
@@ -129,7 +123,7 @@ static void opQuery(Strings opFlags, Strings opArgs)
             for (Strings::iterator i = opArgs.begin();
                  i != opArgs.end(); i++)
             {
-                Paths preds = queryPredecessors(checkPath(*i));
+                Paths preds = queryPredecessors(*i);
                 for (Paths::iterator j = preds.begin();
                      j != preds.end(); j++)
                     cout << format("%s\n") % *j;
@@ -141,7 +135,7 @@ static void opQuery(Strings opFlags, Strings opArgs)
             PathSet roots;
             for (Strings::iterator i = opArgs.begin();
                  i != opArgs.end(); i++)
-                roots.insert(maybeNormalise(checkPath(*i), normalise, realise));
+                roots.insert(maybeNormalise(*i, normalise, realise));
 	    printDotGraph(roots);
             break;
         }
@@ -162,8 +156,8 @@ static void opSuccessor(Strings opFlags, Strings opArgs)
     for (Strings::iterator i = opArgs.begin();
          i != opArgs.end(); )
     {
-        Path path1 = checkPath(*i++);
-        Path path2 = checkPath(*i++);
+        Path path1 = *i++;
+        Path path2 = *i++;
         registerSuccessor(txn, path1, path2);
     }
     txn.commit();
@@ -173,14 +167,28 @@ static void opSuccessor(Strings opFlags, Strings opArgs)
 static void opSubstitute(Strings opFlags, Strings opArgs)
 {
     if (!opFlags.empty()) throw UsageError("unknown flag");
-    if (opArgs.size() % 2) throw UsageError("expecting even number of arguments");
-    
-    for (Strings::iterator i = opArgs.begin();
-         i != opArgs.end(); )
-    {
-        Path src = checkPath(*i++);
-        Path sub = checkPath(*i++);
-        registerSubstitute(src, sub);
+    if (!opArgs.empty())
+        throw UsageError("no arguments expected");
+
+    while (1) {
+        Path srcPath;
+        Substitute sub;
+        getline(cin, srcPath);
+        if (cin.eof()) break;
+        getline(cin, sub.storeExpr);
+        getline(cin, sub.program);
+        string s;
+        getline(cin, s);
+        istringstream st(s);
+        int n;
+        st >> n;
+        if (!st) throw Error("number expected");
+        while (n--) {
+            getline(cin, s);
+            sub.args.push_back(s);
+        }
+        if (!cin || cin.eof()) throw Error("missing input");
+        registerSubstitute(srcPath, sub);
     }
 }
 
@@ -260,7 +268,7 @@ static void opInit(Strings opFlags, Strings opArgs)
 {
     if (!opFlags.empty()) throw UsageError("unknown flag");
     if (!opArgs.empty())
-        throw UsageError("--init does not have arguments");
+        throw UsageError("no arguments expected");
     initDB();
 }