From 0565b5f2b35dc153dc98e1e3bd37476aa13ee4f1 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 30 Nov 2006 22:43:55 +0000 Subject: * More remote operations. * Added new operation hasSubstitutes(), which is more efficient than querySubstitutes().size() > 0. --- src/nix-worker/main.cc | 60 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 51 insertions(+), 9 deletions(-) (limited to 'src/nix-worker/main.cc') diff --git a/src/nix-worker/main.cc b/src/nix-worker/main.cc index d834e625ef46..8ac69561f0bf 100644 --- a/src/nix-worker/main.cc +++ b/src/nix-worker/main.cc @@ -8,6 +8,23 @@ using namespace nix; +Path readStorePath(Source & from) +{ + Path path = readString(from); + assertStorePath(path); + return path; +} + + +PathSet readStorePaths(Source & from) +{ + PathSet paths = readStringSet(from); + for (PathSet::iterator i = paths.begin(); i != paths.end(); ++i) + assertStorePath(*i); + return paths; +} + + void processConnection(Source & from, Sink & to) { store = boost::shared_ptr(new LocalStore(true)); @@ -35,12 +52,29 @@ void processConnection(Source & from, Sink & to) break; case wopIsValidPath: { - Path path = readString(from); - assertStorePath(path); + Path path = readStorePath(from); writeInt(store->isValidPath(path), to); break; } + case wopHasSubstitutes: { + Path path = readStorePath(from); + writeInt(store->hasSubstitutes(path), to); + break; + } + + case wopQueryReferences: + case wopQueryReferrers: { + Path path = readStorePath(from); + PathSet paths; + if (op == wopQueryReferences) + store->queryReferences(path, paths); + else + store->queryReferrers(path, paths); + writeStringSet(paths, to); + break; + } + case wopAddToStore: { /* !!! uberquick hack */ string baseName = readString(from); @@ -55,17 +89,25 @@ void processConnection(Source & from, Sink & to) case wopAddTextToStore: { string suffix = readString(from); string s = readString(from); - unsigned int refCount = readInt(from); - PathSet refs; - while (refCount--) { - Path ref = readString(from); - assertStorePath(ref); - refs.insert(ref); - } + PathSet refs = readStorePaths(from); writeString(store->addTextToStore(suffix, s, refs), to); break; } + case wopBuildDerivations: { + PathSet drvs = readStorePaths(from); + store->buildDerivations(drvs); + writeInt(1, to); + break; + } + + case wopEnsurePath: { + Path path = readStorePath(from); + store->ensurePath(path); + writeInt(1, to); + break; + } + default: throw Error(format("invalid operation %1%") % op); } -- cgit 1.4.1