* Allow unprivileged users to do `nix-store --clear-failed-paths' and

`nix-store --query-failed-paths'.
This commit is contained in:
Eelco Dolstra 2010-05-04 10:45:10 +00:00
parent 7fa338f4ba
commit f92c9a0ac5
7 changed files with 51 additions and 5 deletions

View File

@ -184,11 +184,8 @@ public:
/* Query whether `path' previously failed to build. */ /* Query whether `path' previously failed to build. */
bool hasPathFailed(const Path & path); bool hasPathFailed(const Path & path);
/* Return the set of paths that have failed to build.*/
PathSet queryFailedPaths(); 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); void clearFailedPaths(const PathSet & paths);
private: private:

View File

@ -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) void RemoteStore::processStderr(Sink * sink, Source * source)
{ {
unsigned int msg; unsigned int msg;

View File

@ -70,6 +70,10 @@ public:
void collectGarbage(const GCOptions & options, GCResults & results); void collectGarbage(const GCOptions & options, GCResults & results);
PathSet queryFailedPaths();
void clearFailedPaths(const PathSet & paths);
private: private:
AutoCloseFD fdSocket; AutoCloseFD fdSocket;
FdSink to; FdSink to;

View File

@ -209,6 +209,13 @@ public:
/* Perform a garbage collection. */ /* Perform a garbage collection. */
virtual void collectGarbage(const GCOptions & options, GCResults & results) = 0; 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;
}; };

View File

@ -36,6 +36,8 @@ typedef enum {
wopQuerySubstitutablePathInfo = 21, wopQuerySubstitutablePathInfo = 21,
wopQueryDerivationOutputs = 22, wopQueryDerivationOutputs = 22,
wopQueryValidPaths = 23, wopQueryValidPaths = 23,
wopQueryFailedPaths = 24,
wopClearFailedPaths = 25,
} WorkerOp; } WorkerOp;

View File

@ -670,7 +670,7 @@ static void opQueryFailedPaths(Strings opFlags, Strings opArgs)
{ {
if (!opArgs.empty() || !opFlags.empty()) if (!opArgs.empty() || !opFlags.empty())
throw UsageError("no arguments expected"); throw UsageError("no arguments expected");
PathSet failed = ensureLocalStore().queryFailedPaths(); PathSet failed = store->queryFailedPaths();
foreach (PathSet::iterator, i, failed) foreach (PathSet::iterator, i, failed)
cout << format("%1%\n") % *i; cout << format("%1%\n") % *i;
} }
@ -680,7 +680,7 @@ static void opClearFailedPaths(Strings opFlags, Strings opArgs)
{ {
if (!opFlags.empty()) if (!opFlags.empty())
throw UsageError("no flags expected"); throw UsageError("no flags expected");
ensureLocalStore().clearFailedPaths(PathSet(opArgs.begin(), opArgs.end())); store->clearFailedPaths(PathSet(opArgs.begin(), opArgs.end()));
} }

View File

@ -528,6 +528,23 @@ static void performOp(unsigned int clientVersion,
break; 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: default:
throw Error(format("invalid operation %1%") % op); throw Error(format("invalid operation %1%") % op);
} }