diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc index 0a6ebcd5c..eb0b53628 100644 --- a/src/libmain/shared.cc +++ b/src/libmain/shared.cc @@ -139,6 +139,10 @@ static void initAndRun(int argc, char * * argv) /* ATerm stuff. !!! find a better place to put this */ initDerivationsHelpers(); + + /* Random number generator needed by makeRandomStorePath(); !!! + improve. */ + srand(time(0)); /* Put the arguments in a vector. */ Strings args, remaining; diff --git a/src/libstore/build.cc b/src/libstore/build.cc index 0b32641f0..f08e4a4d7 100644 --- a/src/libstore/build.cc +++ b/src/libstore/build.cc @@ -914,7 +914,7 @@ bool DerivationGoal::prepareBuild() rewrites[hashPartOf(i->second.eqClass)] = hashPartOf(tmpPath); tmpOutputs[i->second.eqClass] = tmpPath; } - + /* Obtain locks on all output paths. The locks are automatically released when we exit this function or Nix crashes. */ /* !!! BUG: this could block, which is not allowed. */ @@ -959,6 +959,7 @@ bool DerivationGoal::prepareBuild() debug(format("building path `%1%'") % i->second.path); allPaths.insert(i->second.path); } +#endif /* Determine the full set of input paths. */ @@ -973,9 +974,25 @@ bool DerivationGoal::prepareBuild() Derivation inDrv = derivationFromPath(i->first); for (StringSet::iterator j = i->second.begin(); j != i->second.end(); ++j) - if (inDrv.outputs.find(*j) != inDrv.outputs.end()) + + if (inDrv.outputs.find(*j) != inDrv.outputs.end()) { + + OutputEqClass eqClass = inDrv.outputs[*j].eqClass; + OutputEqMembers members; + queryOutputEqMembers(noTxn, eqClass, members); + + if (members.size() == 0) + throw Error(format("output equivalence class `%1%' has no members!") + % eqClass); + + Path input = members.front().path; + + rewrites[hashPartOf(eqClass)] = hashPartOf(input); + +#if 0 computeFSClosure(inDrv.outputs[*j].path, inputPaths); - else +#endif + } else throw Error( format("derivation `%1%' requires non-existent output `%2%' from input derivation `%3%'") % drvPath % *j % i->first); @@ -989,7 +1006,6 @@ bool DerivationGoal::prepareBuild() debug(format("added input paths %1%") % showPaths(inputPaths)); allPaths.insert(inputPaths.begin(), inputPaths.end()); -#endif return true; } @@ -1144,6 +1160,15 @@ void DerivationGoal::computeClosure() Path finalPath = addToStore(i->second, hashPartOf(i->second), namePartOf(i->second)); printMsg(lvlError, format("produced final path `%1%'") % finalPath); + + /* Register the fact that this output path is a member of some + output path equivalence class (for a certain user, at + least). This is how subsequent derivations will be able to + find it. */ + Transaction txn; + createStoreTransaction(txn); + addOutputEqMember(txn, i->first, "root", finalPath); + txn.commit(); } #if 0 diff --git a/src/libstore/store.cc b/src/libstore/store.cc index 0cba16b6d..fb9196db8 100644 --- a/src/libstore/store.cc +++ b/src/libstore/store.cc @@ -448,10 +448,52 @@ void queryReferers(const Transaction & txn, } +void addOutputEqMember(const Transaction & txn, + const OutputEqClass & eqClass, const TrustId & trustId, + const Path & path) +{ + OutputEqMembers members; + queryOutputEqMembers(txn, eqClass, members); + + for (OutputEqMembers::iterator i = members.begin(); + i != members.end(); ++i) + if (i->trustId == trustId && i->path == path) return; + + OutputEqMember member; + member.trustId = trustId; + member.path = path; + members.push_back(member); + + Strings ss; + + for (OutputEqMembers::iterator i = members.begin(); + i != members.end(); ++i) + { + Strings ss2; + ss2.push_back(i->trustId); + ss2.push_back(i->path); + ss.push_back(packStrings(ss2)); + } + + nixDB.setStrings(txn, dbEquivalences, eqClass, ss); +} + + void queryOutputEqMembers(const Transaction & txn, const OutputEqClass & eqClass, OutputEqMembers & members) { - assert(0); + Strings ss; + nixDB.queryStrings(txn, dbEquivalences, eqClass, ss); + + for (Strings::iterator i = ss.begin(); i != ss.end(); ++i) { + Strings ss2 = unpackStrings(*i); + if (ss2.size() != 2) continue; + Strings::iterator j = ss2.begin(); + OutputEqMember member; + member.trustId = *j++; + member.path = *j++; + members.push_back(member); + } } diff --git a/src/libstore/store.hh b/src/libstore/store.hh index da5769bef..6d14e6ea9 100644 --- a/src/libstore/store.hh +++ b/src/libstore/store.hh @@ -187,6 +187,10 @@ void queryReferences(const Transaction & txn, void queryReferers(const Transaction & txn, const Path & storePath, PathSet & referers); +void addOutputEqMember(const Transaction & txn, + const OutputEqClass & eqClass, const TrustId & trustId, + const Path & path); + void queryOutputEqMembers(const Transaction & txn, const OutputEqClass & eqClass, OutputEqMembers & members);