2016-04-21 12:59:50 +00:00
|
|
|
#include "command.hh"
|
|
|
|
#include "shared.hh"
|
|
|
|
#include "store-api.hh"
|
2017-04-24 12:21:36 +00:00
|
|
|
#include "common-args.hh"
|
2016-08-26 16:55:55 +00:00
|
|
|
|
2016-04-21 15:53:47 +00:00
|
|
|
#include <algorithm>
|
2018-08-31 17:20:08 +00:00
|
|
|
#include <array>
|
2016-04-21 12:59:50 +00:00
|
|
|
|
2022-11-16 15:49:49 +00:00
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
|
2016-04-21 12:59:50 +00:00
|
|
|
using namespace nix;
|
|
|
|
|
2017-04-24 12:21:36 +00:00
|
|
|
struct CmdPathInfo : StorePathsCommand, MixJSON
|
2016-04-21 12:59:50 +00:00
|
|
|
{
|
|
|
|
bool showSize = false;
|
|
|
|
bool showClosureSize = false;
|
2018-08-25 22:35:15 +00:00
|
|
|
bool humanReadable = false;
|
2016-04-22 12:39:37 +00:00
|
|
|
bool showSigs = false;
|
2016-04-21 12:59:50 +00:00
|
|
|
|
|
|
|
CmdPathInfo()
|
|
|
|
{
|
2021-01-27 11:06:03 +00:00
|
|
|
addFlag({
|
|
|
|
.longName = "size",
|
|
|
|
.shortName = 's',
|
|
|
|
.description = "Print the size of the NAR serialisation of each path.",
|
|
|
|
.handler = {&showSize, true},
|
|
|
|
});
|
|
|
|
|
|
|
|
addFlag({
|
|
|
|
.longName = "closure-size",
|
|
|
|
.shortName = 'S',
|
|
|
|
.description = "Print the sum of the sizes of the NAR serialisations of the closure of each path.",
|
|
|
|
.handler = {&showClosureSize, true},
|
|
|
|
});
|
|
|
|
|
|
|
|
addFlag({
|
|
|
|
.longName = "human-readable",
|
|
|
|
.shortName = 'h',
|
|
|
|
.description = "With `-s` and `-S`, print sizes in a human-friendly format such as `5.67G`.",
|
|
|
|
.handler = {&humanReadable, true},
|
|
|
|
});
|
|
|
|
|
|
|
|
addFlag({
|
|
|
|
.longName = "sigs",
|
|
|
|
.description = "Show signatures.",
|
|
|
|
.handler = {&showSigs, true},
|
|
|
|
});
|
2016-04-21 12:59:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string description() override
|
|
|
|
{
|
|
|
|
return "query information about store paths";
|
|
|
|
}
|
|
|
|
|
2020-12-10 12:45:42 +00:00
|
|
|
std::string doc() override
|
2016-04-21 12:59:50 +00:00
|
|
|
{
|
2020-12-10 12:45:42 +00:00
|
|
|
return
|
|
|
|
#include "path-info.md"
|
|
|
|
;
|
2016-04-21 12:59:50 +00:00
|
|
|
}
|
|
|
|
|
2020-12-10 12:45:42 +00:00
|
|
|
Category category() override { return catSecondary; }
|
|
|
|
|
2020-07-30 11:10:49 +00:00
|
|
|
void printSize(uint64_t value)
|
2018-08-25 22:35:15 +00:00
|
|
|
{
|
|
|
|
if (!humanReadable) {
|
2018-08-30 14:18:53 +00:00
|
|
|
std::cout << fmt("\t%11d", value);
|
2018-08-25 22:35:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-08-31 15:30:45 +00:00
|
|
|
static const std::array<char, 9> idents{{
|
2018-08-26 22:12:06 +00:00
|
|
|
' ', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'
|
2018-08-31 15:30:45 +00:00
|
|
|
}};
|
2018-08-25 22:35:15 +00:00
|
|
|
size_t power = 0;
|
|
|
|
double res = value;
|
2018-08-26 22:12:06 +00:00
|
|
|
while (res > 1024 && power < idents.size()) {
|
2018-08-25 22:35:15 +00:00
|
|
|
++power;
|
|
|
|
res /= 1024;
|
|
|
|
}
|
2018-08-30 14:18:53 +00:00
|
|
|
std::cout << fmt("\t%6.1f%c", res, idents.at(power));
|
2018-08-25 22:35:15 +00:00
|
|
|
}
|
|
|
|
|
2021-09-27 08:53:09 +00:00
|
|
|
void run(ref<Store> store, StorePaths && storePaths) override
|
2016-04-21 12:59:50 +00:00
|
|
|
{
|
|
|
|
size_t pathLen = 0;
|
|
|
|
for (auto & storePath : storePaths)
|
2019-12-05 18:11:09 +00:00
|
|
|
pathLen = std::max(pathLen, store->printStorePath(storePath).size());
|
2016-04-21 12:59:50 +00:00
|
|
|
|
2016-08-26 16:55:55 +00:00
|
|
|
if (json) {
|
2022-11-16 15:49:49 +00:00
|
|
|
std::cout << store->pathInfoToJSON(
|
exportReferencesGraph: Export more complete info in JSON format
This writes info about every path in the closure in the same format as
‘nix path-info --json’. Thus it also includes NAR hashes and sizes.
Example:
[
{
"path": "/nix/store/10h6li26i7g6z3mdpvra09yyf10mmzdr-hello-2.10",
"narHash": "sha256:0ckdc4z20kkmpqdilx0wl6cricxv90lh85xpv2qljppcmz6vzcxl",
"narSize": 197648,
"references": [
"/nix/store/10h6li26i7g6z3mdpvra09yyf10mmzdr-hello-2.10",
"/nix/store/27binbdy296qvjycdgr1535v8872vz3z-glibc-2.24"
],
"closureSize": 20939776
},
{
"path": "/nix/store/27binbdy296qvjycdgr1535v8872vz3z-glibc-2.24",
"narHash": "sha256:1nfn3m3p98y1c0kd0brp80dn9n5mycwgrk183j17rajya0h7gax3",
"narSize": 20742128,
"references": [
"/nix/store/27binbdy296qvjycdgr1535v8872vz3z-glibc-2.24"
],
"closureSize": 20742128
}
]
Fixes #1134.
2017-01-26 19:36:20 +00:00
|
|
|
// FIXME: preserve order?
|
2020-06-16 20:20:18 +00:00
|
|
|
StorePathSet(storePaths.begin(), storePaths.end()),
|
2022-11-16 15:49:49 +00:00
|
|
|
true, showClosureSize, SRI, AllowInvalid).dump();
|
2016-08-26 16:55:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
|
2019-12-05 18:11:09 +00:00
|
|
|
for (auto & storePath : storePaths) {
|
2016-08-26 16:55:55 +00:00
|
|
|
auto info = store->queryPathInfo(storePath);
|
2022-02-18 22:43:33 +00:00
|
|
|
auto storePathS = store->printStorePath(info->path);
|
2016-04-21 12:59:50 +00:00
|
|
|
|
2019-12-05 18:11:09 +00:00
|
|
|
std::cout << storePathS;
|
2018-08-31 22:04:57 +00:00
|
|
|
|
|
|
|
if (showSize || showClosureSize || showSigs)
|
2019-12-05 18:11:09 +00:00
|
|
|
std::cout << std::string(std::max(0, (int) pathLen - (int) storePathS.size()), ' ');
|
2016-08-26 16:55:55 +00:00
|
|
|
|
|
|
|
if (showSize)
|
2018-08-25 22:35:15 +00:00
|
|
|
printSize(info->narSize);
|
2016-08-26 16:55:55 +00:00
|
|
|
|
|
|
|
if (showClosureSize)
|
2019-12-05 18:11:09 +00:00
|
|
|
printSize(store->getClosureSize(info->path).first);
|
2016-08-26 16:55:55 +00:00
|
|
|
|
|
|
|
if (showSigs) {
|
|
|
|
std::cout << '\t';
|
|
|
|
Strings ss;
|
|
|
|
if (info->ultimate) ss.push_back("ultimate");
|
2020-06-02 00:37:43 +00:00
|
|
|
if (info->ca) ss.push_back("ca:" + renderContentAddress(*info->ca));
|
2016-08-26 16:55:55 +00:00
|
|
|
for (auto & sig : info->sigs) ss.push_back(sig);
|
|
|
|
std::cout << concatStringsSep(" ", ss);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cout << std::endl;
|
2016-04-22 12:39:37 +00:00
|
|
|
}
|
|
|
|
|
2016-04-21 12:59:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-10-06 11:36:55 +00:00
|
|
|
static auto rCmdPathInfo = registerCommand<CmdPathInfo>("path-info");
|