From f92c9a0ac585d30e245c6667cbce4b035659cb11 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 4 May 2010 10:45:10 +0000 Subject: [PATCH] * Allow unprivileged users to do `nix-store --clear-failed-paths' and `nix-store --query-failed-paths'. --- src/libstore/local-store.hh | 3 --- src/libstore/remote-store.cc | 19 +++++++++++++++++++ src/libstore/remote-store.hh | 4 ++++ src/libstore/store-api.hh | 7 +++++++ src/libstore/worker-protocol.hh | 2 ++ src/nix-store/nix-store.cc | 4 ++-- src/nix-worker/nix-worker.cc | 17 +++++++++++++++++ 7 files changed, 51 insertions(+), 5 deletions(-) diff --git a/src/libstore/local-store.hh b/src/libstore/local-store.hh index 2fd640e398..c1e0e335f2 100644 --- a/src/libstore/local-store.hh +++ b/src/libstore/local-store.hh @@ -184,11 +184,8 @@ public: /* Query whether `path' previously failed to build. */ bool hasPathFailed(const Path & path); - /* Return the set of paths that have failed to build.*/ PathSet queryFailedPaths(); - /* Clear the "failed" status of the given paths. The special - value `*' causes all failed paths to be cleared. */ void clearFailedPaths(const PathSet & paths); private: diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc index c5d7975b52..334ad95cf9 100644 --- a/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc @@ -451,6 +451,25 @@ void RemoteStore::collectGarbage(const GCOptions & options, GCResults & results) } +PathSet RemoteStore::queryFailedPaths() +{ + openConnection(); + writeInt(wopQueryFailedPaths, to); + processStderr(); + return readStorePaths(from); +} + + +void RemoteStore::clearFailedPaths(const PathSet & paths) +{ + openConnection(); + writeInt(wopClearFailedPaths, to); + writeStringSet(paths, to); + processStderr(); + readInt(from); +} + + void RemoteStore::processStderr(Sink * sink, Source * source) { unsigned int msg; diff --git a/src/libstore/remote-store.hh b/src/libstore/remote-store.hh index 8bab1d8c48..02a1c47525 100644 --- a/src/libstore/remote-store.hh +++ b/src/libstore/remote-store.hh @@ -70,6 +70,10 @@ public: void collectGarbage(const GCOptions & options, GCResults & results); + PathSet queryFailedPaths(); + + void clearFailedPaths(const PathSet & paths); + private: AutoCloseFD fdSocket; FdSink to; diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index 095fdd24bb..fbe0cce81e 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -209,6 +209,13 @@ public: /* Perform a garbage collection. */ virtual void collectGarbage(const GCOptions & options, GCResults & results) = 0; + + /* Return the set of paths that have failed to build.*/ + virtual PathSet queryFailedPaths() = 0; + + /* Clear the "failed" status of the given paths. The special + value `*' causes all failed paths to be cleared. */ + virtual void clearFailedPaths(const PathSet & paths) = 0; }; diff --git a/src/libstore/worker-protocol.hh b/src/libstore/worker-protocol.hh index c3096010b6..392a69acf6 100644 --- a/src/libstore/worker-protocol.hh +++ b/src/libstore/worker-protocol.hh @@ -36,6 +36,8 @@ typedef enum { wopQuerySubstitutablePathInfo = 21, wopQueryDerivationOutputs = 22, wopQueryValidPaths = 23, + wopQueryFailedPaths = 24, + wopClearFailedPaths = 25, } WorkerOp; diff --git a/src/nix-store/nix-store.cc b/src/nix-store/nix-store.cc index 148fd6add4..3b34b9dae6 100644 --- a/src/nix-store/nix-store.cc +++ b/src/nix-store/nix-store.cc @@ -670,7 +670,7 @@ static void opQueryFailedPaths(Strings opFlags, Strings opArgs) { if (!opArgs.empty() || !opFlags.empty()) throw UsageError("no arguments expected"); - PathSet failed = ensureLocalStore().queryFailedPaths(); + PathSet failed = store->queryFailedPaths(); foreach (PathSet::iterator, i, failed) cout << format("%1%\n") % *i; } @@ -680,7 +680,7 @@ static void opClearFailedPaths(Strings opFlags, Strings opArgs) { if (!opFlags.empty()) throw UsageError("no flags expected"); - ensureLocalStore().clearFailedPaths(PathSet(opArgs.begin(), opArgs.end())); + store->clearFailedPaths(PathSet(opArgs.begin(), opArgs.end())); } diff --git a/src/nix-worker/nix-worker.cc b/src/nix-worker/nix-worker.cc index a41fb2e154..d41877e881 100644 --- a/src/nix-worker/nix-worker.cc +++ b/src/nix-worker/nix-worker.cc @@ -528,6 +528,23 @@ static void performOp(unsigned int clientVersion, break; } + case wopQueryFailedPaths: { + startWork(); + PathSet paths = store->queryFailedPaths(); + stopWork(); + writeStringSet(paths, to); + break; + } + + case wopClearFailedPaths: { + PathSet paths = readStringSet(from); + startWork(); + store->clearFailedPaths(paths); + stopWork(); + writeInt(1, to); + break; + } + default: throw Error(format("invalid operation %1%") % op); }