Make derivationFromPath work on diverted stores
This commit is contained in:
		
							parent
							
								
									eda2aaae92
								
							
						
					
					
						commit
						d64e0c1b64
					
				
					 5 changed files with 27 additions and 18 deletions
				
			
		|  | @ -3,6 +3,7 @@ | ||||||
| #include "globals.hh" | #include "globals.hh" | ||||||
| #include "util.hh" | #include "util.hh" | ||||||
| #include "worker-protocol.hh" | #include "worker-protocol.hh" | ||||||
|  | #include "fs-accessor.hh" | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| namespace nix { | namespace nix { | ||||||
|  | @ -164,6 +165,19 @@ Derivation readDerivation(const Path & drvPath) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | Derivation Store::derivationFromPath(const Path & drvPath) | ||||||
|  | { | ||||||
|  |     assertStorePath(drvPath); | ||||||
|  |     ensurePath(drvPath); | ||||||
|  |     auto accessor = getFSAccessor(); | ||||||
|  |     try { | ||||||
|  |         return parseDerivation(accessor->readFile(drvPath)); | ||||||
|  |     } catch (FormatError & e) { | ||||||
|  |         throw Error(format("error parsing derivation ‘%1%’: %2%") % drvPath % e.msg()); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| static void printString(string & res, const string & s) | static void printString(string & res, const string & s) | ||||||
| { | { | ||||||
|     res += '"'; |     res += '"'; | ||||||
|  |  | ||||||
|  | @ -13,20 +13,21 @@ LocalFSStore::LocalFSStore(const Params & params) | ||||||
| 
 | 
 | ||||||
| struct LocalStoreAccessor : public FSAccessor | struct LocalStoreAccessor : public FSAccessor | ||||||
| { | { | ||||||
|     ref<Store> store; |     ref<LocalFSStore> store; | ||||||
| 
 | 
 | ||||||
|     LocalStoreAccessor(ref<Store> store) : store(store) { } |     LocalStoreAccessor(ref<LocalFSStore> store) : store(store) { } | ||||||
| 
 | 
 | ||||||
|     void assertStore(const Path & path) |     Path toRealPath(const Path & path) | ||||||
|     { |     { | ||||||
|         Path storePath = store->toStorePath(path); |         Path storePath = store->toStorePath(path); | ||||||
|         if (!store->isValidPath(storePath)) |         if (!store->isValidPath(storePath)) | ||||||
|             throw Error(format("path ‘%1%’ is not a valid store path") % storePath); |             throw Error(format("path ‘%1%’ is not a valid store path") % storePath); | ||||||
|  |         return store->getRealStoreDir() + std::string(path, store->storeDir.size()); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     FSAccessor::Stat stat(const Path & path) override |     FSAccessor::Stat stat(const Path & path) override | ||||||
|     { |     { | ||||||
|         assertStore(path); |         auto realPath = toRealPath(path); | ||||||
| 
 | 
 | ||||||
|         struct stat st; |         struct stat st; | ||||||
|         if (lstat(path.c_str(), &st)) { |         if (lstat(path.c_str(), &st)) { | ||||||
|  | @ -47,7 +48,7 @@ struct LocalStoreAccessor : public FSAccessor | ||||||
| 
 | 
 | ||||||
|     StringSet readDirectory(const Path & path) override |     StringSet readDirectory(const Path & path) override | ||||||
|     { |     { | ||||||
|         assertStore(path); |         auto realPath = toRealPath(path); | ||||||
| 
 | 
 | ||||||
|         auto entries = nix::readDirectory(path); |         auto entries = nix::readDirectory(path); | ||||||
| 
 | 
 | ||||||
|  | @ -60,20 +61,18 @@ struct LocalStoreAccessor : public FSAccessor | ||||||
| 
 | 
 | ||||||
|     std::string readFile(const Path & path) override |     std::string readFile(const Path & path) override | ||||||
|     { |     { | ||||||
|         assertStore(path); |         return nix::readFile(toRealPath(path)); | ||||||
|         return nix::readFile(path); |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     std::string readLink(const Path & path) override |     std::string readLink(const Path & path) override | ||||||
|     { |     { | ||||||
|         assertStore(path); |         return nix::readLink(toRealPath(path)); | ||||||
|         return nix::readLink(path); |  | ||||||
|     } |     } | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| ref<FSAccessor> LocalFSStore::getFSAccessor() | ref<FSAccessor> LocalFSStore::getFSAccessor() | ||||||
| { | { | ||||||
|     return make_ref<LocalStoreAccessor>(ref<Store>(shared_from_this())); |     return make_ref<LocalStoreAccessor>(ref<LocalFSStore>(std::dynamic_pointer_cast<LocalFSStore>(shared_from_this()))); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void LocalFSStore::narFromPath(const Path & path, Sink & sink) | void LocalFSStore::narFromPath(const Path & path, Sink & sink) | ||||||
|  |  | ||||||
|  | @ -261,6 +261,8 @@ private: | ||||||
|        specified by the ‘secret-key-files’ option. */ |        specified by the ‘secret-key-files’ option. */ | ||||||
|     void signPathInfo(ValidPathInfo & info); |     void signPathInfo(ValidPathInfo & info); | ||||||
| 
 | 
 | ||||||
|  |     Path getRealStoreDir() override { return realStoreDir; } | ||||||
|  | 
 | ||||||
|     friend class DerivationGoal; |     friend class DerivationGoal; | ||||||
|     friend class SubstitutionGoal; |     friend class SubstitutionGoal; | ||||||
| }; | }; | ||||||
|  |  | ||||||
|  | @ -7,14 +7,6 @@ | ||||||
| namespace nix { | namespace nix { | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| Derivation Store::derivationFromPath(const Path & drvPath) |  | ||||||
| { |  | ||||||
|     assertStorePath(drvPath); |  | ||||||
|     ensurePath(drvPath); |  | ||||||
|     return readDerivation(drvPath); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| void Store::computeFSClosure(const Path & path, | void Store::computeFSClosure(const Path & path, | ||||||
|     PathSet & paths, bool flipDirection, bool includeOutputs, bool includeDerivers) |     PathSet & paths, bool flipDirection, bool includeOutputs, bool includeDerivers) | ||||||
| { | { | ||||||
|  |  | ||||||
|  | @ -501,6 +501,8 @@ public: | ||||||
|     /* Register a permanent GC root. */ |     /* Register a permanent GC root. */ | ||||||
|     Path addPermRoot(const Path & storePath, |     Path addPermRoot(const Path & storePath, | ||||||
|         const Path & gcRoot, bool indirect, bool allowOutsideRootsDir = false); |         const Path & gcRoot, bool indirect, bool allowOutsideRootsDir = false); | ||||||
|  | 
 | ||||||
|  |     virtual Path getRealStoreDir() { return storeDir; } | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue