mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-26 15:56:18 +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
|
@ -404,6 +404,7 @@ error: cannot delete path `/nix/store/zq0h41l75vlb4z45kzgjjmsjxvcv1qk7-mesa-6.4'
|
||||||
<arg choice='plain'><option>--tree</option></arg>
|
<arg choice='plain'><option>--tree</option></arg>
|
||||||
<arg choice='plain'><option>--binding</option> <replaceable>name</replaceable></arg>
|
<arg choice='plain'><option>--binding</option> <replaceable>name</replaceable></arg>
|
||||||
<arg choice='plain'><option>--hash</option></arg>
|
<arg choice='plain'><option>--hash</option></arg>
|
||||||
|
<arg choice='plain'><option>--size</option></arg>
|
||||||
<arg choice='plain'><option>--roots</option></arg>
|
<arg choice='plain'><option>--roots</option></arg>
|
||||||
</group>
|
</group>
|
||||||
<arg><option>--use-output</option></arg>
|
<arg><option>--use-output</option></arg>
|
||||||
|
@ -587,9 +588,21 @@ query is applied to the target of the symlink.</para>
|
||||||
<varlistentry><term><option>--hash</option></term>
|
<varlistentry><term><option>--hash</option></term>
|
||||||
|
|
||||||
<listitem><para>Prints the SHA-256 hash of the contents of the
|
<listitem><para>Prints the SHA-256 hash of the contents of the
|
||||||
store paths <replaceable>paths</replaceable>. Since the hash is
|
store paths <replaceable>paths</replaceable> (that is, the hash of
|
||||||
stored in the Nix database, this is a fast
|
the output of <command>nix-store --dump</command> on the given
|
||||||
operation.</para></listitem>
|
paths). Since the hash is stored in the Nix database, this is a
|
||||||
|
fast operation.</para></listitem>
|
||||||
|
|
||||||
|
</varlistentry>
|
||||||
|
|
||||||
|
<varlistentry><term><option>--size</option></term>
|
||||||
|
|
||||||
|
<listitem><para>Prints the size in bytes of the contents of the
|
||||||
|
store paths <replaceable>paths</replaceable> — to be precise, the
|
||||||
|
size of the output of <command>nix-store --dump</command> on the
|
||||||
|
given paths. Note that the actual disk space required by the
|
||||||
|
store paths may be higher, especially on filesystems with large
|
||||||
|
cluster sizes.</para></listitem>
|
||||||
|
|
||||||
</varlistentry>
|
</varlistentry>
|
||||||
|
|
||||||
|
|
|
@ -88,6 +88,13 @@ void SQLiteStmt::bind(int value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SQLiteStmt::bind64(long long value)
|
||||||
|
{
|
||||||
|
if (sqlite3_bind_int64(stmt, curArg++, value) != SQLITE_OK)
|
||||||
|
throw SQLiteError(db, "binding argument");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void SQLiteStmt::bind()
|
void SQLiteStmt::bind()
|
||||||
{
|
{
|
||||||
if (sqlite3_bind_null(stmt, curArg++) != SQLITE_OK)
|
if (sqlite3_bind_null(stmt, curArg++) != SQLITE_OK)
|
||||||
|
@ -340,7 +347,7 @@ void LocalStore::openDB(bool create)
|
||||||
stmtAddReference.create(db,
|
stmtAddReference.create(db,
|
||||||
"insert or replace into Refs (referrer, reference) values (?, ?);");
|
"insert or replace into Refs (referrer, reference) values (?, ?);");
|
||||||
stmtQueryPathInfo.create(db,
|
stmtQueryPathInfo.create(db,
|
||||||
"select id, hash, registrationTime, deriver from ValidPaths where path = ?;");
|
"select id, hash, registrationTime, deriver, narSize from ValidPaths where path = ?;");
|
||||||
stmtQueryReferences.create(db,
|
stmtQueryReferences.create(db,
|
||||||
"select path from Refs join ValidPaths on reference = id where referrer = ?;");
|
"select path from Refs join ValidPaths on reference = id where referrer = ?;");
|
||||||
stmtQueryReferrers.create(db,
|
stmtQueryReferrers.create(db,
|
||||||
|
@ -449,7 +456,7 @@ unsigned long long LocalStore::addValidPath(const ValidPathInfo & info)
|
||||||
else
|
else
|
||||||
stmtRegisterValidPath.bind(); // null
|
stmtRegisterValidPath.bind(); // null
|
||||||
if (info.narSize != 0)
|
if (info.narSize != 0)
|
||||||
stmtRegisterValidPath.bind(info.narSize);
|
stmtRegisterValidPath.bind64(info.narSize);
|
||||||
else
|
else
|
||||||
stmtRegisterValidPath.bind(); // null
|
stmtRegisterValidPath.bind(); // null
|
||||||
if (sqlite3_step(stmtRegisterValidPath) != SQLITE_DONE)
|
if (sqlite3_step(stmtRegisterValidPath) != SQLITE_DONE)
|
||||||
|
@ -600,6 +607,9 @@ ValidPathInfo LocalStore::queryPathInfo(const Path & path)
|
||||||
s = (const char *) sqlite3_column_text(stmtQueryPathInfo, 3);
|
s = (const char *) sqlite3_column_text(stmtQueryPathInfo, 3);
|
||||||
if (s) info.deriver = s;
|
if (s) info.deriver = s;
|
||||||
|
|
||||||
|
/* Note that narSize = NULL yields 0. */
|
||||||
|
info.narSize = sqlite3_column_int64(stmtQueryPathInfo, 4);
|
||||||
|
|
||||||
/* Get the references. */
|
/* Get the references. */
|
||||||
SQLiteStmtUse use2(stmtQueryReferences);
|
SQLiteStmtUse use2(stmtQueryReferences);
|
||||||
|
|
||||||
|
|
|
@ -70,6 +70,7 @@ struct SQLiteStmt
|
||||||
operator sqlite3_stmt * () { return stmt; }
|
operator sqlite3_stmt * () { return stmt; }
|
||||||
void bind(const string & value);
|
void bind(const string & value);
|
||||||
void bind(int value);
|
void bind(int value);
|
||||||
|
void bind64(long long value);
|
||||||
void bind();
|
void bind();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ Operations:
|
||||||
|
|
||||||
--gc: run the garbage collector
|
--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
|
--restore: restore a path from a Nix archive, without
|
||||||
registering validity
|
registering validity
|
||||||
|
|
||||||
|
@ -44,6 +44,7 @@ Query flags:
|
||||||
--graph: print a dot graph rooted at given path
|
--graph: print a dot graph rooted at given path
|
||||||
--xml: emit an XML representation of the graph rooted at the 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
|
--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
|
--roots: print the garbage collector roots that point to the path
|
||||||
|
|
||||||
Query switches (not applicable to all queries):
|
Query switches (not applicable to all queries):
|
||||||
|
|
|
@ -226,7 +226,7 @@ static void printTree(const Path & path,
|
||||||
static void opQuery(Strings opFlags, Strings opArgs)
|
static void opQuery(Strings opFlags, Strings opArgs)
|
||||||
{
|
{
|
||||||
enum { qOutputs, qRequisites, qReferences, qReferrers
|
enum { qOutputs, qRequisites, qReferences, qReferrers
|
||||||
, qReferrersClosure, qDeriver, qBinding, qHash
|
, qReferrersClosure, qDeriver, qBinding, qHash, qSize
|
||||||
, qTree, qGraph, qXml, qResolve, qRoots } query = qOutputs;
|
, qTree, qGraph, qXml, qResolve, qRoots } query = qOutputs;
|
||||||
bool useOutput = false;
|
bool useOutput = false;
|
||||||
bool includeOutputs = false;
|
bool includeOutputs = false;
|
||||||
|
@ -248,6 +248,7 @@ static void opQuery(Strings opFlags, Strings opArgs)
|
||||||
query = qBinding;
|
query = qBinding;
|
||||||
}
|
}
|
||||||
else if (*i == "--hash") query = qHash;
|
else if (*i == "--hash") query = qHash;
|
||||||
|
else if (*i == "--size") query = qSize;
|
||||||
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 == "--xml") query = qXml;
|
else if (*i == "--xml") query = qXml;
|
||||||
|
@ -310,11 +311,15 @@ static void opQuery(Strings opFlags, Strings opArgs)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case qHash:
|
case qHash:
|
||||||
|
case qSize:
|
||||||
foreach (Strings::iterator, i, opArgs) {
|
foreach (Strings::iterator, i, opArgs) {
|
||||||
Path path = maybeUseOutput(followLinksToStorePath(*i), useOutput, forceRealise);
|
Path path = maybeUseOutput(followLinksToStorePath(*i), useOutput, forceRealise);
|
||||||
Hash hash = store->queryPathHash(path);
|
ValidPathInfo info = store->queryPathInfo(path);
|
||||||
assert(hash.type == htSHA256);
|
if (query == qHash) {
|
||||||
cout << format("sha256:%1%\n") % printHash32(hash);
|
assert(info.hash.type == htSHA256);
|
||||||
|
cout << format("sha256:%1%\n") % printHash32(info.hash);
|
||||||
|
} else if (query == qSize)
|
||||||
|
cout << format("%1%\n") % info.narSize;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue