1
1
Fork 0
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:
Wouter den Breejen 2007-06-04 19:41:46 +00:00
parent bcf9d3ab2f
commit 7166ad8eba
7 changed files with 59 additions and 50 deletions

View file

@ -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);
} }
} }

View file

@ -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 (&timestamp); time (&timestamp);
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 storepath = olddrv; //TODO FIX Path drvPath = queryDeriver(txn, storepath);
Path drvPath = getStateDerivation(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
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;
nixDB.queryStrings(txn, dbUpdatedDerivations, key, data);
for (Strings::iterator j = data.begin(); j != data.end(); ++j)
{
printMsg(lvlError, format("getUpdatedStateDerivation: `%1%'") % *j);
}
}
//Set the current derivation of derivers Strings data;
nixDB.queryStrings(txn, dbUpdatedDerivations, drv_key, data);
string getstorepath = data.front();
//if() data.pop_front();
// throw Error(format("T derivation: `%1%'") % path); 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(); 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);
} }

View file

@ -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);
}; };

View file

@ -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;

View file

@ -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:

View file

@ -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;
}; };

View file

@ -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++;