* nix-store: `--isvalid' -> `--check-validity', `--validpath' ->

`--register-validity'.
* `nix-store --register-validity': read arguments from stdin, and
  allow the references and deriver to be set.
This commit is contained in:
Eelco Dolstra 2005-03-23 11:25:20 +00:00
parent a1e00bf6aa
commit f20f081560
4 changed files with 34 additions and 17 deletions

View File

@ -247,7 +247,7 @@ void canonicalisePathMetaData(const Path & path)
} }
static bool isValidPathTxn(const Transaction & txn, const Path & path) bool isValidPathTxn(const Transaction & txn, const Path & path)
{ {
string s; string s;
return nixDB.queryString(txn, dbValidPaths, path, s); return nixDB.queryString(txn, dbValidPaths, path, s);

View File

@ -87,6 +87,7 @@ Path toStorePath(const Path & path);
void canonicalisePathMetaData(const Path & path); void canonicalisePathMetaData(const Path & path);
/* Checks whether a path is valid. */ /* Checks whether a path is valid. */
bool isValidPathTxn(const Transaction & txn, const Path & path);
bool isValidPath(const Path & path); bool isValidPath(const Path & path);
/* Queries the hash of a valid path. */ /* Queries the hash of a valid path. */

View File

@ -11,8 +11,8 @@ Operations:
--substitute: register a substitute expression (dangerous!) --substitute: register a substitute expression (dangerous!)
--clear-substitutes: clear all substitutes --clear-substitutes: clear all substitutes
--validpath: register path validity (dangerous!) --register-validity: register path validity (dangerous!)
--isvalid: check path validity --check-validity: check path validity
--dump: dump a path as a Nix archive --dump: dump a path as a Nix archive
--restore: restore a path from a Nix archive --restore: restore a path from a Nix archive

View File

@ -355,8 +355,7 @@ static void opQuery(Strings opFlags, Strings opArgs)
static void opSubstitute(Strings opFlags, Strings opArgs) static void opSubstitute(Strings opFlags, Strings opArgs)
{ {
if (!opFlags.empty()) throw UsageError("unknown flag"); if (!opFlags.empty()) throw UsageError("unknown flag");
if (!opArgs.empty()) if (!opArgs.empty()) throw UsageError("no arguments expected");
throw UsageError("no arguments expected");
Transaction txn; Transaction txn;
createStoreTransaction(txn); createStoreTransaction(txn);
@ -369,8 +368,7 @@ static void opSubstitute(Strings opFlags, Strings opArgs)
if (cin.eof()) break; if (cin.eof()) break;
getline(cin, sub.deriver); getline(cin, sub.deriver);
getline(cin, sub.program); getline(cin, sub.program);
string s; string s; int n;
int n;
getline(cin, s); getline(cin, s);
if (!string2Int(s, n)) throw Error("number expected"); if (!string2Int(s, n)) throw Error("number expected");
while (n--) { while (n--) {
@ -402,20 +400,38 @@ static void opClearSubstitutes(Strings opFlags, Strings opArgs)
} }
static void opValidPath(Strings opFlags, Strings opArgs) static void opRegisterValidity(Strings opFlags, Strings opArgs)
{ {
if (!opFlags.empty()) throw UsageError("unknown flag"); if (!opFlags.empty()) throw UsageError("unknown flag");
if (!opArgs.empty()) throw UsageError("no arguments expected");
Transaction txn; Transaction txn;
createStoreTransaction(txn); createStoreTransaction(txn);
for (Strings::iterator i = opArgs.begin();
i != opArgs.end(); ++i) while (1) {
registerValidPath(txn, *i, hashPath(htSHA256, *i), PathSet(), ""); Path path;
Path deriver;
PathSet references;
getline(cin, path);
if (cin.eof()) break;
getline(cin, deriver);
string s; int n;
getline(cin, s);
if (!string2Int(s, n)) throw Error("number expected");
while (n--) {
getline(cin, s);
references.insert(s);
}
if (!cin || cin.eof()) throw Error("missing input");
if (!isValidPathTxn(txn, path))
registerValidPath(txn, path, hashPath(htSHA256, path), references, deriver);
}
txn.commit(); txn.commit();
} }
static void opIsValid(Strings opFlags, Strings opArgs) static void opCheckValidity(Strings opFlags, Strings opArgs)
{ {
if (!opFlags.empty()) throw UsageError("unknown flag"); if (!opFlags.empty()) throw UsageError("unknown flag");
@ -545,10 +561,10 @@ void run(Strings args)
op = opSubstitute; op = opSubstitute;
else if (arg == "--clear-substitutes") else if (arg == "--clear-substitutes")
op = opClearSubstitutes; op = opClearSubstitutes;
else if (arg == "--validpath") else if (arg == "--register-validity")
op = opValidPath; op = opRegisterValidity;
else if (arg == "--isvalid") else if (arg == "--check-validity")
op = opIsValid; op = opCheckValidity;
else if (arg == "--gc") else if (arg == "--gc")
op = opGC; op = opGC;
else if (arg == "--dump") else if (arg == "--dump")