mirror of
https://github.com/NixOS/nix.git
synced 2025-11-26 12:10:59 +01:00
Completed updateStateDerivation(Path storepath) method
This commit is contained in:
parent
bcf9d3ab2f
commit
7166ad8eba
7 changed files with 59 additions and 50 deletions
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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++;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue