Merge pull request #2495 from LnL7/doctor-exit-code
nix doctor: return nonzero exitcode if a check fails
This commit is contained in:
		
						commit
						f90a67e24d
					
				
					 1 changed files with 20 additions and 6 deletions
				
			
		|  | @ -18,6 +18,8 @@ std::string formatProtocol(unsigned int proto) | ||||||
| 
 | 
 | ||||||
| struct CmdDoctor : StoreCommand | struct CmdDoctor : StoreCommand | ||||||
| { | { | ||||||
|  |     bool success = true; | ||||||
|  | 
 | ||||||
|     std::string name() override |     std::string name() override | ||||||
|     { |     { | ||||||
|         return "doctor"; |         return "doctor"; | ||||||
|  | @ -36,13 +38,16 @@ struct CmdDoctor : StoreCommand | ||||||
|         auto type = getStoreType(); |         auto type = getStoreType(); | ||||||
| 
 | 
 | ||||||
|         if (type < tOther) { |         if (type < tOther) { | ||||||
|             checkNixInPath(); |             success &= checkNixInPath(); | ||||||
|             checkProfileRoots(store); |             success &= checkProfileRoots(store); | ||||||
|         } |         } | ||||||
|         checkStoreProtocol(store->getProtocol()); |         success &= checkStoreProtocol(store->getProtocol()); | ||||||
|  | 
 | ||||||
|  |         if (!success) | ||||||
|  |             throw Exit(2); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     void checkNixInPath() |     bool checkNixInPath() | ||||||
|     { |     { | ||||||
|         PathSet dirs; |         PathSet dirs; | ||||||
| 
 | 
 | ||||||
|  | @ -56,10 +61,13 @@ struct CmdDoctor : StoreCommand | ||||||
|             for (auto & dir : dirs) |             for (auto & dir : dirs) | ||||||
|                 std::cout << "  " << dir << std::endl; |                 std::cout << "  " << dir << std::endl; | ||||||
|             std::cout << std::endl; |             std::cout << std::endl; | ||||||
|         } |             return false; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|     void checkProfileRoots(ref<Store> store) |         return true; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     bool checkProfileRoots(ref<Store> store) | ||||||
|     { |     { | ||||||
|         PathSet dirs; |         PathSet dirs; | ||||||
| 
 | 
 | ||||||
|  | @ -86,10 +94,13 @@ struct CmdDoctor : StoreCommand | ||||||
|             for (auto & dir : dirs) |             for (auto & dir : dirs) | ||||||
|                 std::cout << "  " << dir << std::endl; |                 std::cout << "  " << dir << std::endl; | ||||||
|             std::cout << std::endl; |             std::cout << std::endl; | ||||||
|         } |             return false; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|     void checkStoreProtocol(unsigned int storeProto) |         return true; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     bool checkStoreProtocol(unsigned int storeProto) | ||||||
|     { |     { | ||||||
|         unsigned int clientProto = GET_PROTOCOL_MAJOR(SERVE_PROTOCOL_VERSION) == GET_PROTOCOL_MAJOR(storeProto) |         unsigned int clientProto = GET_PROTOCOL_MAJOR(SERVE_PROTOCOL_VERSION) == GET_PROTOCOL_MAJOR(storeProto) | ||||||
|             ? SERVE_PROTOCOL_VERSION |             ? SERVE_PROTOCOL_VERSION | ||||||
|  | @ -103,7 +114,10 @@ struct CmdDoctor : StoreCommand | ||||||
|             std::cout << "Client protocol: " << formatProtocol(clientProto) << std::endl; |             std::cout << "Client protocol: " << formatProtocol(clientProto) << std::endl; | ||||||
|             std::cout << "Store protocol: " << formatProtocol(storeProto) << std::endl; |             std::cout << "Store protocol: " << formatProtocol(storeProto) << std::endl; | ||||||
|             std::cout << std::endl; |             std::cout << std::endl; | ||||||
|  |             return false; | ||||||
|         } |         } | ||||||
|  | 
 | ||||||
|  |         return true; | ||||||
|     } |     } | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue