mirror of
https://github.com/NixOS/nix.git
synced 2025-11-26 04:00: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){
|
if(enableState && !disableState){
|
||||||
Path deriver = queryDeriver(noTxn, outPath); //query deriver
|
Path deriver = queryDeriver(noTxn, outPath); //query deriver
|
||||||
if(deriver != drvPath){
|
if(deriver != drvPath){
|
||||||
printMsg(lvlError, format("Adding to the db: update drv `%2%' with `%1%'") % drvPath % deriver);
|
store->setUpdatedStateDerivation(drvPath, outPath);
|
||||||
store->setUpdatedStateDerivation(drvPath, deriver);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1224,17 +1224,17 @@ PathSet LocalStore::getStateReferencesClosure(const Path & path)
|
||||||
|
|
||||||
|
|
||||||
//TODO
|
//TODO
|
||||||
void setUpdatedStateDerivation(const Path & newdrv, const Path & olddrv)
|
void setUpdatedStateDerivation(const Path & newdrv, const Path & storepath)
|
||||||
{
|
{
|
||||||
Transaction txn(nixDB);
|
Transaction txn(nixDB);
|
||||||
|
|
||||||
Strings data;
|
Strings data;
|
||||||
data.push_back(olddrv);
|
data.push_back(storepath);
|
||||||
|
|
||||||
time_t timestamp;
|
time_t timestamp;
|
||||||
time (×tamp);
|
time (×tamp);
|
||||||
string timestamp_s = time_t2string(timestamp);
|
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
|
data.push_back(timestamp_s); //create a timestamp to remember which one was last inserted
|
||||||
|
|
||||||
nixDB.setStrings(txn, dbUpdatedDerivations, newdrv, data);
|
nixDB.setStrings(txn, dbUpdatedDerivations, newdrv, data);
|
||||||
|
|
@ -1245,54 +1245,65 @@ void setUpdatedStateDerivation(const Path & newdrv, const Path & olddrv)
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO
|
//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
|
//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 drvPath = queryDeriver(txn, storepath);
|
||||||
|
printMsg(lvlError, format("Current DRV: %1%") % drvPath);
|
||||||
|
|
||||||
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 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
|
//Get the (multiple) derivations of references
|
||||||
|
Strings keys;
|
||||||
nixDB.enumTable(txn, dbUpdatedDerivations, keys);
|
nixDB.enumTable(txn, dbUpdatedDerivations, keys);
|
||||||
for (Strings::iterator i = keys.begin(); i != keys.end(); ++i)
|
for (Strings::iterator i = keys.begin(); i != keys.end(); ++i)
|
||||||
{
|
{
|
||||||
string key = *i;
|
string drv_key = *i; //the key is the derivation
|
||||||
printMsg(lvlError, format("getUpdatedStateDerivation KEY: `%1%'") % key);
|
|
||||||
|
|
||||||
Strings data;
|
Strings data;
|
||||||
nixDB.queryStrings(txn, dbUpdatedDerivations, key, data);
|
nixDB.queryStrings(txn, dbUpdatedDerivations, drv_key, data);
|
||||||
for (Strings::iterator j = data.begin(); j != data.end(); ++j)
|
string getstorepath = data.front();
|
||||||
{
|
data.pop_front();
|
||||||
printMsg(lvlError, format("getUpdatedStateDerivation: `%1%'") % *j);
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//Set the current derivation of derivers
|
|
||||||
|
|
||||||
|
|
||||||
//if()
|
|
||||||
// throw Error(format("T derivation: `%1%'") % path);
|
|
||||||
|
|
||||||
txn.commit();
|
txn.commit();
|
||||||
|
return newDerivation;
|
||||||
return p;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO
|
//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);
|
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
|
//TODO
|
||||||
void RemoteStore::setUpdatedStateDerivation(const Path & newdrv, const Path & olddrv)
|
void RemoteStore::setUpdatedStateDerivation(const Path & newdrv, const Path & storepath)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO
|
//TODO
|
||||||
Path RemoteStore::getUpdatedStateDerivation(const Path & olddrv)
|
Path RemoteStore::updateStateDerivation(const Path & storepath)
|
||||||
{
|
{
|
||||||
Path p;
|
Path p;
|
||||||
return p;
|
return p;
|
||||||
|
|
|
||||||
|
|
@ -72,9 +72,9 @@ public:
|
||||||
|
|
||||||
PathSet getStateReferencesClosure(const Path & path);
|
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:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -194,10 +194,10 @@ public:
|
||||||
virtual PathSet getStateReferencesClosure(const Path & path) = 0;
|
virtual PathSet getStateReferencesClosure(const Path & path) = 0;
|
||||||
|
|
||||||
/* TODO */
|
/* TODO */
|
||||||
virtual void setUpdatedStateDerivation(const Path & newdrv, const Path & olddrv) = 0;
|
virtual void setUpdatedStateDerivation(const Path & newdrv, const Path & storepath) = 0;
|
||||||
|
|
||||||
/* TODO */
|
/* 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;
|
Strings opFlags, opArgs;
|
||||||
Operation op = 0;
|
Operation op = 0;
|
||||||
|
|
||||||
|
/* test */
|
||||||
store = openStore();
|
store = openStore();
|
||||||
Path p = "AADOLD";
|
Path p = "/nix/store/l569q3a2cfx834mcf3vhwczjgbaljnp7-hellohardcodedstateworld-1.0";
|
||||||
store->setUpdatedStateDerivation("NEW1", p);
|
store->setUpdatedStateDerivation("/nix/store/63xcbrk3v5nbn9qla7rwnx6rvz3iqm5l-hellohardcodedstateworld-1.0.drv", p);
|
||||||
store->setUpdatedStateDerivation("NEW2", p);
|
store->updateStateDerivation(p);
|
||||||
store->setUpdatedStateDerivation("NEW3", p);
|
|
||||||
store->getUpdatedStateDerivation(p);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
/* test */
|
||||||
|
|
||||||
for (Strings::iterator i = args.begin(); i != args.end(); ) {
|
for (Strings::iterator i = args.begin(); i != args.end(); ) {
|
||||||
string arg = *i++;
|
string arg = *i++;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue