about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libstore/store-api.cc62
-rw-r--r--src/libstore/store-api.hh4
-rw-r--r--src/nix/path-info.cc2
3 files changed, 38 insertions, 30 deletions
diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc
index 108e2d4ce9b0..0440af95fa42 100644
--- a/src/libstore/store-api.cc
+++ b/src/libstore/store-api.cc
@@ -455,49 +455,55 @@ string Store::makeValidityRegistration(const PathSet & paths,
 
 
 void Store::pathInfoToJSON(JSONPlaceholder & jsonOut, const PathSet & storePaths,
-    bool includeImpureInfo, bool showClosureSize)
+    bool includeImpureInfo, bool showClosureSize, AllowInvalidFlag allowInvalid)
 {
     auto jsonList = jsonOut.list();
 
     for (auto storePath : storePaths) {
-        auto info = queryPathInfo(storePath);
-        storePath = info->path;
-
         auto jsonPath = jsonList.object();
-        jsonPath
-            .attr("path", storePath)
-            .attr("narHash", info->narHash.to_string())
-            .attr("narSize", info->narSize);
+        jsonPath.attr("path", storePath);
 
-        {
-            auto jsonRefs = jsonPath.list("references");
-            for (auto & ref : info->references)
-                jsonRefs.elem(ref);
-        }
+        try {
+            auto info = queryPathInfo(storePath);
+            storePath = info->path;
 
-        if (info->ca != "")
-            jsonPath.attr("ca", info->ca);
+            jsonPath
+                .attr("narHash", info->narHash.to_string())
+                .attr("narSize", info->narSize);
 
-        if (showClosureSize)
-            jsonPath.attr("closureSize", getClosureSize(storePath));
+            {
+                auto jsonRefs = jsonPath.list("references");
+                for (auto & ref : info->references)
+                    jsonRefs.elem(ref);
+            }
 
-        if (includeImpureInfo) {
+            if (info->ca != "")
+                jsonPath.attr("ca", info->ca);
 
-            if (info->deriver != "")
-                jsonPath.attr("deriver", info->deriver);
+            if (showClosureSize)
+                jsonPath.attr("closureSize", getClosureSize(storePath));
 
-            if (info->registrationTime)
-                jsonPath.attr("registrationTime", info->registrationTime);
+            if (includeImpureInfo) {
 
-            if (info->ultimate)
-                jsonPath.attr("ultimate", info->ultimate);
+                if (info->deriver != "")
+                    jsonPath.attr("deriver", info->deriver);
+
+                if (info->registrationTime)
+                    jsonPath.attr("registrationTime", info->registrationTime);
+
+                if (info->ultimate)
+                    jsonPath.attr("ultimate", info->ultimate);
+
+                if (!info->sigs.empty()) {
+                    auto jsonSigs = jsonPath.list("signatures");
+                    for (auto & sig : info->sigs)
+                        jsonSigs.elem(sig);
+                }
 
-            if (!info->sigs.empty()) {
-                auto jsonSigs = jsonPath.list("signatures");
-                for (auto & sig : info->sigs)
-                    jsonSigs.elem(sig);
             }
 
+        } catch (InvalidPath &) {
+            jsonPath.attr("valid", false);
         }
     }
 }
diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh
index cada37653e6f..586d35e84ffd 100644
--- a/src/libstore/store-api.hh
+++ b/src/libstore/store-api.hh
@@ -35,6 +35,7 @@ class JSONPlaceholder;
 enum RepairFlag : bool { NoRepair = false, Repair = true };
 enum CheckSigsFlag : bool { NoCheckSigs = false, CheckSigs = true };
 enum SubstituteFlag : bool { NoSubstitute = false, Substitute = true };
+enum AllowInvalidFlag : bool { DisallowInvalid = false, AllowInvalid = true };
 
 
 /* Size of the hash part of store paths, in base-32 characters. */
@@ -488,7 +489,8 @@ public:
        included. If ‘showClosureSize’ is true, the closure size of
        each path is included. */
     void pathInfoToJSON(JSONPlaceholder & jsonOut, const PathSet & storePaths,
-        bool includeImpureInfo, bool showClosureSize);
+        bool includeImpureInfo, bool showClosureSize,
+        AllowInvalidFlag allowInvalid = DisallowInvalid);
 
     /* Return the size of the closure of the specified path, that is,
        the sum of the size of the NAR serialisation of each path in
diff --git a/src/nix/path-info.cc b/src/nix/path-info.cc
index f16209238610..f7610ab0814d 100644
--- a/src/nix/path-info.cc
+++ b/src/nix/path-info.cc
@@ -69,7 +69,7 @@ struct CmdPathInfo : StorePathsCommand, MixJSON
             store->pathInfoToJSON(jsonRoot,
                 // FIXME: preserve order?
                 PathSet(storePaths.begin(), storePaths.end()),
-                true, showClosureSize);
+                true, showClosureSize, AllowInvalid);
         }
 
         else {