about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2018-10-29T12·19+0100
committerGitHub <noreply@github.com>2018-10-29T12·19+0100
commitf90a67e24d906bdb86c86b9d1c7e6307aeb6ff7c (patch)
tree6e927014e43e034c427babd2bac88c67b3f3799d
parent18b4c53f71dfc626f5f5ffa0282afd1b9faad6a4 (diff)
parent8e6bf492971347e18c1b5800e9e8fa5191a0839b (diff)
Merge pull request #2495 from LnL7/doctor-exit-code
nix doctor: return nonzero exitcode if a check fails
-rw-r--r--src/nix/doctor.cc26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/nix/doctor.cc b/src/nix/doctor.cc
index 1ce3efcb0415..7b5444619470 100644
--- a/src/nix/doctor.cc
+++ b/src/nix/doctor.cc
@@ -18,6 +18,8 @@ std::string formatProtocol(unsigned int proto)
 
 struct CmdDoctor : StoreCommand
 {
+    bool success = true;
+
     std::string name() override
     {
         return "doctor";
@@ -36,13 +38,16 @@ struct CmdDoctor : StoreCommand
         auto type = getStoreType();
 
         if (type < tOther) {
-            checkNixInPath();
-            checkProfileRoots(store);
+            success &= checkNixInPath();
+            success &= checkProfileRoots(store);
         }
-        checkStoreProtocol(store->getProtocol());
+        success &= checkStoreProtocol(store->getProtocol());
+
+        if (!success)
+            throw Exit(2);
     }
 
-    void checkNixInPath()
+    bool checkNixInPath()
     {
         PathSet dirs;
 
@@ -56,10 +61,13 @@ struct CmdDoctor : StoreCommand
             for (auto & dir : dirs)
                 std::cout << "  " << dir << std::endl;
             std::cout << std::endl;
+            return false;
         }
+
+        return true;
     }
 
-    void checkProfileRoots(ref<Store> store)
+    bool checkProfileRoots(ref<Store> store)
     {
         PathSet dirs;
 
@@ -86,10 +94,13 @@ struct CmdDoctor : StoreCommand
             for (auto & dir : dirs)
                 std::cout << "  " << dir << std::endl;
             std::cout << std::endl;
+            return false;
         }
+
+        return true;
     }
 
-    void checkStoreProtocol(unsigned int storeProto)
+    bool checkStoreProtocol(unsigned int storeProto)
     {
         unsigned int clientProto = GET_PROTOCOL_MAJOR(SERVE_PROTOCOL_VERSION) == GET_PROTOCOL_MAJOR(storeProto)
             ? SERVE_PROTOCOL_VERSION
@@ -103,7 +114,10 @@ struct CmdDoctor : StoreCommand
             std::cout << "Client protocol: " << formatProtocol(clientProto) << std::endl;
             std::cout << "Store protocol: " << formatProtocol(storeProto) << std::endl;
             std::cout << std::endl;
+            return false;
         }
+
+        return true;
     }
 };