1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-26 04:00:59 +01:00

Before adjusting getStateReferencesClosure_

This commit is contained in:
Wouter den Breejen 2007-06-13 15:18:57 +00:00
parent bc0af4449a
commit 184443d18d
7 changed files with 144 additions and 43 deletions

View file

@ -639,6 +639,8 @@ static Expr prim_derivationStrict(EvalState & state, const ATermVector & args)
printMsg(lvlChatty, format("instantiated `%1%' -> `%2%'") % drvName % drvPath); printMsg(lvlChatty, format("instantiated `%1%' -> `%2%'") % drvName % drvPath);
//printMsg(lvlError, format("PRIMOPS %1%") % drvPath);
/* Write updated (no need to rebuild) state derivations to the database, so they can be updated at build time /* Write updated (no need to rebuild) state derivations to the database, so they can be updated at build time
if(enableState && !disableState){ if(enableState && !disableState){
if(store->isValidPath(outPath)){ //Only add when the path is already valid if(store->isValidPath(outPath)){ //Only add when the path is already valid

View file

@ -773,6 +773,11 @@ void DerivationGoal::haveDerivation()
/* Check what outputs paths are not already valid. */ /* Check what outputs paths are not already valid. */
PathSet invalidOutputs = checkPathValidity(false); PathSet invalidOutputs = checkPathValidity(false);
//Just before we build, we resolve the multiple derivations linked to one store path issue, by choosing the latest derivation
printMsg(lvlError, format("updateAllStateDerivations %1%") % drvPath);
//addStateDeriver(....); //only on succesfull! build
/* If they are all valid, then we're done. */ /* If they are all valid, then we're done. */
if (invalidOutputs.size() == 0) { if (invalidOutputs.size() == 0) {
amDone(ecSuccess); amDone(ecSuccess);
@ -1681,10 +1686,14 @@ void DerivationGoal::computeClosure()
/* Get rid of all weird permissions. */ /* Get rid of all weird permissions. */
canonicalisePathMetaData(path); canonicalisePathMetaData(path);
/* For this output path, find the references to other paths contained /* For this output path, find the references to other paths contained in it. */
in it. */
PathSet references = scanForReferences(path, allPaths); PathSet references = scanForReferences(path, allPaths);
/* For this state-output path, find the references to other paths contained in it. */
Path statePath = drv.stateOutputs.find("state")->second.statepath;
PathSet state_references = scanForReferences(statePath, allPaths);
references = mergePathSets(references, state_references);
/* For debugging, print out the referenced and unreferenced /* For debugging, print out the referenced and unreferenced
paths. */ paths. */
for (PathSet::iterator i = inputPaths.begin(); for (PathSet::iterator i = inputPaths.begin();
@ -2479,13 +2488,7 @@ void LocalStore::buildDerivations(const PathSet & drvPaths)
startNest(nest, lvlDebug, startNest(nest, lvlDebug,
format("building %1%") % showPaths(drvPaths)); format("building %1%") % showPaths(drvPaths));
//Just before we build, we resolve the multiple derivations linked to one store path issue, by choosing the latest derivation
printMsg(lvlError, format("updateAllStateDerivations %1%") % showPaths(drvPaths));
store->updateAllStateDerivations();
Worker worker; Worker worker;
Goals goals; Goals goals;
for (PathSet::const_iterator i = drvPaths.begin(); i != drvPaths.end(); ++i){ for (PathSet::const_iterator i = drvPaths.begin(); i != drvPaths.end(); ++i){
goals.insert(worker.makeDerivationGoal(*i)); goals.insert(worker.makeDerivationGoal(*i));

View file

@ -408,7 +408,7 @@ void setDeriver(const Transaction & txn, const Path & storePath, const Path & de
Derivation drv = derivationFromPath(deriver); //Redirect if its a state component Derivation drv = derivationFromPath(deriver); //Redirect if its a state component
if (drv.outputs.size() != 0) if (drv.outputs.size() != 0)
addStateDeriver(txn, storePath, deriver); //TODO remove store-> addStateDeriver(txn, storePath, deriver);
else else
nixDB.setString(txn, dbDerivers, storePath, deriver); nixDB.setString(txn, dbDerivers, storePath, deriver);
} }
@ -474,14 +474,14 @@ PathSet queryDerivers(const Transaction & txn, const Path & storePath, const str
if (!isRealisablePath(txn, storePath)) if (!isRealisablePath(txn, storePath))
throw Error(format("path `%1%' is not valid") % storePath); throw Error(format("path `%1%' is not valid") % storePath);
if(identifier == "" || user == "") if(user == "")
throw Error(format("The identifer or user argument is empty, use queryDeriver(...) for non-state components")); throw Error(format("The user argument is empty, use queryDeriver(...) for non-state components"));
Strings alldata; Strings alldata;
nixDB.queryStrings(txn, dbDerivers, storePath, alldata); //get all current derivers nixDB.queryStrings(txn, dbDerivers, storePath, alldata); //get all current derivers
PathSet filtereddata; PathSet filtereddata;
for (Strings::iterator i = alldata.begin(); i != alldata.end(); ++i) { for (Strings::iterator i = alldata.begin(); i != alldata.end(); ++i) { //filter on username and identifier
string derivationpath = (*i); string derivationpath = (*i);
Derivation drv = derivationFromPath(derivationpath); Derivation drv = derivationFromPath(derivationpath);
@ -496,6 +496,7 @@ PathSet queryDerivers(const Transaction & txn, const Path & storePath, const str
filtereddata.insert(derivationpath); filtereddata.insert(derivationpath);
} }
return filtereddata; return filtereddata;
} }
@ -1244,25 +1245,48 @@ vector<int> LocalStore::getStatePathsInterval(const PathSet & statePaths)
//TODO direct or all recursive parameter //TODO direct or all recursive parameter
//TODO check if these are state components //TODO check if these are state components
PathSet getStateReferencesClosure(const Path & path) //TODO CHECK FOR DERIVATION INSTEAD OF
PathSet getStateReferencesClosure(const Path & drvpath)
{
PathSet empty;
return getStateReferencesClosure_(drvpath, empty);
}
PathSet getStateReferencesClosure_(const Path & drvpath, PathSet & paths)
{ {
Transaction txn(nixDB); //TODO should u do a transaction here? ... this might delay the process ... Transaction txn(nixDB); //TODO should u do a transaction here? ... this might delay the process ...
Strings data; Strings data;
PathSet paths;
TODODODODOD..........
Paths referencesKeys; Paths referencesKeys;
nixDB.queryStrings(txn, dbReferences, path, data); nixDB.queryStrings(txn, dbReferences, path, data);
for (Strings::iterator i = data.begin(); i != data.end(); ++i) for (Strings::iterator i = data.begin(); i != data.end(); ++i)
{ {
//printMsg(lvlError, format("References: `%1%'") % *i); string storePath = *i;
paths.insert(*i);
bool alreadyExists = false;
for (PathSet::iterator j = paths.begin(); j != paths.end(); ++j) //Get also the references of this dep.
{
string checkPath = *j;
if(storePath == checkPath){
alreadyExists = true;
break;
}
}
if( !alreadyExists ){
printMsg(lvlError, format("References: `%1%'") % storePath);
paths.insert(storePath);
PathSet rec = getStateReferencesClosure_(storePath, paths); //go recursive
//paths = mergePathSets(paths, rec); //merge
}
} }
txn.commit(); txn.commit();
return paths; return paths;
} }
PathSet LocalStore::getStateReferencesClosure(const Path & path) PathSet LocalStore::getStateReferencesClosure(const Path & path)
@ -1293,7 +1317,7 @@ PathSet mergeNewDerivationIntoList(const Path & storepath, const Path & newdrv,
newdrvs.insert(drv); newdrvs.insert(drv);
else{ else{
if(deleteDrvs){ if(deleteDrvs){
printMsg(lvlError, format("Deleting decrepated state derivation: %1%") % drv); printMsg(lvlError, format("Deleting decrepated state derivation: %1% with identifier %2% and user %3%") % drv % identifier % user);
deletePath(drv); //Deletes the DRV from DISK! deletePath(drv); //Deletes the DRV from DISK!
} }
} }
@ -1308,6 +1332,7 @@ PathSet mergeNewDerivationIntoList(const Path & storepath, const Path & newdrv,
void updateAllStateDerivations() void updateAllStateDerivations()
{ {
//call AddStateDerivation !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //call AddStateDerivation !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
/* /*

View file

@ -184,6 +184,9 @@ void addStateDeriver(const Transaction & txn, const Path & storePath, const Path
/* TODO */ /* TODO */
PathSet mergeNewDerivationIntoList(const Path & storepath, const Path & newdrv, const PathSet drvs, bool deleteDrvs = false); PathSet mergeNewDerivationIntoList(const Path & storepath, const Path & newdrv, const PathSet drvs, bool deleteDrvs = false);
/* TODO */
PathSet getStateReferencesClosure_(const Path & drvpath, PathSet & paths);
} }

View file

@ -1118,4 +1118,27 @@ string getCallingUserName()
return username; return username;
} }
PathSet mergePathSets(const PathSet & paths1, const PathSet & paths2)
{
PathSet merged = paths2;
for (PathSet::iterator i = paths1.begin(); i != paths1.end(); ++i) //were inserting all paths from pathset1 into pathset2
{
bool alreadyExists = false;
for (PathSet::iterator j = paths2.begin(); j != paths2.end(); ++j) //search in p2 for duplicates
{
if(*i == *j){
alreadyExists = true;
break;
}
}
if( !alreadyExists ){ //insert into p2 if not duplicate
merged.insert(*i);
}
}
return merged;
}
} }

View file

@ -302,6 +302,9 @@ bool IsDirectory(const string FileName);
string getCallingUserName(); string getCallingUserName();
/* TODO */
PathSet mergePathSets(const PathSet & paths1, const PathSet & paths2);
} }
#endif /* !__UTIL_H */ #endif /* !__UTIL_H */

View file

@ -33,13 +33,14 @@ void printHelp()
cout << string((char *) helpText, sizeof helpText); cout << string((char *) helpText, sizeof helpText);
} }
//
// //
Derivation getDerivation_andCheckArgs(Strings opFlags, Strings opArgs, Path & componentPath, Path & statePath, string & stateIdentifier, string & binary) Derivation getDerivation_andCheckArgs_(Strings opFlags, Strings opArgs, Path & componentPath, Path & statePath, string & stateIdentifier, string & binary, string & derivationPath,
bool getDerivers, PathSet & derivers, string & username) //optional
{ {
if (!opFlags.empty()) throw UsageError("unknown flag"); if (!opFlags.empty()) throw UsageError("unknown flag");
if (opArgs.size() != 1 && opArgs.size() != 2) throw UsageError("only one or two arguments allowed (the component path & the identiefier which can be empty)"); if ( (opArgs.size() != 1 && opArgs.size() != 2) && (getDerivers && opArgs.size() != 3) )
throw UsageError("only one or two arguments allowed component path / identiefier (or a third when you need to see the derivations: [username]) )");
//Parse the full path like /nix/store/...../bin/hello //Parse the full path like /nix/store/...../bin/hello
string fullPath = opArgs.front(); string fullPath = opArgs.front();
@ -52,29 +53,65 @@ Derivation getDerivation_andCheckArgs(Strings opFlags, Strings opArgs, Path & co
if(componentPath == "/nix/store") if(componentPath == "/nix/store")
throw UsageError("You must specify the full! binary path"); throw UsageError("You must specify the full! binary path");
stateIdentifier = ""; if(opArgs.size() > 1){
if(opArgs.size() == 2){
opArgs.pop_front(); opArgs.pop_front();
stateIdentifier = opArgs.front(); stateIdentifier = opArgs.front();
} }
string username = getCallingUserName();
//printMsg(lvlError, format("%1% - %2% - %3% - %4% - %5%") % componentPath % statePath % stateIdentifier % binary % username); if(username == "")
username = getCallingUserName();
printMsg(lvlError, format("%1% - %2% - %3% - %4%") % componentPath % stateIdentifier % binary % username);
derivers = queryDerivers(noTxn, componentPath, stateIdentifier, username);
if(getDerivers == true)
return Derivation();
else if(derivers.size() != 1)
throw UsageError("There is more than one deriver....");
PathSet drvs = queryDerivers(noTxn, componentPath, stateIdentifier, username);
if(drvs.size() != 1)
throw UsageError("You must specify the full! binary path");
Derivation drv; Derivation drv;
for (PathSet::iterator i = drvs.begin(); i != drvs.end(); ++i) //ugly workaround for drvs[0]. for (PathSet::iterator i = derivers.begin(); i != derivers.end(); ++i){ //ugly workaround for drvs[0].
drv = derivationFromPath(*i); derivationPath = *i;
drv = derivationFromPath(derivationPath);
queryDeriver(noTxn, ""); }
DerivationStateOutputs stateOutputs = drv.stateOutputs; DerivationStateOutputs stateOutputs = drv.stateOutputs;
statePath = stateOutputs.find("state")->second.statepath; statePath = stateOutputs.find("state")->second.statepath;
return drv; return drv;
} }
//Wrapper
Derivation getDerivation_andCheckArgs(Strings opFlags, Strings opArgs, Path & componentPath, Path & statePath, string & stateIdentifier, string & binary, string & derivationPath)
{
PathSet empty;
string empty2;
return getDerivation_andCheckArgs_(opFlags, opArgs, componentPath, statePath, stateIdentifier, binary, derivationPath, false, empty, empty2);
}
//
static void opShowDerivations(Strings opFlags, Strings opArgs)
{
string username;
if(opArgs.size() == 3)
username = opArgs.back();
else if(opArgs.size() == 2)
username = getCallingUserName();
string stateIdentifier;
Path componentPath;
Path statePath;
string binary;
PathSet derivers;
string derivationPath;
Derivation drv = getDerivation_andCheckArgs_(opFlags, opArgs, componentPath, statePath, stateIdentifier, binary, derivationPath, true, derivers, username);
for (PathSet::iterator i = derivers.begin(); i != derivers.end(); ++i)
printMsg(lvlError, format("%1%") % (*i));
}
//Prints the statepath of a component - indetiefier combination //Prints the statepath of a component - indetiefier combination
static void opShowStatePath(Strings opFlags, Strings opArgs) static void opShowStatePath(Strings opFlags, Strings opArgs)
{ {
@ -82,7 +119,8 @@ static void opShowStatePath(Strings opFlags, Strings opArgs)
Path statePath; Path statePath;
string stateIdentifier; string stateIdentifier;
string binary; string binary;
Derivation drv = getDerivation_andCheckArgs(opFlags, opArgs, componentPath, statePath, stateIdentifier, binary); string derivationPath
Derivation drv = getDerivation_andCheckArgs(opFlags, opArgs, componentPath, statePath, stateIdentifier, binary, derivationPath);
printMsg(lvlError, format("%1%") % statePath); printMsg(lvlError, format("%1%") % statePath);
} }
@ -93,7 +131,8 @@ static void opShowStateReposRootPath(Strings opFlags, Strings opArgs)
Path statePath; Path statePath;
string stateIdentifier; string stateIdentifier;
string binary; string binary;
Derivation drv = getDerivation_andCheckArgs(opFlags, opArgs, componentPath, statePath, stateIdentifier, binary); string derivationPath;
Derivation drv = getDerivation_andCheckArgs(opFlags, opArgs, componentPath, statePath, stateIdentifier, binary, derivationPath);
string drvName = drv.env.find("name")->second; string drvName = drv.env.find("name")->second;
//Get the a repository for this state location //Get the a repository for this state location
@ -114,8 +153,8 @@ static void opRunComponent(Strings opFlags, Strings opArgs)
Path statePath; Path statePath;
string stateIdentifier; string stateIdentifier;
string binary; string binary;
string derivationPath
Derivation drv = getDerivation_andCheckArgs(opFlags, opArgs, componentPath, statePath, stateIdentifier, binary); Derivation drv = getDerivation_andCheckArgs(opFlags, opArgs, componentPath, statePath, stateIdentifier, binary, derivationPath);
DerivationStateOutputDirs stateOutputDirs = drv.stateOutputDirs; DerivationStateOutputDirs stateOutputDirs = drv.stateOutputDirs;
DerivationStateOutputs stateOutputs = drv.stateOutputs; DerivationStateOutputs stateOutputs = drv.stateOutputs;
DerivationOutputs outputs = drv.outputs; DerivationOutputs outputs = drv.outputs;
@ -134,7 +173,7 @@ static void opRunComponent(Strings opFlags, Strings opArgs)
//******************* Afterwards, call the commit script (recursively) //******************* Afterwards, call the commit script (recursively)
//get dependecies (if neccecary | recusively) of all state components that need to be updated //get dependecies (if neccecary | recusively) of all state components that need to be updated
PathSet paths = store->getStateReferencesClosure(componentPath); PathSet paths = store->getStateReferencesClosure(derivationPath);
//TODO nix-store -q --tree $(nix-store -qd /nix/store/6x6glnb9idn53yxfqrz6wq53459vv3qd-firefox-2.0.0.3/) //TODO nix-store -q --tree $(nix-store -qd /nix/store/6x6glnb9idn53yxfqrz6wq53459vv3qd-firefox-2.0.0.3/)
@ -276,8 +315,10 @@ void run(Strings args)
*/ */
store = openStore(); store = openStore();
//store->addUpdatedStateDerivation("/nix/store/bk4p7378ndm1p5qdr6a99wgxbiklilxy-hellohardcodedstateworld-1.0.drv", "/nix/store/vjijdazrn2jyzyk9sqwrl8fjq0qsmi8y-hellohardcodedstateworld-1.0"); //store->addUpdatedStateDerivation("/nix/store/bk4p7378ndm1p5qdr6a99wgxbiklilxy-hellohardcodedstateworld-1.0.drv", "/nix/store/vjijdazrn2jyzyk9sqwrl8fjq0qsmi8y-hellohardcodedstateworld-1.0");
//store->updateAllStateDerivations();
//return;
store->updateAllStateDerivations(); PathSet paths = store->getStateReferencesClosure("/nix/store/928dd2wl5cgqg10hzc3aj4rqaips6bdk-hellohardcodedstateworld-dep1-1.0.drv");
return; return;
/* test */ /* test */
@ -293,7 +334,8 @@ void run(Strings args)
op = opShowStatePath; op = opShowStatePath;
else if (arg == "--showstatereposrootpath") else if (arg == "--showstatereposrootpath")
op = opShowStateReposRootPath; op = opShowStateReposRootPath;
else if (arg == "--showderivations")
op = opShowDerivations;
/* /*
--commit --commit