* Merge addToStore and addToStoreFixed.
* addToStore now adds unconditionally, it doesn't use readOnlyMode. Read-only operation is up to the caller (who can call computeStorePathForPath).
This commit is contained in:
		
							parent
							
								
									ceb982a1be
								
							
						
					
					
						commit
						a824d58b56
					
				
					 11 changed files with 40 additions and 96 deletions
				
			
		|  | @ -2,5 +2,3 @@ SUBDIRS = bin2c boost libutil libstore libmain nix-store nix-hash \ | ||||||
|  libexpr nix-instantiate nix-env nix-worker nix-log2xml bsdiff-4.3 |  libexpr nix-instantiate nix-env nix-worker nix-log2xml bsdiff-4.3 | ||||||
| 
 | 
 | ||||||
| EXTRA_DIST = aterm-helper.pl | EXTRA_DIST = aterm-helper.pl | ||||||
| 
 |  | ||||||
| #SETUID_PROGS = nix-store nix-instantiate nix-env |  | ||||||
|  |  | ||||||
|  | @ -5,6 +5,7 @@ | ||||||
| #include "store-api.hh" | #include "store-api.hh" | ||||||
| #include "derivations.hh" | #include "derivations.hh" | ||||||
| #include "nixexpr-ast.hh" | #include "nixexpr-ast.hh" | ||||||
|  | #include "globals.hh" | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| namespace nix { | namespace nix { | ||||||
|  | @ -251,7 +252,9 @@ string coerceToString(EvalState & state, Expr e, PathSet & context, | ||||||
|         if (state.srcToStore[path] != "") |         if (state.srcToStore[path] != "") | ||||||
|             dstPath = state.srcToStore[path]; |             dstPath = state.srcToStore[path]; | ||||||
|         else { |         else { | ||||||
|             dstPath = store->addToStore(path); |             dstPath = readOnlyMode | ||||||
|  |                 ? computeStorePathForPath(path).first | ||||||
|  |                 : store->addToStore(path); | ||||||
|             state.srcToStore[path] = dstPath; |             state.srcToStore[path] = dstPath; | ||||||
|             printMsg(lvlChatty, format("copied source `%1%' -> `%2%'") |             printMsg(lvlChatty, format("copied source `%1%' -> `%2%'") | ||||||
|                 % path % dstPath); |                 % path % dstPath); | ||||||
|  |  | ||||||
|  | @ -619,20 +619,20 @@ static void invalidatePath(Transaction & txn, const Path & path) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| Path LocalStore::_addToStore(bool fixed, bool recursive, | Path LocalStore::addToStore(const Path & _srcPath, bool fixed, | ||||||
|     string hashAlgo, const Path & _srcPath) |     bool recursive, string hashAlgo) | ||||||
| { | { | ||||||
|     Path srcPath(absPath(_srcPath)); |     Path srcPath(absPath(_srcPath)); | ||||||
|     debug(format("adding `%1%' to the store") % srcPath); |     debug(format("adding `%1%' to the store") % srcPath); | ||||||
| 
 | 
 | ||||||
|     std::pair<Path, Hash> pr = |     std::pair<Path, Hash> pr = | ||||||
|         computeStorePathForPath(fixed, recursive, hashAlgo, srcPath); |         computeStorePathForPath(srcPath, fixed, recursive, hashAlgo); | ||||||
|     Path & dstPath(pr.first); |     Path & dstPath(pr.first); | ||||||
|     Hash & h(pr.second); |     Hash & h(pr.second); | ||||||
| 
 | 
 | ||||||
|     if (!readOnlyMode) addTempRoot(dstPath); |     addTempRoot(dstPath); | ||||||
| 
 | 
 | ||||||
|     if (!readOnlyMode && !isValidPath(dstPath)) { |     if (!isValidPath(dstPath)) { | ||||||
| 
 | 
 | ||||||
|         /* The first check above is an optimisation to prevent
 |         /* The first check above is an optimisation to prevent
 | ||||||
|            unnecessary lock acquisition. */ |            unnecessary lock acquisition. */ | ||||||
|  | @ -664,26 +664,14 @@ Path LocalStore::_addToStore(bool fixed, bool recursive, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| Path LocalStore::addToStore(const Path & srcPath) |  | ||||||
| { |  | ||||||
|     return _addToStore(false, false, "", srcPath); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| Path LocalStore::addToStoreFixed(bool recursive, string hashAlgo, const Path & srcPath) |  | ||||||
| { |  | ||||||
|     return _addToStore(true, recursive, hashAlgo, srcPath); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| Path LocalStore::addTextToStore(const string & suffix, const string & s, | Path LocalStore::addTextToStore(const string & suffix, const string & s, | ||||||
|     const PathSet & references) |     const PathSet & references) | ||||||
| { | { | ||||||
|     Path dstPath = computeStorePathForText(suffix, s); |     Path dstPath = computeStorePathForText(suffix, s); | ||||||
|      |      | ||||||
|     if (!readOnlyMode) addTempRoot(dstPath); |     addTempRoot(dstPath); | ||||||
| 
 | 
 | ||||||
|     if (!readOnlyMode && !isValidPath(dstPath)) { |     if (!isValidPath(dstPath)) { | ||||||
| 
 | 
 | ||||||
|         PathLocks outputLock(singleton<PathSet, Path>(dstPath)); |         PathLocks outputLock(singleton<PathSet, Path>(dstPath)); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -45,27 +45,19 @@ public: | ||||||
| 
 | 
 | ||||||
|     Hash queryPathHash(const Path & path); |     Hash queryPathHash(const Path & path); | ||||||
| 
 | 
 | ||||||
|     void queryReferences(const Path & storePath, |     void queryReferences(const Path & path, PathSet & references); | ||||||
|         PathSet & references); |  | ||||||
| 
 | 
 | ||||||
|     void queryReferrers(const Path & storePath, |     void queryReferrers(const Path & path, PathSet & referrers); | ||||||
|         PathSet & referrers); |  | ||||||
| 
 | 
 | ||||||
|     Path addToStore(const Path & srcPath); |     Path addToStore(const Path & srcPath, bool fixed = false, | ||||||
| 
 |         bool recursive = false, string hashAlgo = ""); | ||||||
|     Path addToStoreFixed(bool recursive, string hashAlgo, |  | ||||||
|         const Path & srcPath); |  | ||||||
| 
 | 
 | ||||||
|     Path addTextToStore(const string & suffix, const string & s, |     Path addTextToStore(const string & suffix, const string & s, | ||||||
|         const PathSet & references); |         const PathSet & references); | ||||||
| 
 | 
 | ||||||
|     void buildDerivations(const PathSet & drvPaths); |     void buildDerivations(const PathSet & drvPaths); | ||||||
| 
 | 
 | ||||||
|     void ensurePath(const Path & storePath); |     void ensurePath(const Path & path); | ||||||
| 
 |  | ||||||
| private: |  | ||||||
|     Path _addToStore(bool fixed, bool recursive, |  | ||||||
|         string hashAlgo, const Path & _srcPath); |  | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | @ -120,16 +112,16 @@ bool isValidPathTxn(const Transaction & txn, const Path & path); | ||||||
| 
 | 
 | ||||||
| /* Sets the set of outgoing FS references for a store path.  Use with
 | /* Sets the set of outgoing FS references for a store path.  Use with
 | ||||||
|    care! */ |    care! */ | ||||||
| void setReferences(const Transaction & txn, const Path & storePath, | void setReferences(const Transaction & txn, const Path & path, | ||||||
|     const PathSet & references); |     const PathSet & references); | ||||||
| 
 | 
 | ||||||
| /* Sets the deriver of a store path.  Use with care! */ | /* Sets the deriver of a store path.  Use with care! */ | ||||||
| void setDeriver(const Transaction & txn, const Path & storePath, | void setDeriver(const Transaction & txn, const Path & path, | ||||||
|     const Path & deriver); |     const Path & deriver); | ||||||
| 
 | 
 | ||||||
| /* Query the deriver of a store path.  Return the empty string if no
 | /* Query the deriver of a store path.  Return the empty string if no
 | ||||||
|    deriver has been set. */ |    deriver has been set. */ | ||||||
| Path queryDeriver(const Transaction & txn, const Path & storePath); | Path queryDeriver(const Transaction & txn, const Path & path); | ||||||
| 
 | 
 | ||||||
| /* Delete a value from the nixStore directory. */ | /* Delete a value from the nixStore directory. */ | ||||||
| void deleteFromStore(const Path & path, unsigned long long & bytesFreed); | void deleteFromStore(const Path & path, unsigned long long & bytesFreed); | ||||||
|  |  | ||||||
|  | @ -3,7 +3,6 @@ | ||||||
| #include "remote-store.hh" | #include "remote-store.hh" | ||||||
| #include "worker-protocol.hh" | #include "worker-protocol.hh" | ||||||
| #include "archive.hh" | #include "archive.hh" | ||||||
| #include "globals.hh" |  | ||||||
| 
 | 
 | ||||||
| #include <iostream> | #include <iostream> | ||||||
| #include <unistd.h> | #include <unistd.h> | ||||||
|  | @ -123,33 +122,14 @@ void RemoteStore::queryReferrers(const Path & path, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| Path RemoteStore::addToStore(const Path & srcPath) | Path RemoteStore::addToStore(const Path & _srcPath, bool fixed, | ||||||
|  |     bool recursive, string hashAlgo) | ||||||
| { | { | ||||||
|     if (readOnlyMode) { |     Path srcPath(absPath(_srcPath)); | ||||||
|         /* No sense in making a round trip, we can just compute the
 |  | ||||||
|            path here. */ |  | ||||||
|         return computeStorePathForPath(false, false, "", srcPath).first; |  | ||||||
|     } |  | ||||||
|      |      | ||||||
|     writeInt(wopAddToStore, to); |     writeInt(wopAddToStore, to); | ||||||
|     writeString(baseNameOf(srcPath), to); |     writeString(baseNameOf(srcPath), to); | ||||||
|     dumpPath(srcPath, to); |     writeInt(fixed ? 1 : 0, to); | ||||||
|     Path path = readString(from); |  | ||||||
|     return path; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| Path RemoteStore::addToStoreFixed(bool recursive, string hashAlgo, |  | ||||||
|     const Path & srcPath) |  | ||||||
| { |  | ||||||
|     if (readOnlyMode) { |  | ||||||
|         /* No sense in making a round trip, we can just compute the
 |  | ||||||
|            path here. */ |  | ||||||
|         return computeStorePathForPath(true, recursive, hashAlgo, srcPath).first; |  | ||||||
|     } |  | ||||||
|      |  | ||||||
|     writeInt(wopAddToStoreFixed, to); |  | ||||||
|     writeString(baseNameOf(srcPath), to); |  | ||||||
|     writeInt(recursive ? 1 : 0, to); |     writeInt(recursive ? 1 : 0, to); | ||||||
|     writeString(hashAlgo, to); |     writeString(hashAlgo, to); | ||||||
|     dumpPath(srcPath, to); |     dumpPath(srcPath, to); | ||||||
|  | @ -161,10 +141,6 @@ Path RemoteStore::addToStoreFixed(bool recursive, string hashAlgo, | ||||||
| Path RemoteStore::addTextToStore(const string & suffix, const string & s, | Path RemoteStore::addTextToStore(const string & suffix, const string & s, | ||||||
|     const PathSet & references) |     const PathSet & references) | ||||||
| { | { | ||||||
|     if (readOnlyMode) { |  | ||||||
|         return computeStorePathForText(suffix, s); |  | ||||||
|     } |  | ||||||
|      |  | ||||||
|     writeInt(wopAddTextToStore, to); |     writeInt(wopAddTextToStore, to); | ||||||
|     writeString(suffix, to); |     writeString(suffix, to); | ||||||
|     writeString(s, to); |     writeString(s, to); | ||||||
|  |  | ||||||
|  | @ -37,10 +37,8 @@ public: | ||||||
| 
 | 
 | ||||||
|     void queryReferrers(const Path & path, PathSet & referrers); |     void queryReferrers(const Path & path, PathSet & referrers); | ||||||
| 
 | 
 | ||||||
|     Path addToStore(const Path & srcPath); |     Path addToStore(const Path & srcPath, bool fixed = false, | ||||||
| 
 |         bool recursive = false, string hashAlgo = ""); | ||||||
|     Path addToStoreFixed(bool recursive, string hashAlgo, |  | ||||||
|         const Path & srcPath); |  | ||||||
| 
 | 
 | ||||||
|     Path addTextToStore(const string & suffix, const string & s, |     Path addTextToStore(const string & suffix, const string & s, | ||||||
|         const PathSet & references); |         const PathSet & references); | ||||||
|  |  | ||||||
|  | @ -93,8 +93,8 @@ Path makeFixedOutputPath(bool recursive, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| std::pair<Path, Hash> computeStorePathForPath(bool fixed, bool recursive, | std::pair<Path, Hash> computeStorePathForPath(const Path & srcPath, | ||||||
|     string hashAlgo, const Path & srcPath) |     bool fixed, bool recursive, string hashAlgo) | ||||||
| { | { | ||||||
|     Hash h(htSHA256); |     Hash h(htSHA256); | ||||||
|     { |     { | ||||||
|  |  | ||||||
|  | @ -63,14 +63,11 @@ public: | ||||||
|         PathSet & referrers) = 0; |         PathSet & referrers) = 0; | ||||||
| 
 | 
 | ||||||
|     /* Copy the contents of a path to the store and register the
 |     /* Copy the contents of a path to the store and register the
 | ||||||
|        validity the resulting path.  The resulting path is |        validity the resulting path.  The resulting path is returned. | ||||||
|        returned. */ |        If `fixed' is true, then the output of a fixed-output | ||||||
|     virtual Path addToStore(const Path & srcPath) = 0; |        derivation is pre-loaded into the Nix store. */ | ||||||
| 
 |     virtual Path addToStore(const Path & srcPath, bool fixed = false, | ||||||
|     /* Like addToStore(), but for pre-adding the outputs of
 |         bool recursive = false, string hashAlgo = "") = 0; | ||||||
|        fixed-output derivations. */ |  | ||||||
|     virtual Path addToStoreFixed(bool recursive, string hashAlgo, |  | ||||||
|         const Path & srcPath) = 0; |  | ||||||
| 
 | 
 | ||||||
|     /* Like addToStore, but the contents written to the output path is
 |     /* Like addToStore, but the contents written to the output path is
 | ||||||
|        a regular file containing the given string. */ |        a regular file containing the given string. */ | ||||||
|  | @ -119,8 +116,8 @@ Path makeFixedOutputPath(bool recursive, | ||||||
|    it computes the store path to which srcPath is to be copied. |    it computes the store path to which srcPath is to be copied. | ||||||
|    Returns the store path and the cryptographic hash of the |    Returns the store path and the cryptographic hash of the | ||||||
|    contents of srcPath. */ |    contents of srcPath. */ | ||||||
| std::pair<Path, Hash> computeStorePathForPath(bool fixed, bool recursive, | std::pair<Path, Hash> computeStorePathForPath(const Path & srcPath, | ||||||
|     string hashAlgo, const Path & srcPath); |     bool fixed = false, bool recursive = false, string hashAlgo = ""); | ||||||
| 
 | 
 | ||||||
| /* Preparatory part of addTextToStore().
 | /* Preparatory part of addTextToStore().
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -15,7 +15,6 @@ typedef enum { | ||||||
|     wopQueryReferences, |     wopQueryReferences, | ||||||
|     wopQueryReferrers, |     wopQueryReferrers, | ||||||
|     wopAddToStore, |     wopAddToStore, | ||||||
|     wopAddToStoreFixed, |  | ||||||
|     wopAddTextToStore, |     wopAddTextToStore, | ||||||
|     wopBuildDerivations, |     wopBuildDerivations, | ||||||
|     wopEnsurePath, |     wopEnsurePath, | ||||||
|  |  | ||||||
|  | @ -133,7 +133,7 @@ static void opAddFixed(Strings opFlags, Strings opArgs) | ||||||
|     opArgs.pop_front(); |     opArgs.pop_front(); | ||||||
| 
 | 
 | ||||||
|     for (Strings::iterator i = opArgs.begin(); i != opArgs.end(); ++i) |     for (Strings::iterator i = opArgs.begin(); i != opArgs.end(); ++i) | ||||||
|         cout << format("%1%\n") % store->addToStoreFixed(recursive, hashAlgo, *i); |         cout << format("%1%\n") % store->addToStore(*i, true, recursive, hashAlgo); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -79,25 +79,18 @@ void processConnection(Source & from, Sink & to) | ||||||
|             break; |             break; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         case wopAddToStore: |         case wopAddToStore: { | ||||||
|         case wopAddToStoreFixed: { |  | ||||||
|             /* !!! uberquick hack */ |             /* !!! uberquick hack */ | ||||||
|             string baseName = readString(from); |             string baseName = readString(from); | ||||||
|             bool recursive = false; |             bool fixed = readInt(from) == 1; | ||||||
|             string hashAlgo; |             bool recursive = readInt(from) == 1; | ||||||
|             if (op == wopAddToStoreFixed) { |             string hashAlgo = readString(from); | ||||||
|                 recursive = readInt(from) == 1; |  | ||||||
|                 hashAlgo = readString(from); |  | ||||||
|             } |  | ||||||
| 
 | 
 | ||||||
|             Path tmp = createTempDir(); |             Path tmp = createTempDir(); | ||||||
|             Path tmp2 = tmp + "/" + baseName; |             Path tmp2 = tmp + "/" + baseName; | ||||||
|             restorePath(tmp2, from); |             restorePath(tmp2, from); | ||||||
| 
 | 
 | ||||||
|             if (op == wopAddToStoreFixed) |             writeString(store->addToStore(tmp2, fixed, recursive, hashAlgo), to); | ||||||
|                 writeString(store->addToStoreFixed(recursive, hashAlgo, tmp2), to); |  | ||||||
|             else |  | ||||||
|                 writeString(store->addToStore(tmp2), to); |  | ||||||
|              |              | ||||||
|             deletePath(tmp); |             deletePath(tmp); | ||||||
|             break; |             break; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue