aboutsummaryrefslogtreecommitdiff
path: root/src/nix-store/nix-store.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-12-05 19:11:09 +0100
committerEelco Dolstra <edolstra@gmail.com>2019-12-10 22:06:05 +0100
commitbbe97dff8b3054d96e758f486f9ce3fa09e64de3 (patch)
tree9dd575bc61ec93de4bc693f00a84fc8686a613f9 /src/nix-store/nix-store.cc
parentebd89999c28e25e71048d523f9c4f8b856dee9a9 (diff)
Make the Store API more type-safe
Most functions now take a StorePath argument rather than a Path (which is just an alias for std::string). The StorePath constructor ensures that the path is syntactically correct (i.e. it looks like <store-dir>/<base32-hash>-<name>). Similarly, functions like buildPaths() now take a StorePathWithOutputs, rather than abusing Path by adding a '!<outputs>' suffix. Note that the StorePath type is implemented in Rust. This involves some hackery to allow Rust values to be used directly in C++, via a helper type whose destructor calls the Rust type's drop() function. The main issue is the dynamic nature of C++ move semantics: after we have moved a Rust value, we should not call the drop function on the original value. So when we move a value, we set the original value to bitwise zero, and the destructor only calls drop() if the value is not bitwise zero. This should be sufficient for most types. Also lots of minor cleanups to the C++ API to make it more modern (e.g. using std::optional and std::string_view in some places).
Diffstat (limited to 'src/nix-store/nix-store.cc')
-rw-r--r--src/nix-store/nix-store.cc310
1 files changed, 157 insertions, 153 deletions
diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc
index dfa473db5..e2e2939f4 100644
--- a/src/nix-store/nix-store.cc
+++ b/src/nix-store/nix-store.cc
@@ -47,38 +47,37 @@ ref<LocalStore> ensureLocalStore()
}
-static Path useDeriver(Path path)
+static StorePath useDeriver(const StorePath & path)
{
- if (isDerivation(path)) return path;
- Path drvPath = store->queryPathInfo(path)->deriver;
- if (drvPath == "")
- throw Error(format("deriver of path '%1%' is not known") % path);
- return drvPath;
+ if (path.isDerivation()) return path.clone();
+ auto info = store->queryPathInfo(path);
+ if (!info->deriver)
+ throw Error("deriver of path '%s' is not known", store->printStorePath(path));
+ return info->deriver->clone();
}
/* Realise the given path. For a derivation that means build it; for
other paths it means ensure their validity. */
-static PathSet realisePath(Path path, bool build = true)
+static PathSet realisePath(StorePathWithOutputs path, bool build = true)
{
- DrvPathWithOutputs p = parseDrvPathWithOutputs(path);
-
auto store2 = std::dynamic_pointer_cast<LocalFSStore>(store);
- if (isDerivation(p.first)) {
+ if (path.path.isDerivation()) {
if (build) store->buildPaths({path});
- Derivation drv = store->derivationFromPath(p.first);
+ Derivation drv = store->derivationFromPath(path.path);
rootNr++;
- if (p.second.empty())
- for (auto & i : drv.outputs) p.second.insert(i.first);
+ if (path.outputs.empty())
+ for (auto & i : drv.outputs) path.outputs.insert(i.first);
PathSet outputs;
- for (auto & j : p.second) {
+ for (auto & j : path.outputs) {
DerivationOutputs::iterator i = drv.outputs.find(j);
if (i == drv.outputs.end())
- throw Error(format("derivation '%1%' does not have an output named '%2%'") % p.first % j);
- Path outPath = i->second.path;
+ throw Error("derivation '%s' does not have an output named '%s'",
+ store2->printStorePath(path.path), j);
+ auto outPath = store2->printStorePath(i->second.path);
if (store2) {
if (gcRoot == "")
printGCWarning();
@@ -86,7 +85,7 @@ static PathSet realisePath(Path path, bool build = true)
Path rootName = gcRoot;
if (rootNr > 1) rootName += "-" + std::to_string(rootNr);
if (i->first != "out") rootName += "-" + i->first;
- outPath = store2->addPermRoot(outPath, rootName, indirectRoot);
+ outPath = store2->addPermRoot(store->parseStorePath(outPath), rootName, indirectRoot);
}
}
outputs.insert(outPath);
@@ -95,8 +94,9 @@ static PathSet realisePath(Path path, bool build = true)
}
else {
- if (build) store->ensurePath(path);
- else if (!store->isValidPath(path)) throw Error(format("path '%1%' does not exist and cannot be created") % path);
+ if (build) store->ensurePath(path.path);
+ else if (!store->isValidPath(path.path))
+ throw Error("path '%s' does not exist and cannot be created", store->printStorePath(path.path));
if (store2) {
if (gcRoot == "")
printGCWarning();
@@ -104,10 +104,10 @@ static PathSet realisePath(Path path, bool build = true)
Path rootName = gcRoot;
rootNr++;
if (rootNr > 1) rootName += "-" + std::to_string(rootNr);
- path = store2->addPermRoot(path, rootName, indirectRoot);
+ return {store2->addPermRoot(path.path, rootName, indirectRoot)};
}
}
- return {path};
+ return {store->printStorePath(path.path)};
}
}
@@ -126,23 +126,20 @@ static void opRealise(Strings opFlags, Strings opArgs)
else if (i == "--ignore-unknown") ignoreUnknown = true;
else throw UsageError(format("unknown flag '%1%'") % i);
- Paths paths;
- for (auto & i : opArgs) {
- DrvPathWithOutputs p = parseDrvPathWithOutputs(i);
- paths.push_back(makeDrvPathWithOutputs(store->followLinksToStorePath(p.first), p.second));
- }
+ std::vector<StorePathWithOutputs> paths;
+ for (auto & i : opArgs)
+ paths.push_back(store->parseDrvPathWithOutputs(i));
unsigned long long downloadSize, narSize;
- PathSet willBuild, willSubstitute, unknown;
- store->queryMissing(PathSet(paths.begin(), paths.end()),
- willBuild, willSubstitute, unknown, downloadSize, narSize);
+ StorePathSet willBuild, willSubstitute, unknown;
+ store->queryMissing(paths, willBuild, willSubstitute, unknown, downloadSize, narSize);
if (ignoreUnknown) {
- Paths paths2;
+ std::vector<StorePathWithOutputs> paths2;
for (auto & i : paths)
- if (unknown.find(i) == unknown.end()) paths2.push_back(i);
- paths = paths2;
- unknown = PathSet();
+ if (!unknown.count(i.path)) paths2.push_back(i);
+ paths = std::move(paths2);
+ unknown = StorePathSet();
}
if (settings.printMissing)
@@ -151,14 +148,14 @@ static void opRealise(Strings opFlags, Strings opArgs)
if (dryRun) return;
/* Build all paths at the same time to exploit parallelism. */
- store->buildPaths(PathSet(paths.begin(), paths.end()), buildMode);
+ store->buildPaths(paths, buildMode);
if (!ignoreUnknown)
for (auto & i : paths) {
- PathSet paths = realisePath(i, false);
+ auto paths2 = realisePath(i, false);
if (!noOutput)
- for (auto & j : paths)
- cout << format("%1%\n") % j;
+ for (auto & j : paths2)
+ cout << fmt("%1%\n", j);
}
}
@@ -169,7 +166,7 @@ static void opAdd(Strings opFlags, Strings opArgs)
if (!opFlags.empty()) throw UsageError("unknown flag");
for (auto & i : opArgs)
- cout << format("%1%\n") % store->addToStore(baseNameOf(i), i);
+ cout << fmt("%s\n", store->printStorePath(store->addToStore(std::string(baseNameOf(i)), i)));
}
@@ -190,7 +187,7 @@ static void opAddFixed(Strings opFlags, Strings opArgs)
opArgs.pop_front();
for (auto & i : opArgs)
- cout << format("%1%\n") % store->addToStore(baseNameOf(i), i, recursive, hashAlgo);
+ cout << fmt("%s\n", store->printStorePath(store->addToStore(std::string(baseNameOf(i)), i, recursive, hashAlgo)));
}
@@ -211,22 +208,21 @@ static void opPrintFixedPath(Strings opFlags, Strings opArgs)
string hash = *i++;
string name = *i++;
- cout << format("%1%\n") %
- store->makeFixedOutputPath(recursive, Hash(hash, hashAlgo), name);
+ cout << fmt("%s\n", store->printStorePath(store->makeFixedOutputPath(recursive, Hash(hash, hashAlgo), name)));
}
-static PathSet maybeUseOutputs(const Path & storePath, bool useOutput, bool forceRealise)
+static StorePathSet maybeUseOutputs(const StorePath & storePath, bool useOutput, bool forceRealise)
{
if (forceRealise) realisePath(storePath);
- if (useOutput && isDerivation(storePath)) {
- Derivation drv = store->derivationFromPath(storePath);
- PathSet outputs;
+ if (useOutput && storePath.isDerivation()) {
+ auto drv = store->derivationFromPath(storePath);
+ StorePathSet outputs;
for (auto & i : drv.outputs)
- outputs.insert(i.second.path);
+ outputs.insert(i.second.path.clone());
return outputs;
}
- else return {storePath};
+ else return singleton(storePath.clone());
}
@@ -239,23 +235,23 @@ const string treeLine = "| ";
const string treeNull = " ";
-static void printTree(const Path & path,
- const string & firstPad, const string & tailPad, PathSet & done)
+static void printTree(const StorePath & path,
+ const string & firstPad, const string & tailPad, StorePathSet & done)
{
- if (!done.insert(path).second) {
- cout << format("%1%%2% [...]\n") % firstPad % path;
+ if (!done.insert(path.clone()).second) {
+ cout << fmt("%s%s [...]\n", firstPad, store->printStorePath(path));
return;
}
- cout << format("%1%%2%\n") % firstPad % path;
+ cout << fmt("%s%s\n", firstPad, store->printStorePath(path));
- auto references = store->queryPathInfo(path)->references;
+ auto info = store->queryPathInfo(path);
/* Topologically sort under the relation A < B iff A \in
closure(B). That is, if derivation A is an (possibly indirect)
input of B, then A is printed first. This has the effect of
flattening the tree, preventing deeply nested structures. */
- Paths sorted = store->topoSortPaths(references);
+ auto sorted = store->topoSortPaths(info->references);
reverse(sorted.begin(), sorted.end());
for (auto i = sorted.begin(); i != sorted.end(); ++i) {
@@ -318,11 +314,11 @@ static void opQuery(Strings opFlags, Strings opArgs)
case qOutputs: {
for (auto & i : opArgs) {
- i = store->followLinksToStorePath(i);
- if (forceRealise) realisePath(i);
- Derivation drv = store->derivationFromPath(i);
+ auto i2 = store->followLinksToStorePath(i);
+ if (forceRealise) realisePath(i2);
+ Derivation drv = store->derivationFromPath(i2);
for (auto & j : drv.outputs)
- cout << format("%1%\n") % j.second.path;
+ cout << fmt("%1%\n", store->printStorePath(j.second.path));
}
break;
}
@@ -331,51 +327,54 @@ static void opQuery(Strings opFlags, Strings opArgs)
case qReferences:
case qReferrers:
case qReferrersClosure: {
- PathSet paths;
+ StorePathSet paths;
for (auto & i : opArgs) {
- PathSet ps = maybeUseOutputs(store->followLinksToStorePath(i), useOutput, forceRealise);
+ auto ps = maybeUseOutputs(store->followLinksToStorePath(i), useOutput, forceRealise);
for (auto & j : ps) {
if (query == qRequisites) store->computeFSClosure(j, paths, false, includeOutputs);
else if (query == qReferences) {
for (auto & p : store->queryPathInfo(j)->references)
- paths.insert(p);
+ paths.insert(p.clone());
+ }
+ else if (query == qReferrers) {
+ StorePathSet tmp;
+ store->queryReferrers(j, tmp);
+ for (auto & i : tmp)
+ paths.insert(i.clone());
}
- else if (query == qReferrers) store->queryReferrers(j, paths);
else if (query == qReferrersClosure) store->computeFSClosure(j, paths, true);
}
}
- Paths sorted = store->topoSortPaths(paths);
- for (Paths::reverse_iterator i = sorted.rbegin();
+ auto sorted = store->topoSortPaths(paths);
+ for (StorePaths::reverse_iterator i = sorted.rbegin();
i != sorted.rend(); ++i)
- cout << format("%s\n") % *i;
+ cout << fmt("%s\n", store->printStorePath(*i));
break;
}
case qDeriver:
for (auto & i : opArgs) {
- Path deriver = store->queryPathInfo(store->followLinksToStorePath(i))->deriver;
- cout << format("%1%\n") %
- (deriver == "" ? "unknown-deriver" : deriver);
+ auto info = store->queryPathInfo(store->followLinksToStorePath(i));
+ cout << fmt("%s\n", info->deriver ? store->printStorePath(*info->deriver) : "unknown-deriver");
}
break;
case qBinding:
for (auto & i : opArgs) {
- Path path = useDeriver(store->followLinksToStorePath(i));
+ auto path = useDeriver(store->followLinksToStorePath(i));
Derivation drv = store->derivationFromPath(path);
StringPairs::iterator j = drv.env.find(bindingName);
if (j == drv.env.end())
- throw Error(format("derivation '%1%' has no environment binding named '%2%'")
- % path % bindingName);
- cout << format("%1%\n") % j->second;
+ throw Error("derivation '%s' has no environment binding named '%s'",
+ store->printStorePath(path), bindingName);
+ cout << fmt("%s\n", j->second);
}
break;
case qHash:
case qSize:
for (auto & i : opArgs) {
- PathSet paths = maybeUseOutputs(store->followLinksToStorePath(i), useOutput, forceRealise);
- for (auto & j : paths) {
+ for (auto & j : maybeUseOutputs(store->followLinksToStorePath(i), useOutput, forceRealise)) {
auto info = store->queryPathInfo(j);
if (query == qHash) {
assert(info->narHash.type == htSHA256);
@@ -387,50 +386,51 @@ static void opQuery(Strings opFlags, Strings opArgs)
break;
case qTree: {
- PathSet done;
+ StorePathSet done;
for (auto & i : opArgs)
printTree(store->followLinksToStorePath(i), "", "", done);
break;
}
case qGraph: {
- PathSet roots;
- for (auto & i : opArgs) {
- PathSet paths = maybeUseOutputs(store->followLinksToStorePath(i), useOutput, forceRealise);
- roots.insert(paths.begin(), paths.end());
- }
- printDotGraph(ref<Store>(store), roots);
+ StorePathSet roots;
+ for (auto & i : opArgs)
+ for (auto & j : maybeUseOutputs(store->followLinksToStorePath(i), useOutput, forceRealise))
+ roots.insert(j.clone());
+ printDotGraph(ref<Store>(store), std::move(roots));
break;
}
case qGraphML: {
- PathSet roots;
- for (auto & i : opArgs) {
- PathSet paths = maybeUseOutputs(store->followLinksToStorePath(i), useOutput, forceRealise);
- roots.insert(paths.begin(), paths.end());
- }
- printGraphML(ref<Store>(store), roots);
+ StorePathSet roots;
+ for (auto & i : opArgs)
+ for (auto & j : maybeUseOutputs(store->followLinksToStorePath(i), useOutput, forceRealise))
+ roots.insert(j.clone());
+ printGraphML(ref<Store>(store), std::move(roots));
break;
}
case qResolve: {
for (auto & i : opArgs)
- cout << format("%1%\n") % store->followLinksToStorePath(i);
+ cout << fmt("%s\n", store->printStorePath(store->followLinksToStorePath(i)));
break;
}
case qRoots: {
- PathSet referrers;
- for (auto & i : opArgs) {
- store->computeFSClosure(
- maybeUseOutputs(store->followLinksToStorePath(i), useOutput, forceRealise),
- referrers, true, settings.gcKeepOutputs, settings.gcKeepDerivations);
- }
+ StorePathSet args;
+ for (auto & i : opArgs)
+ for (auto & p : maybeUseOutputs(store->followLinksToStorePath(i), useOutput, forceRealise))
+ args.insert(p.clone());
+
+ StorePathSet referrers;
+ store->computeFSClosure(
+ args, referrers, true, settings.gcKeepOutputs, settings.gcKeepDerivations);
+
Roots roots = store->findRoots(false);
for (auto & [target, links] : roots)
if (referrers.find(target) != referrers.end())
for (auto & link : links)
- cout << format("%1% -> %2%\n") % link % target;
+ cout << fmt("%1% -> %2%\n", link, store->printStorePath(target));
break;
}
@@ -446,7 +446,7 @@ static void opPrintEnv(Strings opFlags, Strings opArgs)
if (opArgs.size() != 1) throw UsageError("'--print-env' requires one derivation store path");
Path drvPath = opArgs.front();
- Derivation drv = store->derivationFromPath(drvPath);
+ Derivation drv = store->derivationFromPath(store->parseStorePath(drvPath));
/* Print each environment variable in the derivation in a format
that can be sourced by the shell. */
@@ -476,7 +476,7 @@ static void opReadLog(Strings opFlags, Strings opArgs)
auto path = store->followLinksToStorePath(i);
auto log = store->getBuildLog(path);
if (!log)
- throw Error("build log of derivation '%s' is not available", path);
+ throw Error("build log of derivation '%s' is not available", store->printStorePath(path));
std::cout << *log;
}
}
@@ -487,13 +487,10 @@ static void opDumpDB(Strings opFlags, Strings opArgs)
if (!opFlags.empty()) throw UsageError("unknown flag");
if (!opArgs.empty()) {
for (auto & i : opArgs)
- i = store->followLinksToStorePath(i);
- for (auto & i : opArgs)
- cout << store->makeValidityRegistration({i}, true, true);
+ cout << store->makeValidityRegistration(singleton(store->followLinksToStorePath(i)), true, true);
} else {
- PathSet validPaths = store->queryAllValidPaths();
- for (auto & i : validPaths)
- cout << store->makeValidityRegistration({i}, true, true);
+ for (auto & i : store->queryAllValidPaths())
+ cout << store->makeValidityRegistration(singleton(i), true, true);
}
}
@@ -503,18 +500,18 @@ static void registerValidity(bool reregister, bool hashGiven, bool canonicalise)
ValidPathInfos infos;
while (1) {
- ValidPathInfo info = decodeValidPathInfo(cin, hashGiven);
- if (info.path == "") break;
- if (!store->isValidPath(info.path) || reregister) {
+ auto info = decodeValidPathInfo(*store, cin, hashGiven);
+ if (!info) break;
+ if (!store->isValidPath(info->path) || reregister) {
/* !!! races */
if (canonicalise)
- canonicalisePathMetaData(info.path, -1);
+ canonicalisePathMetaData(store->printStorePath(info->path), -1);
if (!hashGiven) {
- HashResult hash = hashPath(htSHA256, info.path);
- info.narHash = hash.first;
- info.narSize = hash.second;
+ HashResult hash = hashPath(htSHA256, store->printStorePath(info->path));
+ info->narHash = hash.first;
+ info->narSize = hash.second;
}
- infos.push_back(info);
+ infos.push_back(std::move(*info));
}
}
@@ -556,12 +553,12 @@ static void opCheckValidity(Strings opFlags, Strings opArgs)
else throw UsageError(format("unknown flag '%1%'") % i);
for (auto & i : opArgs) {
- Path path = store->followLinksToStorePath(i);
+ auto path = store->followLinksToStorePath(i);
if (!store->isValidPath(path)) {
if (printInvalid)
- cout << format("%1%\n") % path;
+ cout << fmt("%s\n", store->printStorePath(path));
else
- throw Error(format("path '%1%' is not valid") % path);
+ throw Error("path '%s' is not valid", store->printStorePath(path));
}
}
}
@@ -591,13 +588,13 @@ static void opGC(Strings opFlags, Strings opArgs)
if (printRoots) {
Roots roots = store->findRoots(false);
- std::set<std::pair<Path, Path>> roots2;
+ std::set<std::pair<Path, StorePath>> roots2;
// Transpose and sort the roots.
for (auto & [target, links] : roots)
for (auto & link : links)
- roots2.emplace(link, target);
+ roots2.emplace(link, target.clone());
for (auto & [link, target] : roots2)
- std::cout << link << " -> " << target << "\n";
+ std::cout << link << " -> " << store->printStorePath(target) << "\n";
}
else {
@@ -661,11 +658,13 @@ static void opExport(Strings opFlags, Strings opArgs)
for (auto & i : opFlags)
throw UsageError(format("unknown flag '%1%'") % i);
+ StorePathSet paths;
+
for (auto & i : opArgs)
- i = store->followLinksToStorePath(i);
+ paths.insert(store->followLinksToStorePath(i));
FdSink sink(STDOUT_FILENO);
- store->exportPaths(opArgs, sink);
+ store->exportPaths(paths, sink);
sink.flush();
}
@@ -678,10 +677,10 @@ static void opImport(Strings opFlags, Strings opArgs)
if (!opArgs.empty()) throw UsageError("no arguments expected");
FdSource source(STDIN_FILENO);
- Paths paths = store->importPaths(source, nullptr, NoCheckSigs);
+ auto paths = store->importPaths(source, nullptr, NoCheckSigs);
for (auto & i : paths)
- cout << format("%1%\n") % i << std::flush;
+ cout << fmt("%s\n", store->printStorePath(i)) << std::flush;
}
@@ -726,16 +725,16 @@ static void opVerifyPath(Strings opFlags, Strings opArgs)
int status = 0;
for (auto & i : opArgs) {
- Path path = store->followLinksToStorePath(i);
- printMsg(lvlTalkative, format("checking path '%1%'...") % path);
+ auto path = store->followLinksToStorePath(i);
+ printMsg(lvlTalkative, "checking path '%s'...", store->printStorePath(path));
auto info = store->queryPathInfo(path);
HashSink sink(info->narHash.type);
store->narFromPath(path, sink);
auto current = sink.finish();
if (current.first != info->narHash) {
printError(
- format("path '%1%' was modified! expected hash '%2%', got '%3%'")
- % path % info->narHash.to_string() % current.first.to_string());
+ "path '%s' was modified! expected hash '%s', got '%s'",
+ store->printStorePath(path), info->narHash.to_string(), current.first.to_string());
status = 1;
}
}
@@ -751,10 +750,8 @@ static void opRepairPath(Strings opFlags, Strings opArgs)
if (!opFlags.empty())
throw UsageError("no flags expected");
- for (auto & i : opArgs) {
- Path path = store->followLinksToStorePath(i);
- ensureLocalStore()->repairPath(path);
- }
+ for (auto & i : opArgs)
+ ensureLocalStore()->repairPath(store->followLinksToStorePath(i));
}
/* Optimise the disk space usage of the Nix store by hard-linking
@@ -818,7 +815,7 @@ static void opServe(Strings opFlags, Strings opArgs)
case cmdQueryValidPaths: {
bool lock = readInt(in);
bool substitute = readInt(in);
- PathSet paths = readStorePaths<PathSet>(*store, in);
+ auto paths = readStorePaths<StorePathSet>(*store, in);
if (lock && writeAllowed)
for (auto & path : paths)
store->addTempRoot(path);
@@ -828,34 +825,39 @@ static void opServe(Strings opFlags, Strings opArgs)
flag. */
if (substitute && writeAllowed) {
/* Filter out .drv files (we don't want to build anything). */
- PathSet paths2;
+ std::vector<StorePathWithOutputs> paths2;
for (auto & path : paths)
- if (!isDerivation(path)) paths2.insert(path);
+ if (!path.isDerivation())
+ paths2.emplace_back(path.clone());
unsigned long long downloadSize, narSize;
- PathSet willBuild, willSubstitute, unknown;
- store->queryMissing(PathSet(paths2.begin(), paths2.end()),
+ StorePathSet willBuild, willSubstitute, unknown;
+ store->queryMissing(paths2,
willBuild, willSubstitute, unknown, downloadSize, narSize);
/* FIXME: should use ensurePath(), but it only
does one path at a time. */
if (!willSubstitute.empty())
try {
- store->buildPaths(willSubstitute);
+ std::vector<StorePathWithOutputs> subs;
+ for (auto & p : willSubstitute) subs.emplace_back(p.clone());
+ store->buildPaths(subs);
} catch (Error & e) {
printError(format("warning: %1%") % e.msg());
}
}
- out << store->queryValidPaths(paths);
+ writeStorePaths(*store, out, store->queryValidPaths(paths));
break;
}
case cmdQueryPathInfos: {
- PathSet paths = readStorePaths<PathSet>(*store, in);
+ auto paths = readStorePaths<StorePathSet>(*store, in);
// !!! Maybe we want a queryPathInfos?
for (auto & i : paths) {
try {
auto info = store->queryPathInfo(i);
- out << info->path << info->deriver << info->references;
+ out << store->printStorePath(info->path)
+ << (info->deriver ? store->printStorePath(*info->deriver) : "");
+ writeStorePaths(*store, out, info->references);
// !!! Maybe we want compression?
out << info->narSize // downloadSize
<< info->narSize;
@@ -869,7 +871,7 @@ static void opServe(Strings opFlags, Strings opArgs)
}
case cmdDumpStorePath:
- store->narFromPath(readStorePath(*store, in), out);
+ store->narFromPath(store->parseStorePath(readString(in)), out);
break;
case cmdImportPaths: {
@@ -881,14 +883,17 @@ static void opServe(Strings opFlags, Strings opArgs)
case cmdExportPaths: {
readInt(in); // obsolete
- store->exportPaths(readStorePaths<Paths>(*store, in), out);
+ store->exportPaths(readStorePaths<StorePathSet>(*store, in), out);
break;
}
case cmdBuildPaths: {
if (!writeAllowed) throw Error("building paths is not allowed");
- PathSet paths = readStorePaths<PathSet>(*store, in);
+
+ std::vector<StorePathWithOutputs> paths;
+ for (auto & s : readStrings<Strings>(in))
+ paths.emplace_back(store->parseDrvPathWithOutputs(s));
getBuildSettings();
@@ -907,7 +912,7 @@ static void opServe(Strings opFlags, Strings opArgs)
if (!writeAllowed) throw Error("building paths is not allowed");
- Path drvPath = readStorePath(*store, in); // informational only
+ auto drvPath = store->parseStorePath(readString(in)); // informational only
BasicDerivation drv;
readDerivation(in, *store, drv);
@@ -926,30 +931,29 @@ static void opServe(Strings opFlags, Strings opArgs)
case cmdQueryClosure: {
bool includeOutputs = readInt(in);
- PathSet closure;
- store->computeFSClosure(readStorePaths<PathSet>(*store, in),
+ StorePathSet closure;
+ store->computeFSClosure(readStorePaths<StorePathSet>(*store, in),
closure, false, includeOutputs);
- out << closure;
+ writeStorePaths(*store, out, closure);
break;
}
case cmdAddToStoreNar: {
if (!writeAllowed) throw Error("importing paths is not allowed");
- ValidPathInfo info;
- info.path = readStorePath(*store, in);
- in >> info.deriver;
- if (!info.deriver.empty())
- store->assertStorePath(info.deriver);
+ auto path = readString(in);
+ ValidPathInfo info(store->parseStorePath(path));
+ auto deriver = readString(in);
+ if (deriver != "")
+ info.deriver = store->parseStorePath(deriver);
info.narHash = Hash(readString(in), htSHA256);
- info.references = readStorePaths<PathSet>(*store, in);
+ info.references = readStorePaths<StorePathSet>(*store, in);
in >> info.registrationTime >> info.narSize >> info.ultimate;
info.sigs = readStrings<StringSet>(in);
in >> info.ca;
- if (info.narSize == 0) {
+ if (info.narSize == 0)
throw Error("narInfo is too old and missing the narSize field");
- }
SizedSource sizedSource(in, info.narSize);