about summary refs log tree commit diff
path: root/src/nix
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2016-04-19T16·50+0200
committerEelco Dolstra <eelco.dolstra@logicblox.com>2016-04-19T16·52+0200
commite0204f8d462041387651af388074491fd0bf36d6 (patch)
treeecd20759ce49499722d140d653c5678051bcdfc2 /src/nix
parent608b0265e104b4a97f51e5745b1a32078770f3cf (diff)
Move path info caching from BinaryCacheStore to Store
Caching path info is generally useful. For instance, it speeds up "nix
path-info -rS /run/current-system" (i.e. showing the closure sizes of
all paths in the closure of the current system) from 5.6s to 0.15s.

This also eliminates some APIs like Store::queryDeriver() and
Store::queryReferences().
Diffstat (limited to 'src/nix')
-rw-r--r--src/nix/sigs.cc36
-rw-r--r--src/nix/verify.cc16
2 files changed, 27 insertions, 25 deletions
diff --git a/src/nix/sigs.cc b/src/nix/sigs.cc
index bcc46c3e7d4f..6cff5a084dec 100644
--- a/src/nix/sigs.cc
+++ b/src/nix/sigs.cc
@@ -64,19 +64,21 @@ struct CmdCopySigs : StorePathsCommand
             StringSet newSigs;
 
             for (auto & store2 : substituters) {
-                if (!store2->isValidPath(storePath)) continue;
-                auto info2 = store2->queryPathInfo(storePath);
-
-                /* Don't import signatures that don't match this
-                   binary. */
-                if (info.narHash != info2.narHash ||
-                    info.narSize != info2.narSize ||
-                    info.references != info2.references)
-                    continue;
-
-                for (auto & sig : info2.sigs)
-                    if (!info.sigs.count(sig))
-                        newSigs.insert(sig);
+                try {
+                    auto info2 = store2->queryPathInfo(storePath);
+
+                    /* Don't import signatures that don't match this
+                       binary. */
+                    if (info->narHash != info2->narHash ||
+                        info->narSize != info2->narSize ||
+                        info->references != info2->references)
+                        continue;
+
+                    for (auto & sig : info2->sigs)
+                        if (!info->sigs.count(sig))
+                            newSigs.insert(sig);
+                } catch (InvalidPath &) {
+                }
             }
 
             if (!newSigs.empty()) {
@@ -122,8 +124,8 @@ struct CmdQueryPathSigs : StorePathsCommand
         for (auto & storePath : storePaths) {
             auto info = store->queryPathInfo(storePath);
             std::cout << storePath << " ";
-            if (info.ultimate) std::cout << "ultimate ";
-            for (auto & sig : info.sigs)
+            if (info->ultimate) std::cout << "ultimate ";
+            for (auto & sig : info->sigs)
                 std::cout << sig << " ";
             std::cout << "\n";
         }
@@ -163,12 +165,12 @@ struct CmdSignPaths : StorePathsCommand
         for (auto & storePath : storePaths) {
             auto info = store->queryPathInfo(storePath);
 
-            auto info2(info);
+            auto info2(*info);
             info2.sigs.clear();
             info2.sign(secretKey);
             assert(!info2.sigs.empty());
 
-            if (!info.sigs.count(*info2.sigs.begin())) {
+            if (!info->sigs.count(*info2.sigs.begin())) {
                 store->addSignatures(storePath, info2.sigs);
                 added++;
             }
diff --git a/src/nix/verify.cc b/src/nix/verify.cc
index 39a4395cfe5b..da15678088d0 100644
--- a/src/nix/verify.cc
+++ b/src/nix/verify.cc
@@ -83,16 +83,16 @@ struct CmdVerify : StorePathsCommand
 
                 if (!noContents) {
 
-                    HashSink sink(info.narHash.type);
+                    HashSink sink(info->narHash.type);
                     store->narFromPath(storePath, sink);
 
                     auto hash = sink.finish();
 
-                    if (hash.first != info.narHash) {
+                    if (hash.first != info->narHash) {
                         corrupted = 1;
                         printMsg(lvlError,
                             format("path ‘%s’ was modified! expected hash ‘%s’, got ‘%s’")
-                            % storePath % printHash(info.narHash) % printHash(hash.first));
+                            % storePath % printHash(info->narHash) % printHash(hash.first));
                     }
 
                 }
@@ -101,7 +101,7 @@ struct CmdVerify : StorePathsCommand
 
                     bool good = false;
 
-                    if (info.ultimate && !sigsNeeded)
+                    if (info->ultimate && !sigsNeeded)
                         good = true;
 
                     else {
@@ -114,18 +114,18 @@ struct CmdVerify : StorePathsCommand
                             for (auto sig : sigs) {
                                 if (sigsSeen.count(sig)) continue;
                                 sigsSeen.insert(sig);
-                                if (info.checkSignature(publicKeys, sig))
+                                if (info->checkSignature(publicKeys, sig))
                                     validSigs++;
                             }
                         };
 
-                        doSigs(info.sigs);
+                        doSigs(info->sigs);
 
                         for (auto & store2 : substituters) {
                             if (validSigs >= actualSigsNeeded) break;
                             try {
-                                if (!store2->isValidPath(storePath)) continue;
-                                doSigs(store2->queryPathInfo(storePath).sigs);
+                                doSigs(store2->queryPathInfo(storePath)->sigs);
+                            } catch (InvalidPath &) {
                             } catch (Error & e) {
                                 printMsg(lvlError, format(ANSI_RED "error:" ANSI_NORMAL " %s") % e.what());
                             }