about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-07-14T15·36+0200
committerEelco Dolstra <edolstra@gmail.com>2017-07-14T16·29+0200
commit766ad5db3b2e8678b649375e59191978671c821e (patch)
treed5721aa938edbd907102f0bc43e3547e01fdbb7a /src
parentfdc9da034fd7e0cb9c5275209d991ed6ca38f1cc (diff)
nix path-info: Show download sizes for binary cache stores
E.g.

  $ nix path-info --json --store https://cache.nixos.org nixpkgs.thunderbird -S
  ...
      "downloadHash": "sha256:1jlixpzi225wwa0f4xdrwrqgi47ip1qpj9p06fyxxg07sfmyi4q0",
      "downloadSize": 43047620,
      "closureDownloadSize": 84745960
    }
  ]
Diffstat (limited to 'src')
-rw-r--r--src/libstore/store-api.cc35
-rw-r--r--src/libstore/store-api.hh2
-rw-r--r--src/nix/path-info.cc2
3 files changed, 30 insertions, 9 deletions
diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc
index 0440af95fa42..339445aa064a 100644
--- a/src/libstore/store-api.cc
+++ b/src/libstore/store-api.cc
@@ -480,8 +480,12 @@ void Store::pathInfoToJSON(JSONPlaceholder & jsonOut, const PathSet & storePaths
             if (info->ca != "")
                 jsonPath.attr("ca", info->ca);
 
-            if (showClosureSize)
-                jsonPath.attr("closureSize", getClosureSize(storePath));
+            std::pair<uint64_t, uint64_t> closureSizes;
+
+            if (showClosureSize) {
+                closureSizes = getClosureSize(storePath);
+                jsonPath.attr("closureSize", closureSizes.first);
+            }
 
             if (includeImpureInfo) {
 
@@ -500,6 +504,17 @@ void Store::pathInfoToJSON(JSONPlaceholder & jsonOut, const PathSet & storePaths
                         jsonSigs.elem(sig);
                 }
 
+                auto narInfo = std::dynamic_pointer_cast<const NarInfo>(
+                    std::shared_ptr<const ValidPathInfo>(info));
+
+                if (narInfo) {
+                    if (narInfo->fileHash)
+                        jsonPath.attr("downloadHash", narInfo->fileHash.to_string());
+                    if (narInfo->fileSize)
+                        jsonPath.attr("downloadSize", narInfo->fileSize);
+                    if (showClosureSize)
+                        jsonPath.attr("closureDownloadSize", closureSizes.second);
+                }
             }
 
         } catch (InvalidPath &) {
@@ -509,14 +524,20 @@ void Store::pathInfoToJSON(JSONPlaceholder & jsonOut, const PathSet & storePaths
 }
 
 
-unsigned long long Store::getClosureSize(const Path & storePath)
+std::pair<uint64_t, uint64_t> Store::getClosureSize(const Path & storePath)
 {
-    unsigned long long totalSize = 0;
+    uint64_t totalNarSize = 0, totalDownloadSize = 0;
     PathSet closure;
     computeFSClosure(storePath, closure, false, false);
-    for (auto & p : closure)
-        totalSize += queryPathInfo(p)->narSize;
-    return totalSize;
+    for (auto & p : closure) {
+        auto info = queryPathInfo(p);
+        totalNarSize += info->narSize;
+        auto narInfo = std::dynamic_pointer_cast<const NarInfo>(
+            std::shared_ptr<const ValidPathInfo>(info));
+        if (narInfo)
+            totalDownloadSize += narInfo->fileSize;
+    }
+    return {totalNarSize, totalDownloadSize};
 }
 
 
diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh
index 586d35e84ffd..3247a67678cf 100644
--- a/src/libstore/store-api.hh
+++ b/src/libstore/store-api.hh
@@ -495,7 +495,7 @@ public:
     /* 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
        the closure. */
-    unsigned long long getClosureSize(const Path & storePath);
+    std::pair<uint64_t, uint64_t> getClosureSize(const Path & storePath);
 
     /* Optimise the disk space usage of the Nix store by hard-linking files
        with the same contents. */
diff --git a/src/nix/path-info.cc b/src/nix/path-info.cc
index f7610ab0814d..ca02a4c929be 100644
--- a/src/nix/path-info.cc
+++ b/src/nix/path-info.cc
@@ -84,7 +84,7 @@ struct CmdPathInfo : StorePathsCommand, MixJSON
                     std::cout << '\t' << std::setw(11) << info->narSize;
 
                 if (showClosureSize)
-                    std::cout << '\t' << std::setw(11) << store->getClosureSize(storePath);
+                    std::cout << '\t' << std::setw(11) << store->getClosureSize(storePath).first;
 
                 if (showSigs) {
                     std::cout << '\t';