about summary refs log tree commit diff
path: root/src/nix
diff options
context:
space:
mode:
Diffstat (limited to 'src/nix')
-rw-r--r--src/nix/path-info.cc55
1 files changed, 6 insertions, 49 deletions
diff --git a/src/nix/path-info.cc b/src/nix/path-info.cc
index a9b33e1877dd..0f9a1125f2e9 100644
--- a/src/nix/path-info.cc
+++ b/src/nix/path-info.cc
@@ -65,55 +65,12 @@ struct CmdPathInfo : StorePathsCommand
         for (auto & storePath : storePaths)
             pathLen = std::max(pathLen, storePath.size());
 
-        auto getClosureSize = [&](const Path & storePath) -> unsigned long long {
-            unsigned long long totalSize = 0;
-            PathSet closure;
-            store->computeFSClosure(storePath, closure, false, false);
-            for (auto & p : closure)
-                totalSize += store->queryPathInfo(p)->narSize;
-            return totalSize;
-        };
-
         if (json) {
-            JSONList jsonRoot(std::cout, true);
-
-            for (auto storePath : storePaths) {
-                auto info = store->queryPathInfo(storePath);
-                storePath = info->path;
-
-                auto jsonPath = jsonRoot.object();
-                jsonPath
-                    .attr("path", storePath)
-                    .attr("narHash", info->narHash.to_string())
-                    .attr("narSize", info->narSize);
-
-                if (showClosureSize)
-                    jsonPath.attr("closureSize", getClosureSize(storePath));
-
-                if (info->deriver != "")
-                    jsonPath.attr("deriver", info->deriver);
-
-                {
-                    auto jsonRefs = jsonPath.list("references");
-                    for (auto & ref : info->references)
-                        jsonRefs.elem(ref);
-                }
-
-                if (info->registrationTime)
-                    jsonPath.attr("registrationTime", info->registrationTime);
-
-                if (info->ultimate)
-                    jsonPath.attr("ultimate", info->ultimate);
-
-                if (info->ca != "")
-                    jsonPath.attr("ca", info->ca);
-
-                if (!info->sigs.empty()) {
-                    auto jsonSigs = jsonPath.list("signatures");
-                    for (auto & sig : info->sigs)
-                        jsonSigs.elem(sig);
-                }
-            }
+            JSONPlaceholder jsonRoot(std::cout, true);
+            store->pathInfoToJSON(jsonRoot,
+                // FIXME: preserve order?
+                PathSet(storePaths.begin(), storePaths.end()),
+                true, showClosureSize);
         }
 
         else {
@@ -128,7 +85,7 @@ struct CmdPathInfo : StorePathsCommand
                     std::cout << '\t' << std::setw(11) << info->narSize;
 
                 if (showClosureSize)
-                    std::cout << '\t' << std::setw(11) << getClosureSize(storePath);
+                    std::cout << '\t' << std::setw(11) << store->getClosureSize(storePath);
 
                 if (showSigs) {
                     std::cout << '\t';