aboutsummaryrefslogtreecommitdiff
path: root/src/nix-store/nix-store.cc
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2010-11-17 12:40:52 +0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2010-11-17 12:40:52 +0000
commite60c962fb8dd3d8be37c1f4ae08d5247901fa129 (patch)
treec8ac16743478164312460f897901d1731930dbd1 /src/nix-store/nix-store.cc
parent1db6259076b1b8f667451da8d2e44a55ece19056 (diff)
* Add an operation `nix-store -q --size'.
Diffstat (limited to 'src/nix-store/nix-store.cc')
-rw-r--r--src/nix-store/nix-store.cc13
1 files changed, 9 insertions, 4 deletions
diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc
index 120f6ce72..49a705585 100644
--- a/src/nix-store/nix-store.cc
+++ b/src/nix-store/nix-store.cc
@@ -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;