diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2022-11-03 17:43:40 +0100 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2022-11-03 17:43:40 +0100 |
commit | b95faccf03e5213b6087626ab8d46e0704aad6b5 (patch) | |
tree | f9d560f2004f951d8efbf1024292a88366d8efd7 /src/nix/path-from-hash-part.cc | |
parent | 47dec825c5daeeb9d615eb4d1eead3dbaa06c7c9 (diff) | |
parent | dd1970c233a82328445b69e903574e14115ee933 (diff) |
Merge remote-tracking branch 'origin/master' into auto-uid-allocation
Diffstat (limited to 'src/nix/path-from-hash-part.cc')
-rw-r--r-- | src/nix/path-from-hash-part.cc | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/nix/path-from-hash-part.cc b/src/nix/path-from-hash-part.cc new file mode 100644 index 000000000..7f7cda8d3 --- /dev/null +++ b/src/nix/path-from-hash-part.cc @@ -0,0 +1,39 @@ +#include "command.hh" +#include "store-api.hh" + +using namespace nix; + +struct CmdPathFromHashPart : StoreCommand +{ + std::string hashPart; + + CmdPathFromHashPart() + { + expectArgs({ + .label = "hash-part", + .handler = {&hashPart}, + }); + } + + std::string description() override + { + return "get a store path from its hash part"; + } + + std::string doc() override + { + return + #include "path-from-hash-part.md" + ; + } + + void run(ref<Store> store) override + { + if (auto storePath = store->queryPathFromHashPart(hashPart)) + logger->cout(store->printStorePath(*storePath)); + else + throw Error("there is no store path corresponding to '%s'", hashPart); + } +}; + +static auto rCmdPathFromHashPart = registerCommand2<CmdPathFromHashPart>({"store", "path-from-hash-part"}); |