From ef337f7089e484929be92114dac5455d00cebb45 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 26 Apr 2010 12:58:12 +0000 Subject: --- src/nix-store/help.txt | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/nix-store/help.txt') diff --git a/src/nix-store/help.txt b/src/nix-store/help.txt index 7576e3ef5d42..8022bf7c7120 100644 --- a/src/nix-store/help.txt +++ b/src/nix-store/help.txt @@ -27,6 +27,9 @@ Operations: --verify: verify Nix structures --optimise: optimise the Nix store by hard-linking identical files + --query-failed-paths: list paths that failed to build (if enabled) + --clear-failed-paths: clear the failed status of the given paths + --version: output version information --help: display help -- cgit 1.4.1 From e60c962fb8dd3d8be37c1f4ae08d5247901fa129 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 17 Nov 2010 12:40:52 +0000 Subject: * Add an operation `nix-store -q --size'. --- doc/manual/nix-store.xml | 19 ++++++++++++++++--- src/libstore/local-store.cc | 14 ++++++++++++-- src/libstore/local-store.hh | 1 + src/nix-store/help.txt | 3 ++- src/nix-store/nix-store.cc | 13 +++++++++---- 5 files changed, 40 insertions(+), 10 deletions(-) (limited to 'src/nix-store/help.txt') diff --git a/doc/manual/nix-store.xml b/doc/manual/nix-store.xml index 10bb3eda5774..a32559c033f4 100644 --- a/doc/manual/nix-store.xml +++ b/doc/manual/nix-store.xml @@ -404,6 +404,7 @@ error: cannot delete path `/nix/store/zq0h41l75vlb4z45kzgjjmsjxvcv1qk7-mesa-6.4' name + @@ -587,9 +588,21 @@ query is applied to the target of the symlink. Prints the SHA-256 hash of the contents of the - store paths paths. Since the hash is - stored in the Nix database, this is a fast - operation. + store paths paths (that is, the hash of + the output of nix-store --dump on the given + paths). Since the hash is stored in the Nix database, this is a + fast operation. + + + + + + Prints the size in bytes of the contents of the + store paths paths — to be precise, the + size of the output of nix-store --dump 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. diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 9595561bcb61..201e4bae124a 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -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() { if (sqlite3_bind_null(stmt, curArg++) != SQLITE_OK) @@ -340,7 +347,7 @@ void LocalStore::openDB(bool create) stmtAddReference.create(db, "insert or replace into Refs (referrer, reference) values (?, ?);"); 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, "select path from Refs join ValidPaths on reference = id where referrer = ?;"); stmtQueryReferrers.create(db, @@ -449,7 +456,7 @@ unsigned long long LocalStore::addValidPath(const ValidPathInfo & info) else stmtRegisterValidPath.bind(); // null if (info.narSize != 0) - stmtRegisterValidPath.bind(info.narSize); + stmtRegisterValidPath.bind64(info.narSize); else stmtRegisterValidPath.bind(); // null if (sqlite3_step(stmtRegisterValidPath) != SQLITE_DONE) @@ -600,6 +607,9 @@ ValidPathInfo LocalStore::queryPathInfo(const Path & path) s = (const char *) sqlite3_column_text(stmtQueryPathInfo, 3); if (s) info.deriver = s; + /* Note that narSize = NULL yields 0. */ + info.narSize = sqlite3_column_int64(stmtQueryPathInfo, 4); + /* Get the references. */ SQLiteStmtUse use2(stmtQueryReferences); diff --git a/src/libstore/local-store.hh b/src/libstore/local-store.hh index 2fd31c26d561..4076e595748a 100644 --- a/src/libstore/local-store.hh +++ b/src/libstore/local-store.hh @@ -70,6 +70,7 @@ struct SQLiteStmt operator sqlite3_stmt * () { return stmt; } void bind(const string & value); void bind(int value); + void bind64(long long value); void bind(); }; diff --git a/src/nix-store/help.txt b/src/nix-store/help.txt index 342281b338c4..4782518517dd 100644 --- a/src/nix-store/help.txt +++ b/src/nix-store/help.txt @@ -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): diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc index 120f6ce72912..49a705585ebf 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; -- cgit 1.4.1