Unify "nix verify-paths" and "nix verify-store"
"verify-store" is now simply an "--all" flag to "nix verify". This flag can be used for any other store path command as well (e.g. "nix path-info", "nix copy-sigs", ...).
This commit is contained in:
		
							parent
							
								
									327569035c
								
							
						
					
					
						commit
						99851c6f06
					
				
					 3 changed files with 31 additions and 60 deletions
				
			
		|  | @ -73,18 +73,28 @@ StorePathsCommand::StorePathsCommand() | ||||||
| { | { | ||||||
|     expectArgs("paths", &storePaths); |     expectArgs("paths", &storePaths); | ||||||
|     mkFlag('r', "recursive", "apply operation to closure of the specified paths", &recursive); |     mkFlag('r', "recursive", "apply operation to closure of the specified paths", &recursive); | ||||||
|  |     mkFlag(0, "all", "apply operation to the entire store", &all); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void StorePathsCommand::run(ref<Store> store) | void StorePathsCommand::run(ref<Store> store) | ||||||
| { | { | ||||||
|     for (auto & storePath : storePaths) |     if (all) { | ||||||
|         storePath = followLinksToStorePath(storePath); |         if (storePaths.size()) | ||||||
|  |             throw UsageError("‘--all’ does not expect arguments"); | ||||||
|  |         for (auto & p : store->queryAllValidPaths()) | ||||||
|  |             storePaths.push_back(p); | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     if (recursive) { |     else { | ||||||
|         PathSet closure; |  | ||||||
|         for (auto & storePath : storePaths) |         for (auto & storePath : storePaths) | ||||||
|             store->computeFSClosure(storePath, closure, false, false); |             storePath = followLinksToStorePath(storePath); | ||||||
|         storePaths = store->topoSortPaths(closure); | 
 | ||||||
|  |         if (recursive) { | ||||||
|  |             PathSet closure; | ||||||
|  |             for (auto & storePath : storePaths) | ||||||
|  |                 store->computeFSClosure(storePath, closure, false, false); | ||||||
|  |             storePaths = store->topoSortPaths(closure); | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     run(store, storePaths); |     run(store, storePaths); | ||||||
|  |  | ||||||
|  | @ -31,6 +31,7 @@ private: | ||||||
| 
 | 
 | ||||||
|     Paths storePaths; |     Paths storePaths; | ||||||
|     bool recursive = false; |     bool recursive = false; | ||||||
|  |     bool all = false; | ||||||
| 
 | 
 | ||||||
| public: | public: | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -10,14 +10,14 @@ | ||||||
| 
 | 
 | ||||||
| using namespace nix; | using namespace nix; | ||||||
| 
 | 
 | ||||||
| struct MixVerify : virtual Args | struct CmdVerify : StorePathsCommand | ||||||
| { | { | ||||||
|     bool noContents = false; |     bool noContents = false; | ||||||
|     bool noTrust = false; |     bool noTrust = false; | ||||||
|     Strings substituterUris; |     Strings substituterUris; | ||||||
|     size_t sigsNeeded; |     size_t sigsNeeded; | ||||||
| 
 | 
 | ||||||
|     MixVerify() |     CmdVerify() | ||||||
|     { |     { | ||||||
|         mkFlag(0, "no-contents", "do not verify the contents of each store path", &noContents); |         mkFlag(0, "no-contents", "do not verify the contents of each store path", &noContents); | ||||||
|         mkFlag(0, "no-trust", "do not verify whether each store path is trusted", &noTrust); |         mkFlag(0, "no-trust", "do not verify whether each store path is trusted", &noTrust); | ||||||
|  | @ -26,7 +26,17 @@ struct MixVerify : virtual Args | ||||||
|         mkIntFlag('n', "sigs-needed", "require that each path has at least N valid signatures", &sigsNeeded); |         mkIntFlag('n', "sigs-needed", "require that each path has at least N valid signatures", &sigsNeeded); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     void verifyPaths(ref<Store> store, const Paths & storePaths) |     std::string name() override | ||||||
|  |     { | ||||||
|  |         return "verify"; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     std::string description() override | ||||||
|  |     { | ||||||
|  |         return "verify the integrity of store paths"; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     void run(ref<Store> store, Paths storePaths) override | ||||||
|     { |     { | ||||||
|         restoreAffinity(); // FIXME
 |         restoreAffinity(); // FIXME
 | ||||||
| 
 | 
 | ||||||
|  | @ -158,54 +168,4 @@ struct MixVerify : virtual Args | ||||||
|     } |     } | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| struct CmdVerifyPaths : StorePathsCommand, MixVerify | static RegisterCommand r1(make_ref<CmdVerify>()); | ||||||
| { |  | ||||||
|     CmdVerifyPaths() |  | ||||||
|     { |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     std::string name() override |  | ||||||
|     { |  | ||||||
|         return "verify-paths"; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     std::string description() override |  | ||||||
|     { |  | ||||||
|         return "verify the integrity of store paths"; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     void run(ref<Store> store, Paths storePaths) override |  | ||||||
|     { |  | ||||||
|         verifyPaths(store, storePaths); |  | ||||||
|     } |  | ||||||
| }; |  | ||||||
| 
 |  | ||||||
| static RegisterCommand r1(make_ref<CmdVerifyPaths>()); |  | ||||||
| 
 |  | ||||||
| struct CmdVerifyStore : StoreCommand, MixVerify |  | ||||||
| { |  | ||||||
|     CmdVerifyStore() |  | ||||||
|     { |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     std::string name() override |  | ||||||
|     { |  | ||||||
|         return "verify-store"; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     std::string description() override |  | ||||||
|     { |  | ||||||
|         return "verify the integrity of all paths in the Nix store"; |  | ||||||
|     } |  | ||||||
| 
 |  | ||||||
|     void run(ref<Store> store) override |  | ||||||
|     { |  | ||||||
|         // FIXME: use store->verifyStore()?
 |  | ||||||
| 
 |  | ||||||
|         PathSet validPaths = store->queryAllValidPaths(); |  | ||||||
| 
 |  | ||||||
|         verifyPaths(store, Paths(validPaths.begin(), validPaths.end())); |  | ||||||
|     } |  | ||||||
| }; |  | ||||||
| 
 |  | ||||||
| static RegisterCommand r2(make_ref<CmdVerifyStore>()); |  | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue