diff options
author | Daiderd Jordan <daiderd@gmail.com> | 2018-08-30 23:42:28 +0200 |
---|---|---|
committer | Daiderd Jordan <daiderd@gmail.com> | 2018-09-02 12:54:39 +0200 |
commit | 7314dc7f07a90782dea5cc9d298c7f7148e3b7c3 (patch) | |
tree | c4eb33b75efef4fca31dab5e84db4062ea8a69a2 /src/nix/doctor.cc | |
parent | 070823baa4c3c397c8a5eb0378944187e7f4903c (diff) |
nix doctor: add warning if client/daemon protocol mismatches
A protocol mismatch can sometimes cause problems when using specific
features with an older daemon. For example:
Nix 2.0 changed the way files are compied to the store. The daemon is
backwards compatible and can still handle older clients, however a 1.11
nix-daemon isn't forwards compatible.
Diffstat (limited to 'src/nix/doctor.cc')
-rw-r--r-- | src/nix/doctor.cc | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/nix/doctor.cc b/src/nix/doctor.cc index fb4fc2a6e..6ef5eb9d3 100644 --- a/src/nix/doctor.cc +++ b/src/nix/doctor.cc @@ -1,9 +1,20 @@ #include "command.hh" #include "shared.hh" #include "store-api.hh" +#include "worker-protocol.hh" using namespace nix; +std::string formatProtocol(unsigned int proto) +{ + if (proto) { + auto major = GET_PROTOCOL_MAJOR(proto) >> 8; + auto minor = GET_PROTOCOL_MINOR(proto); + return (format("%1%.%2%") % major % minor).str(); + } + return "unknown"; +} + struct CmdDoctor : StoreCommand { std::string name() override @@ -19,8 +30,22 @@ struct CmdDoctor : StoreCommand void run(ref<Store> store) override { std::cout << "Store uri: " << store->getUri() << std::endl; + std::cout << std::endl; + + checkStoreProtocol(store->getProtocol()); + } + + void checkStoreProtocol(unsigned int proto) { + if (PROTOCOL_VERSION != proto) { + std::cout << "Warning: protocol version of this client does not match the store." << std::endl; + std::cout << "While this is not necessarily a problem it's recommended to keep the client in" << std::endl; + std::cout << "sync with the daemon." << std::endl; + std::cout << std::endl; + std::cout << "Client protocol: " << formatProtocol(PROTOCOL_VERSION) << std::endl; + std::cout << "Store protocol: " << formatProtocol(proto) << std::endl; + std::cout << std::endl; + } } }; static RegisterCommand r1(make_ref<CmdDoctor>()); - |