Move BinaryCacheStore / LocalBinaryCacheStore from Hydra
So you can now do: $ NIX_REMOTE=file:///tmp/binary-cache nix-store -qR /nix/store/...
This commit is contained in:
		
							parent
							
								
									b584a0e7de
								
							
						
					
					
						commit
						263187a2ec
					
				
					 7 changed files with 658 additions and 5 deletions
				
			
		
							
								
								
									
										44
									
								
								src/libstore/local-binary-cache-store.cc
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								src/libstore/local-binary-cache-store.cc
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,44 @@ | |||
| #include "local-binary-cache-store.hh" | ||||
| 
 | ||||
| namespace nix { | ||||
| 
 | ||||
| LocalBinaryCacheStore::LocalBinaryCacheStore(std::shared_ptr<Store> localStore, | ||||
|     const Path & secretKeyFile, const Path & publicKeyFile, | ||||
|     const Path & binaryCacheDir) | ||||
|     : BinaryCacheStore(localStore, secretKeyFile, publicKeyFile) | ||||
|     , binaryCacheDir(binaryCacheDir) | ||||
| { | ||||
| } | ||||
| 
 | ||||
| void LocalBinaryCacheStore::init() | ||||
| { | ||||
|     createDirs(binaryCacheDir + "/nar"); | ||||
|     BinaryCacheStore::init(); | ||||
| } | ||||
| 
 | ||||
| static void atomicWrite(const Path & path, const std::string & s) | ||||
| { | ||||
|     Path tmp = path + ".tmp." + std::to_string(getpid()); | ||||
|     AutoDelete del(tmp, false); | ||||
|     writeFile(tmp, s); | ||||
|     if (rename(tmp.c_str(), path.c_str())) | ||||
|         throw SysError(format("renaming ‘%1%’ to ‘%2%’") % tmp % path); | ||||
|     del.cancel(); | ||||
| } | ||||
| 
 | ||||
| bool LocalBinaryCacheStore::fileExists(const std::string & path) | ||||
| { | ||||
|     return pathExists(binaryCacheDir + "/" + path); | ||||
| } | ||||
| 
 | ||||
| void LocalBinaryCacheStore::upsertFile(const std::string & path, const std::string & data) | ||||
| { | ||||
|     atomicWrite(binaryCacheDir + "/" + path, data); | ||||
| } | ||||
| 
 | ||||
| std::string LocalBinaryCacheStore::getFile(const std::string & path) | ||||
| { | ||||
|     return readFile(binaryCacheDir + "/" + path); | ||||
| } | ||||
| 
 | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue