Add Store::dumpPath() method
This allows applying nix-store --verify-path to binary cache stores: NIX_REMOTE=https://cache.nixos.org nix-store --verify-path /nix/store/s5c7...
This commit is contained in:
		
							parent
							
								
									87295b9844
								
							
						
					
					
						commit
						1c5f73f529
					
				
					 7 changed files with 29 additions and 7 deletions
				
			
		|  | @ -156,10 +156,8 @@ bool BinaryCacheStore::isValidPath(const Path & storePath) | ||||||
|     return fileExists(narInfoFileFor(storePath)); |     return fileExists(narInfoFileFor(storePath)); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void BinaryCacheStore::exportPath(const Path & storePath, bool sign, Sink & sink) | void BinaryCacheStore::dumpPath(const Path & storePath, Sink & sink) | ||||||
| { | { | ||||||
|     assert(!sign); |  | ||||||
| 
 |  | ||||||
|     auto res = readNarInfo(storePath); |     auto res = readNarInfo(storePath); | ||||||
| 
 | 
 | ||||||
|     auto nar = getFile(res.url); |     auto nar = getFile(res.url); | ||||||
|  | @ -183,6 +181,15 @@ void BinaryCacheStore::exportPath(const Path & storePath, bool sign, Sink & sink | ||||||
|     assert(nar.size() % 8 == 0); |     assert(nar.size() % 8 == 0); | ||||||
| 
 | 
 | ||||||
|     sink((unsigned char *) nar.c_str(), nar.size()); |     sink((unsigned char *) nar.c_str(), nar.size()); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void BinaryCacheStore::exportPath(const Path & storePath, bool sign, Sink & sink) | ||||||
|  | { | ||||||
|  |     assert(!sign); | ||||||
|  | 
 | ||||||
|  |     auto res = readNarInfo(storePath); | ||||||
|  | 
 | ||||||
|  |     dumpPath(storePath, sink); | ||||||
| 
 | 
 | ||||||
|     // FIXME: check integrity of NAR.
 |     // FIXME: check integrity of NAR.
 | ||||||
| 
 | 
 | ||||||
|  | @ -264,7 +271,7 @@ Path BinaryCacheStore::addToStore(const string & name, const Path & srcPath, | ||||||
|     StringSink sink; |     StringSink sink; | ||||||
|     Hash h; |     Hash h; | ||||||
|     if (recursive) { |     if (recursive) { | ||||||
|         dumpPath(srcPath, sink, filter); |         nix::dumpPath(srcPath, sink, filter); | ||||||
|         h = hashString(hashAlgo, *sink.s); |         h = hashString(hashAlgo, *sink.s); | ||||||
|     } else { |     } else { | ||||||
|         auto s = readFile(srcPath); |         auto s = readFile(srcPath); | ||||||
|  |  | ||||||
|  | @ -124,6 +124,8 @@ public: | ||||||
|     Path addTextToStore(const string & name, const string & s, |     Path addTextToStore(const string & name, const string & s, | ||||||
|         const PathSet & references, bool repair = false) override; |         const PathSet & references, bool repair = false) override; | ||||||
| 
 | 
 | ||||||
|  |     void dumpPath(const Path & path, Sink & sink) override; | ||||||
|  | 
 | ||||||
|     void exportPath(const Path & path, bool sign, Sink & sink) override; |     void exportPath(const Path & path, bool sign, Sink & sink) override; | ||||||
| 
 | 
 | ||||||
|     Paths importPaths(bool requireSignature, Source & source, |     Paths importPaths(bool requireSignature, Source & source, | ||||||
|  |  | ||||||
|  | @ -1,3 +1,4 @@ | ||||||
|  | #include "archive.hh" | ||||||
| #include "fs-accessor.hh" | #include "fs-accessor.hh" | ||||||
| #include "store-api.hh" | #include "store-api.hh" | ||||||
| 
 | 
 | ||||||
|  | @ -68,4 +69,9 @@ ref<FSAccessor> LocalFSStore::getFSAccessor() | ||||||
|     return make_ref<LocalStoreAccessor>(ref<Store>(shared_from_this())); |     return make_ref<LocalStoreAccessor>(ref<Store>(shared_from_this())); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void LocalFSStore::dumpPath(const Path & path, Sink & sink) | ||||||
|  | { | ||||||
|  |     nix::dumpPath(path, sink); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -1418,7 +1418,7 @@ Path LocalStore::addToStore(const string & name, const Path & _srcPath, | ||||||
|        small files. */ |        small files. */ | ||||||
|     StringSink sink; |     StringSink sink; | ||||||
|     if (recursive) |     if (recursive) | ||||||
|         dumpPath(srcPath, sink, filter); |         nix::dumpPath(srcPath, sink, filter); | ||||||
|     else |     else | ||||||
|         sink.s = make_ref<std::string>(readFile(srcPath)); |         sink.s = make_ref<std::string>(readFile(srcPath)); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -366,7 +366,7 @@ Path RemoteStore::addToStore(const string & name, const Path & _srcPath, | ||||||
|     try { |     try { | ||||||
|         conn->to.written = 0; |         conn->to.written = 0; | ||||||
|         conn->to.warn = true; |         conn->to.warn = true; | ||||||
|         dumpPath(srcPath, conn->to, filter); |         nix::dumpPath(srcPath, conn->to, filter); | ||||||
|         conn->to.warn = false; |         conn->to.warn = false; | ||||||
|         conn->processStderr(); |         conn->processStderr(); | ||||||
|     } catch (SysError & e) { |     } catch (SysError & e) { | ||||||
|  |  | ||||||
|  | @ -215,6 +215,9 @@ public: | ||||||
|     virtual Path addTextToStore(const string & name, const string & s, |     virtual Path addTextToStore(const string & name, const string & s, | ||||||
|         const PathSet & references, bool repair = false) = 0; |         const PathSet & references, bool repair = false) = 0; | ||||||
| 
 | 
 | ||||||
|  |     /* Write a NAR dump of a store path. */ | ||||||
|  |     virtual void dumpPath(const Path & path, Sink & sink) = 0; | ||||||
|  | 
 | ||||||
|     /* Export a store path, that is, create a NAR dump of the store
 |     /* Export a store path, that is, create a NAR dump of the store
 | ||||||
|        path and append its references and its deriver.  Optionally, a |        path and append its references and its deriver.  Optionally, a | ||||||
|        cryptographic signature (created by OpenSSL) of the preceding |        cryptographic signature (created by OpenSSL) of the preceding | ||||||
|  | @ -354,6 +357,8 @@ public: | ||||||
| 
 | 
 | ||||||
| class LocalFSStore : public Store | class LocalFSStore : public Store | ||||||
| { | { | ||||||
|  | public: | ||||||
|  |     void dumpPath(const Path & path, Sink & sink) override; | ||||||
|     ref<FSAccessor> getFSAccessor() override; |     ref<FSAccessor> getFSAccessor() override; | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -783,7 +783,9 @@ static void opVerifyPath(Strings opFlags, Strings opArgs) | ||||||
|         Path path = followLinksToStorePath(i); |         Path path = followLinksToStorePath(i); | ||||||
|         printMsg(lvlTalkative, format("checking path ‘%1%’...") % path); |         printMsg(lvlTalkative, format("checking path ‘%1%’...") % path); | ||||||
|         ValidPathInfo info = store->queryPathInfo(path); |         ValidPathInfo info = store->queryPathInfo(path); | ||||||
|         HashResult current = hashPath(info.narHash.type, path); |         HashSink sink(info.narHash.type); | ||||||
|  |         store->dumpPath(path, sink); | ||||||
|  |         auto current = sink.finish(); | ||||||
|         if (current.first != info.narHash) { |         if (current.first != info.narHash) { | ||||||
|             printMsg(lvlError, |             printMsg(lvlError, | ||||||
|                 format("path ‘%1%’ was modified! expected hash ‘%2%’, got ‘%3%’") |                 format("path ‘%1%’ was modified! expected hash ‘%2%’, got ‘%3%’") | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue