* `nix-store -q --hash' to quickly query the hash of the contents of a
store path (which is stored in the database).
This commit is contained in:
parent
9e50e648a4
commit
07b4399fb6
|
@ -509,6 +509,14 @@ static Hash queryHash(const Transaction & txn, const Path & storePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Hash queryPathHash(const Path & path)
|
||||||
|
{
|
||||||
|
if (!isValidPath(path))
|
||||||
|
throw Error(format("path `%1%' is not valid") % path);
|
||||||
|
return queryHash(noTxn, path);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void registerValidPath(const Transaction & txn,
|
void registerValidPath(const Transaction & txn,
|
||||||
const Path & _path, const Hash & hash, const PathSet & references,
|
const Path & _path, const Hash & hash, const PathSet & references,
|
||||||
const Path & deriver)
|
const Path & deriver)
|
||||||
|
|
|
@ -89,6 +89,9 @@ void canonicalisePathMetaData(const Path & path);
|
||||||
/* Checks whether a path is valid. */
|
/* Checks whether a path is valid. */
|
||||||
bool isValidPath(const Path & path);
|
bool isValidPath(const Path & path);
|
||||||
|
|
||||||
|
/* Queries the hash of a valid path. */
|
||||||
|
Hash queryPathHash(const Path & path);
|
||||||
|
|
||||||
/* Sets the set of outgoing FS references for a store path. Use with
|
/* Sets the set of outgoing FS references for a store path. Use with
|
||||||
care! */
|
care! */
|
||||||
void setReferences(const Transaction & txn, const Path & storePath,
|
void setReferences(const Transaction & txn, const Path & storePath,
|
||||||
|
|
|
@ -228,8 +228,9 @@ static void printDrvTree(const Path & drvPath,
|
||||||
/* Perform various sorts of queries. */
|
/* Perform various sorts of queries. */
|
||||||
static void opQuery(Strings opFlags, Strings opArgs)
|
static void opQuery(Strings opFlags, Strings opArgs)
|
||||||
{
|
{
|
||||||
enum { qOutputs, qRequisites, qReferences, qReferers,
|
enum { qOutputs, qRequisites, qReferences, qReferers
|
||||||
qReferersClosure, qDeriver, qBinding, qTree, qGraph } query = qOutputs;
|
, qReferersClosure, qDeriver, qBinding, qHash
|
||||||
|
, qTree, qGraph } query = qOutputs;
|
||||||
bool useOutput = false;
|
bool useOutput = false;
|
||||||
bool includeOutputs = false;
|
bool includeOutputs = false;
|
||||||
bool forceRealise = false;
|
bool forceRealise = false;
|
||||||
|
@ -250,6 +251,7 @@ static void opQuery(Strings opFlags, Strings opArgs)
|
||||||
opArgs.pop_front();
|
opArgs.pop_front();
|
||||||
query = qBinding;
|
query = qBinding;
|
||||||
}
|
}
|
||||||
|
else if (*i == "--hash") query = qHash;
|
||||||
else if (*i == "--tree") query = qTree;
|
else if (*i == "--tree") query = qTree;
|
||||||
else if (*i == "--graph") query = qGraph;
|
else if (*i == "--graph") query = qGraph;
|
||||||
else if (*i == "--use-output" || *i == "-u") useOutput = true;
|
else if (*i == "--use-output" || *i == "-u") useOutput = true;
|
||||||
|
@ -279,8 +281,7 @@ static void opQuery(Strings opFlags, Strings opArgs)
|
||||||
for (Strings::iterator i = opArgs.begin();
|
for (Strings::iterator i = opArgs.begin();
|
||||||
i != opArgs.end(); i++)
|
i != opArgs.end(); i++)
|
||||||
{
|
{
|
||||||
*i = fixPath(*i);
|
Path path = maybeUseOutput(fixPath(*i), useOutput, forceRealise);
|
||||||
Path path = maybeUseOutput(*i, useOutput, forceRealise);
|
|
||||||
if (query == qRequisites)
|
if (query == qRequisites)
|
||||||
storePathRequisites(path, includeOutputs, paths);
|
storePathRequisites(path, includeOutputs, paths);
|
||||||
else if (query == qReferences) queryReferences(noTxn, path, paths);
|
else if (query == qReferences) queryReferences(noTxn, path, paths);
|
||||||
|
@ -295,8 +296,7 @@ static void opQuery(Strings opFlags, Strings opArgs)
|
||||||
for (Strings::iterator i = opArgs.begin();
|
for (Strings::iterator i = opArgs.begin();
|
||||||
i != opArgs.end(); i++)
|
i != opArgs.end(); i++)
|
||||||
{
|
{
|
||||||
*i = fixPath(*i);
|
Path deriver = queryDeriver(noTxn, fixPath(*i));
|
||||||
Path deriver = queryDeriver(noTxn, *i);
|
|
||||||
cout << format("%1%\n") %
|
cout << format("%1%\n") %
|
||||||
(deriver == "" ? "unknown-deriver" : deriver);
|
(deriver == "" ? "unknown-deriver" : deriver);
|
||||||
}
|
}
|
||||||
|
@ -316,6 +316,17 @@ static void opQuery(Strings opFlags, Strings opArgs)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case qHash:
|
||||||
|
for (Strings::iterator i = opArgs.begin();
|
||||||
|
i != opArgs.end(); i++)
|
||||||
|
{
|
||||||
|
Path path = maybeUseOutput(fixPath(*i), useOutput, forceRealise);
|
||||||
|
Hash hash = queryPathHash(path);
|
||||||
|
assert(hash.type == htSHA256);
|
||||||
|
cout << format("sha256:%1%\n") % printHash32(hash);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case qTree: {
|
case qTree: {
|
||||||
PathSet done;
|
PathSet done;
|
||||||
for (Strings::iterator i = opArgs.begin();
|
for (Strings::iterator i = opArgs.begin();
|
||||||
|
|
Loading…
Reference in a new issue