From 0e41b191bf5b7bf2e16d6bd0adebcffdfadc0756 Mon Sep 17 00:00:00 2001 From: Wouter den Breejen Date: Thu, 21 Jun 2007 16:47:48 +0000 Subject: [PATCH] --- src/libexpr/get-drvs.hh | 2 +- src/libexpr/primops.cc | 21 ++++++++++++--------- src/libstore/build.cc | 8 +++++--- src/libstore/derivations.cc | 7 ++----- src/libstore/local-store.cc | 22 +++++++++++----------- src/libstore/local-store.hh | 2 +- src/libstore/remote-store.cc | 3 +-- src/libstore/remote-store.hh | 2 +- src/libstore/store-api.cc | 6 +----- src/libstore/store-api.hh | 4 ++-- src/nix-env/nix-env.cc | 7 ++++--- src/nix-worker/nix-worker.cc | 3 +-- 12 files changed, 42 insertions(+), 45 deletions(-) diff --git a/src/libexpr/get-drvs.hh b/src/libexpr/get-drvs.hh index 920197d1f..24894efdc 100644 --- a/src/libexpr/get-drvs.hh +++ b/src/libexpr/get-drvs.hh @@ -44,7 +44,7 @@ public: { outPath = s; } - + void setMetaInfo(const MetaInfo & meta); }; diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index c344e5581..7c38926eb 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -350,7 +350,7 @@ static Hash hashDerivationModulo(EvalState & state, Derivation drv) if(drvso.runtimeStateParamters != ""){ //Has runtime parameters --> Clear all state parameters drv.stateOutputs.clear(); drv.stateOutputDirs.clear(); - drv.env["statepath"] = ""; + drv.env["statePath"] = ""; } else{ //Has NO runtime parameters --> Clear state parameters selectively drvso.clearAllRuntimeParamters(); @@ -617,14 +617,15 @@ static Expr prim_derivationStrict(EvalState & state, const ATermVector & args) //printMsg(lvlError, format("DerivationOutput %1% %2% %3%") % outPath % outputHashAlgo % outputHash); //only add state when we have to to keep compitibilty with the 'old' format. //We add state when it's enbaled by the keywords, and not excplicitly disabled by the user + Path stateOutPath; if(enableState && !disableState){ /* Add the state path based on the outPath * * NOTE: we do not include the username into the hash calculation of the statepath yet, multiple different users can use the same dervation * but need different state paths. Thats why we keep a 'dummy' value e.g. global hash for everyone, and later at build time recalculate the real state path */ - Path stateOutPath = makeStatePath(printHash(componentHash), drvName, stateIdentifier); //State path - drv.env["statepath"] = stateOutPath; + stateOutPath = makeStatePath(printHash(componentHash), drvName, stateIdentifier); //State path + drv.env["statePath"] = stateOutPath; string enableStateS = bool2string("true"); string createDirsBeforeInstallS = bool2string(createDirsBeforeInstall); @@ -659,10 +660,10 @@ static Expr prim_derivationStrict(EvalState & state, const ATermVector & args) /* !!! assumes a single output */ ATermMap outAttrs(2); - outAttrs.set(toATerm("outPath"), - makeAttrRHS(makeStr(outPath, singleton(drvPath)), makeNoPos())); - outAttrs.set(toATerm("drvPath"), - makeAttrRHS(makeStr(drvPath, singleton(drvPath)), makeNoPos())); + outAttrs.set(toATerm("outPath"), makeAttrRHS(makeStr(outPath, singleton(drvPath)), makeNoPos())); + outAttrs.set(toATerm("drvPath"), makeAttrRHS(makeStr(drvPath, singleton(drvPath)), makeNoPos())); + if(enableState && !disableState) + outAttrs.set(toATerm("statePath"), makeAttrRHS(makeStr(stateOutPath, singleton(drvPath)), makeNoPos())); return makeAttrs(outAttrs); } @@ -683,6 +684,8 @@ static Expr prim_derivationLazy(EvalState & state, const ATermVector & args) makeAttrRHS(makeSelect(drvStrict, toATerm("outPath")), makeNoPos())); attrs.set(toATerm("drvPath"), makeAttrRHS(makeSelect(drvStrict, toATerm("drvPath")), makeNoPos())); + attrs.set(toATerm("statePath"), //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! add a state check ! + makeAttrRHS(makeSelect(drvStrict, toATerm("statePath")), makeNoPos())); return makeAttrs(attrs); } @@ -769,8 +772,8 @@ static Expr prim_toFile(EvalState & state, const ATermVector & args) } Path storePath = readOnlyMode - ? computeStorePathForText(name, contents, refs, stateRefs) - : store->addTextToStore(name, contents, refs, stateRefs); + ? computeStorePathForText(name, contents, refs) + : store->addTextToStore(name, contents, refs); /* Note: we don't need to add `context' to the context of the result, since `storePath' itself has references to the paths diff --git a/src/libstore/build.cc b/src/libstore/build.cc index a9d2aa53c..97580faf2 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -1730,6 +1730,7 @@ void DerivationGoal::computeClosure() The reason that we do the transaction here and not on the fly while we are scanning (above) is so that we don't hold database locks for too long. */ + Transaction txn; createStoreTransaction(txn); for (DerivationOutputs::iterator i = drv.outputs.begin(); @@ -1778,7 +1779,9 @@ void DerivationGoal::computeClosure() //If state is enabled: Seaches for state and component references in the state path if(isStateDrvTxn(txn, drv)){ - Path statePath = drv.stateOutputs.find("state")->second.statepath; + Path statePath = drv.stateOutputs.find("state")->second.statepath; + printMsg(lvlTalkative, format("scanning for component and state references inside `%1%'") % statePath); + PathSet state_references = scanForReferences(statePath, allPaths); PathSet state_stateReferences = scanForStateReferences(statePath, allStatePaths); all_state_references = mergePathSets(all_state_references, mergePathSets(state_references, state_stateReferences)); @@ -1794,8 +1797,7 @@ void DerivationGoal::computeClosure() allStateReferences[path] = all_state_references; } - for (DerivationOutputs::iterator i = drv.outputs.begin(); - i != drv.outputs.end(); ++i) + for (DerivationOutputs::iterator i = drv.outputs.begin(); i != drv.outputs.end(); ++i) { registerValidPath(txn, i->second.path, contentHashes[i->second.path], diff --git a/src/libstore/derivations.cc b/src/libstore/derivations.cc index 25a50c25c..3a8bf284e 100644 --- a/src/libstore/derivations.cc +++ b/src/libstore/derivations.cc @@ -27,14 +27,11 @@ Path writeDerivation(const Derivation & drv, const string & name) (that can be missing (of course) and should not necessarily be held during a garbage collection). */ - //We only need to hash over inputSrcs and inputDrvs (I think ...) - PathSet stateReferences; - string suffix = name + drvExtension; string contents = atPrint(unparseDerivation(drv)); return readOnlyMode - ? computeStorePathForText(suffix, contents, references, stateReferences) - : store->addTextToStore(suffix, contents, references, stateReferences); + ? computeStorePathForText(suffix, contents, references) + : store->addTextToStore(suffix, contents, references); } diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index 818f63a2f..55fe8107e 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -483,8 +483,7 @@ void setDeriver(const Transaction & txn, const Path & storePath, const Path & de if (!isRealisablePath(txn, storePath)) throw Error(format("path `%1%' is not valid") % storePath); - Derivation drv = derivationFromPath(deriver); - if (drv.outputs.size() != 0){ //Redirect if its a state component + if (isStateDrvPathTxn(txn, deriver)){ //Redirect if its a state component addStateDeriver(txn, storePath, deriver); } else{ @@ -787,14 +786,13 @@ void registerValidPath(const Transaction & txn, } -void registerValidPaths(const Transaction & txn, - const ValidPathInfos & infos) +void registerValidPaths(const Transaction & txn, const ValidPathInfos & infos) { PathSet newPaths; for (ValidPathInfos::const_iterator i = infos.begin(); i != infos.end(); ++i) newPaths.insert(i->path); - + for (ValidPathInfos::const_iterator i = infos.begin(); i != infos.end(); ++i) { @@ -804,7 +802,7 @@ void registerValidPaths(const Transaction & txn, setHash(txn, i->path, i->hash); setReferences(txn, i->path, i->references, i->stateReferences); - + /* Check that all referenced paths are also valid (or about to become valid). */ for (PathSet::iterator j = i->references.begin(); @@ -882,10 +880,13 @@ Path LocalStore::addToStore(const Path & _srcPath, bool fixed, } +//Gets all derivations ... Path LocalStore::addTextToStore(const string & suffix, const string & s, - const PathSet & references, const PathSet & stateReferences) + const PathSet & references) { - Path dstPath = computeStorePathForText(suffix, s, references, stateReferences); + Path dstPath = computeStorePathForText(suffix, s, references); + + printMsg(lvlError, format("addTextToStore: %1%") % dstPath); addTempRoot(dstPath); @@ -902,7 +903,7 @@ Path LocalStore::addTextToStore(const string & suffix, const string & s, canonicalisePathMetaData(dstPath); Transaction txn(nixDB); - registerValidPath(txn, dstPath, hashPath(htSHA256, dstPath), references, stateReferences, ""); + registerValidPath(txn, dstPath, hashPath(htSHA256, dstPath), references, PathSet(), ""); //There are no stateReferences in drvs..... so we dont need to register them (I think) txn.commit(); } @@ -1299,8 +1300,7 @@ void verifyStore(bool checkContents) //TODO TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! if (find(references.begin(), references.end(), to) == references.end()) { - printMsg(lvlError, format("adding missing referrer mapping from `%1%' to `%2%'") - % from % to); + printMsg(lvlError, format("adding missing referrer mapping from `%1%' to `%2%'") % from % to); references.insert(to); setReferences(txn, from, references, stateReferences); } diff --git a/src/libstore/local-store.hh b/src/libstore/local-store.hh index 080d466d3..2c349699e 100644 --- a/src/libstore/local-store.hh +++ b/src/libstore/local-store.hh @@ -58,7 +58,7 @@ public: PathFilter & filter = defaultPathFilter); Path addTextToStore(const string & suffix, const string & s, - const PathSet & references, const PathSet & stateReferences); + const PathSet & references); void exportPath(const Path & path, bool sign, Sink & sink); diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc index 09c52454d..3a2f81d95 100644 --- a/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc @@ -250,13 +250,12 @@ Path RemoteStore::addToStore(const Path & _srcPath, bool fixed, Path RemoteStore::addTextToStore(const string & suffix, const string & s, - const PathSet & references, const PathSet & stateReferences) + const PathSet & references) { writeInt(wopAddTextToStore, to); writeString(suffix, to); writeString(s, to); writeStringSet(references, to); - writeStringSet(stateReferences, to); processStderr(); Path path = readStorePath(from); diff --git a/src/libstore/remote-store.hh b/src/libstore/remote-store.hh index 95589bead..aea1308e1 100644 --- a/src/libstore/remote-store.hh +++ b/src/libstore/remote-store.hh @@ -46,7 +46,7 @@ public: PathFilter & filter = defaultPathFilter); Path addTextToStore(const string & suffix, const string & s, - const PathSet & references, const PathSet & stateReferences); + const PathSet & references); void exportPath(const Path & path, bool sign, Sink & sink); diff --git a/src/libstore/store-api.cc b/src/libstore/store-api.cc index d6efcfd4a..2a5114738 100644 --- a/src/libstore/store-api.cc +++ b/src/libstore/store-api.cc @@ -179,7 +179,7 @@ std::pair computeStorePathForPath(const Path & srcPath, Path computeStorePathForText(const string & suffix, const string & s, - const PathSet & references, const PathSet & stateReferences) + const PathSet & references) { Hash hash = hashString(htSHA256, s); /* Stuff the references (if any) into the type. This is a bit @@ -190,10 +190,6 @@ Path computeStorePathForText(const string & suffix, const string & s, type += ":"; type += *i; } - for (PathSet::const_iterator i = stateReferences.begin(); i != stateReferences.end(); ++i) { - type += ":"; - type += *i; - } return makeStorePath(type, hash, suffix); } diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index f7b34fc68..e08af96bb 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -100,7 +100,7 @@ public: /* Like addToStore, but the contents written to the output path is a regular file containing the given string. */ virtual Path addTextToStore(const string & suffix, const string & s, - const PathSet & references, const PathSet & stateReferences) = 0; + const PathSet & references) = 0; /* Export a store path, that is, create a NAR dump of the store path and append its references and its deriver. Optionally, a @@ -264,7 +264,7 @@ std::pair computeStorePathForPath(const Path & srcPath, affected), but it has some backwards compatibility issues (the hashing scheme changes), so I'm not doing that for now. */ Path computeStorePathForText(const string & suffix, const string & s, - const PathSet & references, const PathSet & stateReferences); + const PathSet & references); /* Remove the temporary roots file for this process. Any temporary diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc index a83090028..3e64d36fe 100644 --- a/src/nix-env/nix-env.cc +++ b/src/nix-env/nix-env.cc @@ -159,7 +159,6 @@ static void createUserEnv(EvalState & state, const DrvInfos & elems, /* Construct the whole top level derivation. */ PathSet references; - PathSet stateReferences; //TODO TODO TODO TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ATermList manifest = ATempty; ATermList inputs = ATempty; for (DrvInfos::const_iterator i = elems.begin(); @@ -197,14 +196,13 @@ static void createUserEnv(EvalState & state, const DrvInfos & elems, `nix-env -i /nix/store/abcd...-foo'. */ store->addTempRoot(i->queryOutPath(state)); store->ensurePath(i->queryOutPath(state)); - references.insert(i->queryOutPath(state)); if (drvPath != "") references.insert(drvPath); } /* Also write a copy of the list of inputs to the store; we need it for future modifications of the environment. */ - Path manifestFile = store->addTextToStore("env-manifest", atPrint(canonicaliseExpr(makeList(ATreverse(manifest)))), references, stateReferences); + Path manifestFile = store->addTextToStore("env-manifest", atPrint(canonicaliseExpr(makeList(ATreverse(manifest)))), references); Expr topLevel = makeCall(envBuilder, makeAttrs(ATmakeList3( makeBind(toATerm("system"), @@ -379,6 +377,9 @@ static void queryInstSources(EvalState & state, if (isDerivation(*i)) { elem.setDrvPath(*i); elem.setOutPath(findOutput(derivationFromPath(*i), "out")); + + //TODO !!!!!!!!!!!!!!!!!!!! setStatePath?? + if (name.size() >= drvExtension.size() && string(name, name.size() - drvExtension.size()) == drvExtension) name = string(name, 0, name.size() - drvExtension.size()); diff --git a/src/nix-worker/nix-worker.cc b/src/nix-worker/nix-worker.cc index f7bda6e0d..4b16b7519 100644 --- a/src/nix-worker/nix-worker.cc +++ b/src/nix-worker/nix-worker.cc @@ -315,9 +315,8 @@ static void performOp(Source & from, Sink & to, unsigned int op) string suffix = readString(from); string s = readString(from); PathSet refs = readStorePaths(from); - PathSet stateRefs; //TODO TODO TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! startWork(); - Path path = store->addTextToStore(suffix, s, refs, stateRefs); + Path path = store->addTextToStore(suffix, s, refs); stopWork(); writeString(path, to); break;