1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-05 12:21:48 +02:00

* A command to query the paths referenced by an fstate expression.

* Use a temporary directory for build actions.
This commit is contained in:
Eelco Dolstra 2003-07-08 13:22:08 +00:00
parent a279137327
commit 40274c1f4f
6 changed files with 198 additions and 97 deletions

View file

@ -21,9 +21,10 @@ static ArgType argType = atpUnknown;
Operations:
--install / -i: realise a Nix expression
--install / -i: realise an fstate
--delete / -d: delete paths from the Nix store
--add / -A: copy a path to the Nix store
--query / -q: query information
--dump: dump a path as a Nix archive
--restore: restore a path from a Nix archive
@ -39,6 +40,11 @@ static ArgType argType = atpUnknown;
--file / -f: by file name
--hash / -h: by hash
Query flags:
--path / -p: query the path of an fstate
--refs / -r: query paths referenced by an fstate
Options:
--verbose / -v: verbose operation
@ -54,10 +60,8 @@ static void getArgType(Strings & flags)
{
string arg = *it;
ArgType tp;
if (arg == "--hash" || arg == "-h")
tp = atpHash;
else if (arg == "--file" || arg == "-f")
tp = atpPath;
if (arg == "--hash" || arg == "-h") tp = atpHash;
else if (arg == "--file" || arg == "-f") tp = atpPath;
else { it++; continue; }
if (argType != atpUnknown)
throw UsageError("only one argument type specified may be specified");
@ -69,6 +73,20 @@ static void getArgType(Strings & flags)
}
static Hash argToHash(const string & arg)
{
if (argType == atpHash)
return parseHash(arg);
else if (argType == atpPath) {
string path;
Hash hash;
addToStore(arg, path, hash);
return hash;
}
else abort();
}
/* Realise (or install) paths from the given Nix fstate
expressions. */
static void opInstall(Strings opFlags, Strings opArgs)
@ -78,20 +96,11 @@ static void opInstall(Strings opFlags, Strings opArgs)
for (Strings::iterator it = opArgs.begin();
it != opArgs.end(); it++)
{
Hash hash;
if (argType == atpHash)
hash = parseHash(*it);
else if (argType == atpPath) {
string path;
addToStore(*it, path, hash);
}
FState fs = ATmake("Include(<str>)", ((string) hash).c_str());
realiseFState(fs);
}
realiseFState(termFromHash(argToHash(*it)));
}
/* Delete a path in the Nix store directory. */
static void opDelete(Strings opFlags, Strings opArgs)
{
if (!opFlags.empty()) throw UsageError("unknown flag");
@ -120,6 +129,51 @@ static void opAdd(Strings opFlags, Strings opArgs)
}
/* Perform various sorts of queries. */
static void opQuery(Strings opFlags, Strings opArgs)
{
enum { qPath, qRefs, qUnknown } query = qPath;
for (Strings::iterator it = opFlags.begin();
it != opFlags.end(); )
{
string arg = *it;
if (arg == "--path" || arg == "-p") query = qPath;
else if (arg == "--refs" || arg == "-r") query = qRefs;
else { it++; continue; }
it = opFlags.erase(it);
}
getArgType(opFlags);
if (!opFlags.empty()) throw UsageError("unknown flag");
for (Strings::iterator it = opArgs.begin();
it != opArgs.end(); it++)
{
Hash hash = argToHash(*it);
switch (query) {
case qPath:
cout << format("%s\n") %
(string) fstatePath(termFromHash(hash));
break;
case qRefs: {
Strings refs = fstateRefs(termFromHash(hash));
for (Strings::iterator j = refs.begin();
j != refs.end(); j++)
cout << format("%s\n") % *j;
break;
}
default:
abort();
}
}
}
/* A sink that writes dump output to stdout. */
struct StdoutSink : DumpSink
{
@ -208,8 +262,10 @@ void run(Strings args)
op = opInstall;
else if (arg == "--delete" || arg == "-d")
op = opDelete;
else if (arg == "--add")
else if (arg == "--add" || arg == "-A")
op = opAdd;
else if (arg == "--query" || arg == "-q")
op = opQuery;
else if (arg == "--dump")
op = opDump;
else if (arg == "--restore")