nix-store -r: Add ‘--ignore-unknown’ flag
This flag causes paths that do not have a known substitute to be quietly ignored. This is mostly useful for Charon, allowing it to speed up deployment by letting a machine use substitutes for all substitutable paths, instead of uploading them. The latter is frequently faster, e.g. if the target machine has a fast Internet connection while the source machine is on a slow ADSL line.
This commit is contained in:
		
							parent
							
								
									bf3725da2a
								
							
						
					
					
						commit
						9de6bc5d05
					
				
					 4 changed files with 44 additions and 10 deletions
				
			
		|  | @ -182,7 +182,14 @@ printed.)</para> | |||
| 
 | ||||
|     <listitem><para>Print on standard error a description of what | ||||
|     packages would be built or downloaded, without actually performing | ||||
|     the operation</para></listitem> | ||||
|     the operation.</para></listitem> | ||||
| 
 | ||||
|   </varlistentry> | ||||
| 
 | ||||
|   <varlistentry><term><option>--ignore-unknown</option></term> | ||||
| 
 | ||||
|     <listitem><para>If a non-derivation path does not have a | ||||
|     substitute, then silently ignore it.</para></listitem> | ||||
| 
 | ||||
|   </varlistentry> | ||||
| 
 | ||||
|  |  | |||
|  | @ -47,7 +47,14 @@ void printMissing(StoreAPI & store, const PathSet & paths) | |||
|     unsigned long long downloadSize, narSize; | ||||
|     PathSet willBuild, willSubstitute, unknown; | ||||
|     queryMissing(store, paths, willBuild, willSubstitute, unknown, downloadSize, narSize); | ||||
|     printMissing(willBuild, willSubstitute, unknown, downloadSize, narSize); | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| void printMissing(const PathSet & willBuild, | ||||
|     const PathSet & willSubstitute, const PathSet & unknown, | ||||
|     unsigned long long downloadSize, unsigned long long narSize) | ||||
| { | ||||
|     if (!willBuild.empty()) { | ||||
|         printMsg(lvlInfo, format("these derivations will be built:")); | ||||
|         foreach (PathSet::iterator, i, willBuild) | ||||
|  |  | |||
|  | @ -30,6 +30,10 @@ void printGCWarning(); | |||
| 
 | ||||
| void printMissing(StoreAPI & store, const PathSet & paths); | ||||
| 
 | ||||
| void printMissing(const PathSet & willBuild, | ||||
|     const PathSet & willSubstitute, const PathSet & unknown, | ||||
|     unsigned long long downloadSize, unsigned long long narSize); | ||||
| 
 | ||||
| template<class N> N getIntArg(const string & opt, | ||||
|     Strings::iterator & i, const Strings::iterator & end) | ||||
| { | ||||
|  |  | |||
|  | @ -94,28 +94,44 @@ static void opRealise(Strings opFlags, Strings opArgs) | |||
| { | ||||
|     bool dryRun = false; | ||||
|     bool repair = false; | ||||
|     bool ignoreUnknown = false; | ||||
| 
 | ||||
|     foreach (Strings::iterator, i, opFlags) | ||||
|         if (*i == "--dry-run") dryRun = true; | ||||
|         else if (*i == "--repair") repair = true; | ||||
|         else if (*i == "--ignore-unknown") ignoreUnknown = true; | ||||
|         else throw UsageError(format("unknown flag `%1%'") % *i); | ||||
| 
 | ||||
|     Paths paths; | ||||
|     foreach (Strings::iterator, i, opArgs) | ||||
|         *i = followLinksToStorePath(*i); | ||||
|         paths.push_back(followLinksToStorePath(*i)); | ||||
| 
 | ||||
|     printMissing(*store, PathSet(opArgs.begin(), opArgs.end())); | ||||
|     unsigned long long downloadSize, narSize; | ||||
|     PathSet willBuild, willSubstitute, unknown; | ||||
|     queryMissing(*store, PathSet(paths.begin(), paths.end()), | ||||
|         willBuild, willSubstitute, unknown, downloadSize, narSize); | ||||
| 
 | ||||
|     if (ignoreUnknown) { | ||||
|         Paths paths2; | ||||
|         foreach (Paths::iterator, i, paths) | ||||
|             if (unknown.find(*i) == unknown.end()) paths2.push_back(*i); | ||||
|         paths = paths2; | ||||
|         unknown = PathSet(); | ||||
|     } | ||||
| 
 | ||||
|     printMissing(willBuild, willSubstitute, unknown, downloadSize, narSize); | ||||
| 
 | ||||
|     if (dryRun) return; | ||||
| 
 | ||||
|     /* Build all paths at the same time to exploit parallelism. */ | ||||
|     PathSet paths(opArgs.begin(), opArgs.end()); | ||||
|     store->buildPaths(paths, repair); | ||||
|     store->buildPaths(PathSet(paths.begin(), paths.end()), repair); | ||||
| 
 | ||||
|     foreach (Paths::iterator, i, opArgs) { | ||||
|         PathSet paths = realisePath(*i, false); | ||||
|         foreach (PathSet::iterator, j, paths) | ||||
|             cout << format("%1%\n") % *j; | ||||
|     } | ||||
|     if (!ignoreUnknown) | ||||
|         foreach (Paths::iterator, i, paths) { | ||||
|             PathSet paths = realisePath(*i, false); | ||||
|             foreach (PathSet::iterator, j, paths) | ||||
|                 cout << format("%1%\n") % *j; | ||||
|         } | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue