diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index d5518859e..65b766796 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -623,8 +623,7 @@ static Expr prim_derivationStrict(EvalState & state, const ATermVector & args) if(enableState && !disableState){ Path deriver = queryDeriver(noTxn, outPath); //query deriver if(deriver != drvPath){ - printMsg(lvlError, format("Adding to the db: update drv `%2%' with `%1%'") % drvPath % deriver); - store->setUpdatedStateDerivation(drvPath, deriver); + store->setUpdatedStateDerivation(drvPath, outPath); } } diff --git a/src/libstore/local-store.cc b/src/libstore/local-store.cc index c3ac233c9..08e2fad67 100644 --- a/src/libstore/local-store.cc +++ b/src/libstore/local-store.cc @@ -1224,17 +1224,17 @@ PathSet LocalStore::getStateReferencesClosure(const Path & path) //TODO -void setUpdatedStateDerivation(const Path & newdrv, const Path & olddrv) +void setUpdatedStateDerivation(const Path & newdrv, const Path & storepath) { Transaction txn(nixDB); - + Strings data; - data.push_back(olddrv); + data.push_back(storepath); time_t timestamp; time (×tamp); string timestamp_s = time_t2string(timestamp); - printMsg(lvlError, format("Adding new drv (%1%) to replace old drv (%2%) with timestamp: %3%") % newdrv % olddrv % timestamp_s); + printMsg(lvlError, format("Adding new drv (%1%) to replace drv of old component (%2%) with timestamp: %3%") % newdrv % storepath % timestamp_s); data.push_back(timestamp_s); //create a timestamp to remember which one was last inserted nixDB.setStrings(txn, dbUpdatedDerivations, newdrv, data); @@ -1245,54 +1245,65 @@ void setUpdatedStateDerivation(const Path & newdrv, const Path & olddrv) } //TODO -void LocalStore::setUpdatedStateDerivation(const Path & newdrv, const Path & olddrv) +void LocalStore::setUpdatedStateDerivation(const Path & newdrv, const Path & storepath) { - nix::setUpdatedStateDerivation(newdrv, olddrv); + nix::setUpdatedStateDerivation(newdrv, storepath); } //TODO -Path getUpdatedStateDerivation(const Path & olddrv) //TODO Path updateStateDerivationPath(const Path & storepath) +Path updateStateDerivation(const Path & storepath) { - Transaction txn(nixDB); //TODO should u do a transaction here? ... this might delay the process ... + Transaction txn(nixDB); - Path storepath = olddrv; //TODO FIX - Path drvPath = getStateDerivation(storepath); - Path newDerivation = drvPath; //the new drv path first equals the old one until a new one is found + Path drvPath = queryDeriver(txn, storepath); + printMsg(lvlError, format("Current DRV: %1%") % drvPath); + + Path newDerivation = drvPath; //the new drv path first equals the old one until a new one is found + int timestamp = 0; - Strings keys; - //Get the (multiple) derivations of references + Strings keys; nixDB.enumTable(txn, dbUpdatedDerivations, keys); for (Strings::iterator i = keys.begin(); i != keys.end(); ++i) { - string key = *i; - printMsg(lvlError, format("getUpdatedStateDerivation KEY: `%1%'") % key); - - Strings data; - nixDB.queryStrings(txn, dbUpdatedDerivations, key, data); - for (Strings::iterator j = data.begin(); j != data.end(); ++j) - { - printMsg(lvlError, format("getUpdatedStateDerivation: `%1%'") % *j); - } - } - - + string drv_key = *i; //the key is the derivation - //Set the current derivation of derivers - - - //if() - // throw Error(format("T derivation: `%1%'") % path); + Strings data; + nixDB.queryStrings(txn, dbUpdatedDerivations, drv_key, data); + string getstorepath = data.front(); + data.pop_front(); + string gettimestamp = data.front(); + + if(storepath == getstorepath){ + + int gettimestamp_i; + string2Int(gettimestamp, gettimestamp_i); + + if(gettimestamp_i == timestamp) + throw Error(format("Error! Multiple changes at the same time of derivation: `%1%' with timestamp") % drv_key); //TODO delete the mulitple changes ?? + + if(timestamp == 0 || gettimestamp_i > timestamp){ //we choose the new derivation as the latest submitted derivation + printMsg(lvlError, format("Replacing old drv (%1%) with new drv (%2%) with timestamp: %3%") % newDerivation % drv_key % gettimestamp_i); + newDerivation = drv_key; + timestamp = gettimestamp_i; + + //Replace the old deriver link in the derivers database (TODO, and delete old deriver path????????) + setDeriver(txn, storepath, newDerivation); + } + + //Always Remove the old updatelink in the dbUpdatedDerivations + nixDB.delPair(txn, dbUpdatedDerivations, drv_key); + } + } txn.commit(); - - return p; + return newDerivation; } //TODO -Path LocalStore::getUpdatedStateDerivation(const Path & olddrv) +Path LocalStore::updateStateDerivation(const Path & storepath) { - return nix::getUpdatedStateDerivation(olddrv); + return nix::updateStateDerivation(storepath); } diff --git a/src/libstore/local-store.hh b/src/libstore/local-store.hh index 05eb14bff..86d66cd52 100644 --- a/src/libstore/local-store.hh +++ b/src/libstore/local-store.hh @@ -84,9 +84,9 @@ public: PathSet getStateReferencesClosure(const Path & path); - void setUpdatedStateDerivation(const Path & newdrv, const Path & olddrv); + void setUpdatedStateDerivation(const Path & newdrv, const Path & storepath); - Path getUpdatedStateDerivation(const Path & olddrv); + Path updateStateDerivation(const Path & storepath); }; diff --git a/src/libstore/remote-store.cc b/src/libstore/remote-store.cc index a57ae839d..dd8d29f6f 100644 --- a/src/libstore/remote-store.cc +++ b/src/libstore/remote-store.cc @@ -403,13 +403,13 @@ PathSet RemoteStore::getStateReferencesClosure(const Path & path) } //TODO -void RemoteStore::setUpdatedStateDerivation(const Path & newdrv, const Path & olddrv) +void RemoteStore::setUpdatedStateDerivation(const Path & newdrv, const Path & storepath) { } //TODO -Path RemoteStore::getUpdatedStateDerivation(const Path & olddrv) +Path RemoteStore::updateStateDerivation(const Path & storepath) { Path p; return p; diff --git a/src/libstore/remote-store.hh b/src/libstore/remote-store.hh index c41c41a1a..9cea22f09 100644 --- a/src/libstore/remote-store.hh +++ b/src/libstore/remote-store.hh @@ -72,9 +72,9 @@ public: PathSet getStateReferencesClosure(const Path & path); - void setUpdatedStateDerivation(const Path & newdrv, const Path & olddrv); + void setUpdatedStateDerivation(const Path & newdrv, const Path & storepath); - Path getUpdatedStateDerivation(const Path & olddrv); + Path updateStateDerivation(const Path & storepath); private: diff --git a/src/libstore/store-api.hh b/src/libstore/store-api.hh index 12492d939..c810778ca 100644 --- a/src/libstore/store-api.hh +++ b/src/libstore/store-api.hh @@ -194,10 +194,10 @@ public: virtual PathSet getStateReferencesClosure(const Path & path) = 0; /* TODO */ - virtual void setUpdatedStateDerivation(const Path & newdrv, const Path & olddrv) = 0; + virtual void setUpdatedStateDerivation(const Path & newdrv, const Path & storepath) = 0; /* TODO */ - virtual Path getUpdatedStateDerivation(const Path & olddrv) = 0; + virtual Path updateStateDerivation(const Path & storepath) = 0; }; diff --git a/src/nix-state/nix-state.cc b/src/nix-state/nix-state.cc index f4565fb40..6ce035542 100644 --- a/src/nix-state/nix-state.cc +++ b/src/nix-state/nix-state.cc @@ -229,14 +229,13 @@ void run(Strings args) Strings opFlags, opArgs; Operation op = 0; + /* test */ store = openStore(); - Path p = "AADOLD"; - store->setUpdatedStateDerivation("NEW1", p); - store->setUpdatedStateDerivation("NEW2", p); - store->setUpdatedStateDerivation("NEW3", p); - store->getUpdatedStateDerivation(p); - + Path p = "/nix/store/l569q3a2cfx834mcf3vhwczjgbaljnp7-hellohardcodedstateworld-1.0"; + store->setUpdatedStateDerivation("/nix/store/63xcbrk3v5nbn9qla7rwnx6rvz3iqm5l-hellohardcodedstateworld-1.0.drv", p); + store->updateStateDerivation(p); return; + /* test */ for (Strings::iterator i = args.begin(); i != args.end(); ) { string arg = *i++;