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 } ]
This commit is contained in:
		
							parent
							
								
									fdc9da034f
								
							
						
					
					
						commit
						766ad5db3b
					
				
					 3 changed files with 30 additions and 9 deletions
				
			
		|  | @ -480,8 +480,12 @@ void Store::pathInfoToJSON(JSONPlaceholder & jsonOut, const PathSet & storePaths | ||||||
|             if (info->ca != "") |             if (info->ca != "") | ||||||
|                 jsonPath.attr("ca", info->ca); |                 jsonPath.attr("ca", info->ca); | ||||||
| 
 | 
 | ||||||
|             if (showClosureSize) |             std::pair<uint64_t, uint64_t> closureSizes; | ||||||
|                 jsonPath.attr("closureSize", getClosureSize(storePath)); | 
 | ||||||
|  |             if (showClosureSize) { | ||||||
|  |                 closureSizes = getClosureSize(storePath); | ||||||
|  |                 jsonPath.attr("closureSize", closureSizes.first); | ||||||
|  |             } | ||||||
| 
 | 
 | ||||||
|             if (includeImpureInfo) { |             if (includeImpureInfo) { | ||||||
| 
 | 
 | ||||||
|  | @ -500,6 +504,17 @@ void Store::pathInfoToJSON(JSONPlaceholder & jsonOut, const PathSet & storePaths | ||||||
|                         jsonSigs.elem(sig); |                         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 &) { |         } 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; |     PathSet closure; | ||||||
|     computeFSClosure(storePath, closure, false, false); |     computeFSClosure(storePath, closure, false, false); | ||||||
|     for (auto & p : closure) |     for (auto & p : closure) { | ||||||
|         totalSize += queryPathInfo(p)->narSize; |         auto info = queryPathInfo(p); | ||||||
|     return totalSize; |         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}; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -495,7 +495,7 @@ public: | ||||||
|     /* Return the size of the closure of the specified path, that is,
 |     /* 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 sum of the size of the NAR serialisation of each path in | ||||||
|        the closure. */ |        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
 |     /* Optimise the disk space usage of the Nix store by hard-linking files
 | ||||||
|        with the same contents. */ |        with the same contents. */ | ||||||
|  |  | ||||||
|  | @ -84,7 +84,7 @@ struct CmdPathInfo : StorePathsCommand, MixJSON | ||||||
|                     std::cout << '\t' << std::setw(11) << info->narSize; |                     std::cout << '\t' << std::setw(11) << info->narSize; | ||||||
| 
 | 
 | ||||||
|                 if (showClosureSize) |                 if (showClosureSize) | ||||||
|                     std::cout << '\t' << std::setw(11) << store->getClosureSize(storePath); |                     std::cout << '\t' << std::setw(11) << store->getClosureSize(storePath).first; | ||||||
| 
 | 
 | ||||||
|                 if (showSigs) { |                 if (showSigs) { | ||||||
|                     std::cout << '\t'; |                     std::cout << '\t'; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue