libstore: add usage hints to repairPath on daemons
we can't change the protocol to allow daemons to do this, and we should not try to guess what the `auto` store uri means depending on whether a command was run by root or not due to copious side effects and not even being able to tell whether the `auto` store uri was given explicitly or not. while `auto` may *technically* allow this via its naming we should resist the urge to add a hack and fix the underlying protocols instead, especially since repairPath should be a rare, superuser only operation. fixes #888 Change-Id: I1b53245db226199f827a89a237a2ab9907c3f766
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
#include <atomic>
|
||||
#include <limits>
|
||||
#include <map>
|
||||
#include <optional>
|
||||
#include <type_traits>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
@@ -927,11 +928,17 @@ protected:
|
||||
* \todo Using this should be a last resort. It is better to make
|
||||
* the method "virtual pure" and/or move it to a subclass.
|
||||
*/
|
||||
[[noreturn]] void unsupported(const std::string & op)
|
||||
[[noreturn]]
|
||||
void
|
||||
unsupported(const std::string & op, const std::optional<std::string_view> info = std::nullopt)
|
||||
{
|
||||
throw Unsupported("operation '%s' is not supported by store '%s'", op, getUri());
|
||||
throw Unsupported(
|
||||
"operation '%s' is not supported by store '%s'%s",
|
||||
op,
|
||||
getUri(),
|
||||
Uncolored(info ? fmt(". %s", *info) : "")
|
||||
);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -49,6 +49,16 @@ public:
|
||||
return LocalFSStore::narFromPath(path, context);
|
||||
}
|
||||
|
||||
kj::Promise<Result<void>> repairPath(const StorePath & path) override
|
||||
try {
|
||||
unsupported(
|
||||
"repairPath",
|
||||
HintFmt("This command must be run as %s with %s", "root", "--store local").str()
|
||||
);
|
||||
} catch (...) {
|
||||
return {result::current_exception()};
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of `IndirectRootStore::addIndirectRoot()` which
|
||||
* delegates to the remote store.
|
||||
|
||||
Reference in New Issue
Block a user