mirror of
https://github.com/NixOS/nix
synced 2025-07-04 19:41:48 +02:00
* Add an operation `nix-store -q --size'.
This commit is contained in:
parent
1db6259076
commit
e60c962fb8
5 changed files with 40 additions and 10 deletions
|
@ -16,7 +16,7 @@ Operations:
|
|||
|
||||
--gc: run the garbage collector
|
||||
|
||||
--dump: dump a path as a Nix archive, forgetting dependencies
|
||||
--dump: dump a path as a Nix archive (NAR), forgetting dependencies
|
||||
--restore: restore a path from a Nix archive, without
|
||||
registering validity
|
||||
|
||||
|
@ -44,6 +44,7 @@ Query flags:
|
|||
--graph: print a dot graph rooted at given path
|
||||
--xml: emit an XML representation of the graph rooted at the given path
|
||||
--hash: print the SHA-256 hash of the contents of the path
|
||||
--size: print the size of the NAR dump of the path
|
||||
--roots: print the garbage collector roots that point to the path
|
||||
|
||||
Query switches (not applicable to all queries):
|
||||
|
|
|
@ -226,7 +226,7 @@ static void printTree(const Path & path,
|
|||
static void opQuery(Strings opFlags, Strings opArgs)
|
||||
{
|
||||
enum { qOutputs, qRequisites, qReferences, qReferrers
|
||||
, qReferrersClosure, qDeriver, qBinding, qHash
|
||||
, qReferrersClosure, qDeriver, qBinding, qHash, qSize
|
||||
, qTree, qGraph, qXml, qResolve, qRoots } query = qOutputs;
|
||||
bool useOutput = false;
|
||||
bool includeOutputs = false;
|
||||
|
@ -248,6 +248,7 @@ static void opQuery(Strings opFlags, Strings opArgs)
|
|||
query = qBinding;
|
||||
}
|
||||
else if (*i == "--hash") query = qHash;
|
||||
else if (*i == "--size") query = qSize;
|
||||
else if (*i == "--tree") query = qTree;
|
||||
else if (*i == "--graph") query = qGraph;
|
||||
else if (*i == "--xml") query = qXml;
|
||||
|
@ -310,11 +311,15 @@ static void opQuery(Strings opFlags, Strings opArgs)
|
|||
break;
|
||||
|
||||
case qHash:
|
||||
case qSize:
|
||||
foreach (Strings::iterator, i, opArgs) {
|
||||
Path path = maybeUseOutput(followLinksToStorePath(*i), useOutput, forceRealise);
|
||||
Hash hash = store->queryPathHash(path);
|
||||
assert(hash.type == htSHA256);
|
||||
cout << format("sha256:%1%\n") % printHash32(hash);
|
||||
ValidPathInfo info = store->queryPathInfo(path);
|
||||
if (query == qHash) {
|
||||
assert(info.hash.type == htSHA256);
|
||||
cout << format("sha256:%1%\n") % printHash32(info.hash);
|
||||
} else if (query == qSize)
|
||||
cout << format("%1%\n") % info.narSize;
|
||||
}
|
||||
break;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue