mirror of
https://github.com/NixOS/nix.git
synced 2025-11-26 04:00:59 +01:00
before moving some functions to nix-state
This commit is contained in:
parent
ba437f451e
commit
36b79c7135
2 changed files with 87 additions and 72 deletions
|
|
@ -1693,6 +1693,35 @@ void getDependenciesAtBuildTime(const Transaction & txn, const Path & drvPath)
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
int readRevisionNumber(const Derivation & drv)
|
||||||
|
{
|
||||||
|
string svnbin = nixSVNPath + "/svn";
|
||||||
|
RevisionNumbers revisions;
|
||||||
|
|
||||||
|
DerivationStateOutputDirs stateOutputDirs = drv.stateOutputDirs;
|
||||||
|
string drvName = drv.env.find("name")->second;
|
||||||
|
DerivationStateOutputs stateOutputs = drv.stateOutputs;
|
||||||
|
Path statePath = stateOutputs.find("state")->second.statepath;
|
||||||
|
string getStateIdentifier = stateOutputs.find("state")->second.stateIdentifier;
|
||||||
|
|
||||||
|
string repos = getStateReposPath("stateOutput:staterepospath", statePath, drvName, getStateIdentifier); //this is a copy from store-state.cc
|
||||||
|
|
||||||
|
Strings p_args;
|
||||||
|
p_args.push_back(svnbin);
|
||||||
|
p_args.push_back("file://" + repos);
|
||||||
|
string output = runProgram(nixLibexecDir + "/nix/nix-readrevisions.sh", true, p_args); //run
|
||||||
|
|
||||||
|
int pos = output.find("\n",0); //remove trailing \n
|
||||||
|
output.erase(pos,1);
|
||||||
|
|
||||||
|
int revision;
|
||||||
|
bool succeed = string2Int(output, revision);
|
||||||
|
if(!succeed)
|
||||||
|
throw Error(format("Cannot read revision number of path '%1%'") % repos);
|
||||||
|
|
||||||
|
return revision;
|
||||||
|
}
|
||||||
|
|
||||||
//TODO include this call in the validate function
|
//TODO include this call in the validate function
|
||||||
//TODO ONLY CALL THIS FUNCTION ON A NON-SHARED STATE PATH!!!!!!!!!!!
|
//TODO ONLY CALL THIS FUNCTION ON A NON-SHARED STATE PATH!!!!!!!!!!!
|
||||||
void scanAndUpdateAllReferencesTxn(const Transaction & txn, const Path & statePath
|
void scanAndUpdateAllReferencesTxn(const Transaction & txn, const Path & statePath
|
||||||
|
|
@ -1780,39 +1809,57 @@ void scanAndUpdateAllReferencesTxn(const Transaction & txn, const Path & statePa
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void scanAndUpdateAllReferencesRecusivelyTxn(const Transaction & txn, const Path & storeOrStatePath, const int revision) //TODO Can also work for statePaths???
|
void scanAndUpdateAllReferencesRecusivelyTxn(const Transaction & txn, const Path & storeOrStatePath, RevisionNumbersSet & rivisionMapping) //TODO Can also work for statePaths???
|
||||||
{
|
{
|
||||||
//get all state current state references recursively
|
//get all state current state references recursively
|
||||||
PathSet statePaths;
|
PathSet statePaths;
|
||||||
storePathRequisites(storeOrStatePath, false, statePaths, false, true, -1); //Get all current state dependencies
|
storePathRequisites(storeOrStatePath, false, statePaths, false, true, -1); //Get all current state dependencies
|
||||||
|
|
||||||
|
//get all revisions
|
||||||
|
//TODO
|
||||||
|
|
||||||
//call scanForAllReferences again on all newly found statePaths
|
//call scanForAllReferences again on all newly found statePaths
|
||||||
for (PathSet::iterator i = statePaths.begin(); i != statePaths.end(); ++i)
|
for (PathSet::iterator i = statePaths.begin(); i != statePaths.end(); ++i)
|
||||||
{
|
{
|
||||||
//Scan, update, call recursively
|
//Scan, update, call recursively
|
||||||
PathSet newFoundComponentReferences;
|
PathSet newFoundComponentReferences;
|
||||||
PathSet newFoundStateReferences;
|
PathSet newFoundStateReferences;
|
||||||
scanAndUpdateAllReferencesTxn(txn, *i, newFoundComponentReferences, newFoundStateReferences, revision);
|
scanAndUpdateAllReferencesTxn(txn, *i, newFoundComponentReferences, newFoundStateReferences, 000000000); //TODO
|
||||||
PathSet allNewReferences = pathSets_union(newFoundComponentReferences, newFoundStateReferences);
|
PathSet allNewReferences = pathSets_union(newFoundComponentReferences, newFoundStateReferences);
|
||||||
|
|
||||||
//Call the function recursively again on all newly found references //TODO test if this doesnt go into an infinite loop
|
//Call the function recursively again on all newly found references //TODO test if this doesnt go into an infinite loop
|
||||||
for (PathSet::iterator j = allNewReferences.begin(); j != allNewReferences.end(); ++j)
|
for (PathSet::iterator j = allNewReferences.begin(); j != allNewReferences.end(); ++j)
|
||||||
scanAndUpdateAllReferencesRecusivelyTxn(txn, *j, revision);
|
scanAndUpdateAllReferencesRecusivelyTxn(txn, *j, rivisionMapping);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void scanAndUpdateAllReferencesTxn(const Transaction & txn, const Path & storeOrStatePath, const int revision, bool recursive)
|
void scanAndUpdateAllReferencesTxn(const Transaction & txn, const Path & statePath, const int state_revision, bool recursive)
|
||||||
{
|
{
|
||||||
//TODO name-refactor storeOrStatePath to statePath
|
//TODO name-refactor storeOrStatePath to statePath
|
||||||
if(! isValidStatePathTxn(txn, storeOrStatePath)) //check if storeOrStatePath is a statePath, else throw error
|
if(! isValidStatePathTxn(txn, statePath)) //check if storeOrStatePath is a statePath, else throw error
|
||||||
throw Error(format("This path '%1%' is not a state path") % storeOrStatePath);
|
throw Error(format("This path '%1%' is not a state path") % statePath);
|
||||||
|
|
||||||
if(recursive)
|
RevisionNumbersSet rivisionMapping;
|
||||||
nix::scanAndUpdateAllReferencesRecusivelyTxn(txn, storeOrStatePath, revision);
|
|
||||||
|
if(recursive){
|
||||||
|
nix::scanAndUpdateAllReferencesRecusivelyTxn(txn, statePath, rivisionMapping);
|
||||||
|
}
|
||||||
else{
|
else{
|
||||||
|
|
||||||
|
//get drv
|
||||||
|
Derivation drv; //TODO
|
||||||
|
|
||||||
|
//get revision
|
||||||
|
int revision = readRevisionNumber(drv);
|
||||||
|
rivisionMapping[statePath] = revision;
|
||||||
|
|
||||||
|
//update
|
||||||
PathSet empty;
|
PathSet empty;
|
||||||
nix::scanAndUpdateAllReferencesTxn(txn, storeOrStatePath, empty, empty, revision);
|
nix::scanAndUpdateAllReferencesTxn(txn, statePath, empty, empty, revision);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Store the revision numbers in the database for this statePath with revision number
|
||||||
|
store->setStateRevisions(statePath, rivisionMapping, state_revision);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LocalStore::scanAndUpdateAllReferences(const Path & storeOrStatePath, const int revision, bool recursive)
|
void LocalStore::scanAndUpdateAllReferences(const Path & storeOrStatePath, const int revision, bool recursive)
|
||||||
|
|
|
||||||
|
|
@ -41,17 +41,13 @@ void printHelp()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
Derivation getDerivation(const string & fullPath, const string & program_args, Path & componentPath, Path & statePath,
|
||||||
Derivation getDerivation_andCheckArgs_(Strings opFlags, Strings opArgs, Path & componentPath, Path & statePath,
|
string & binary, string & derivationPath, bool isStatePath,
|
||||||
string & binary, string & derivationPath, bool isStatePath, string & program_args,
|
bool getDerivers, PathSet & derivers) //optional
|
||||||
bool getDerivers, PathSet & derivers) //optional
|
|
||||||
{
|
{
|
||||||
if (!opFlags.empty()) throw UsageError("unknown flag");
|
|
||||||
if ( opArgs.size() != 1 && opArgs.size() != 2 )
|
|
||||||
throw UsageError("only one or two arguments allowed component path and program arguments (counts as one) ");
|
|
||||||
|
|
||||||
//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();
|
||||||
|
|
||||||
componentPath = fullPath.substr(nixStore.size() + 1, fullPath.size()); //+1 to strip off the /
|
componentPath = fullPath.substr(nixStore.size() + 1, fullPath.size()); //+1 to strip off the /
|
||||||
int pos = componentPath.find("/",0);
|
int pos = componentPath.find("/",0);
|
||||||
componentPath = fullPath.substr(0, pos + nixStore.size() + 1);
|
componentPath = fullPath.substr(0, pos + nixStore.size() + 1);
|
||||||
|
|
@ -64,17 +60,7 @@ Derivation getDerivation_andCheckArgs_(Strings opFlags, Strings opArgs, Path & c
|
||||||
//Check if path is statepath
|
//Check if path is statepath
|
||||||
isStatePath = store->isStateComponent(componentPath);
|
isStatePath = store->isStateComponent(componentPath);
|
||||||
|
|
||||||
//Extract the program arguments
|
//printMsg(lvlError, format("'%1%' - '%2%' - '%3%' - '%4%' - '%5%'") % componentPath % stateIdentifier % binary % username % program_args);
|
||||||
string allArgs;
|
|
||||||
if(opArgs.size() > 1){
|
|
||||||
opArgs.pop_front();
|
|
||||||
allArgs = opArgs.front();
|
|
||||||
|
|
||||||
program_args = allArgs;
|
|
||||||
//Strings progam_args_strings = tokenizeString(allArgs, " ");
|
|
||||||
}
|
|
||||||
|
|
||||||
//printMsg(lvlError, format("'%1%' - '%2%' - '%3%' - '%4%' - '%5%'") % componentPath % stateIdentifier % binary % username % allArgs);
|
|
||||||
|
|
||||||
if(isStatePath)
|
if(isStatePath)
|
||||||
derivers = queryDerivers(noTxn, componentPath, stateIdentifier, username);
|
derivers = queryDerivers(noTxn, componentPath, stateIdentifier, username);
|
||||||
|
|
@ -105,6 +91,27 @@ Derivation getDerivation_andCheckArgs_(Strings opFlags, Strings opArgs, Path & c
|
||||||
return drv;
|
return drv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Wrapper
|
||||||
|
Derivation getDerivation_andCheckArgs_(Strings opFlags, Strings opArgs, Path & componentPath, Path & statePath,
|
||||||
|
string & binary, string & derivationPath, bool isStatePath, string & program_args,
|
||||||
|
bool getDerivers, PathSet & derivers) //optional
|
||||||
|
{
|
||||||
|
if (!opFlags.empty()) throw UsageError("unknown flag");
|
||||||
|
if ( opArgs.size() != 1 && opArgs.size() != 2 )
|
||||||
|
throw UsageError("only one or two arguments allowed component path and program arguments (counts as one) ");
|
||||||
|
|
||||||
|
|
||||||
|
string fullPath = opArgs.front();
|
||||||
|
|
||||||
|
if(opArgs.size() > 1){
|
||||||
|
opArgs.pop_front();
|
||||||
|
program_args = opArgs.front();
|
||||||
|
//Strings progam_args_strings = tokenizeString(program_args, " ");
|
||||||
|
}
|
||||||
|
|
||||||
|
return getDerivation(fullPath, program_args, componentPath, statePath, binary, derivationPath, isStatePath, getDerivers, derivers);
|
||||||
|
}
|
||||||
|
|
||||||
//Wrapper
|
//Wrapper
|
||||||
Derivation getDerivation_andCheckArgs(Strings opFlags, Strings opArgs, Path & componentPath, Path & statePath,
|
Derivation getDerivation_andCheckArgs(Strings opFlags, Strings opArgs, Path & componentPath, Path & statePath,
|
||||||
string & binary, string & derivationPath, bool & isStatePath, string & program_args)
|
string & binary, string & derivationPath, bool & isStatePath, string & program_args)
|
||||||
|
|
@ -171,34 +178,7 @@ static void opShowStateReposPath(Strings opFlags, Strings opArgs)
|
||||||
printMsg(lvlError, format("%1%") % repos);
|
printMsg(lvlError, format("%1%") % repos);
|
||||||
}
|
}
|
||||||
|
|
||||||
int readRevisionNumber(const Derivation & drv)
|
|
||||||
{
|
|
||||||
string svnbin = nixSVNPath + "/svn";
|
|
||||||
RevisionNumbers revisions;
|
|
||||||
|
|
||||||
DerivationStateOutputDirs stateOutputDirs = drv.stateOutputDirs;
|
|
||||||
string drvName = drv.env.find("name")->second;
|
|
||||||
DerivationStateOutputs stateOutputs = drv.stateOutputs;
|
|
||||||
Path statePath = stateOutputs.find("state")->second.statepath;
|
|
||||||
string getStateIdentifier = stateOutputs.find("state")->second.stateIdentifier;
|
|
||||||
|
|
||||||
string repos = getStateReposPath("stateOutput:staterepospath", statePath, drvName, getStateIdentifier); //this is a copy from store-state.cc
|
|
||||||
|
|
||||||
Strings p_args;
|
|
||||||
p_args.push_back(svnbin);
|
|
||||||
p_args.push_back("file://" + repos);
|
|
||||||
string output = runProgram(nixLibexecDir + "/nix/nix-readrevisions.sh", true, p_args); //run
|
|
||||||
|
|
||||||
int pos = output.find("\n",0); //remove trailing \n
|
|
||||||
output.erase(pos,1);
|
|
||||||
|
|
||||||
int revision;
|
|
||||||
bool succeed = string2Int(output, revision);
|
|
||||||
if(!succeed)
|
|
||||||
throw Error(format("Cannot read revision number of path '%1%'") % repos);
|
|
||||||
|
|
||||||
return revision;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Input: store (or statePath?)
|
* Input: store (or statePath?)
|
||||||
|
|
@ -448,32 +428,20 @@ static void opRunComponent(Strings opFlags, Strings opArgs)
|
||||||
|
|
||||||
//Update the intervals again
|
//Update the intervals again
|
||||||
//store->setStatePathsInterval(intervalPaths, intervals); //TODO!!!!!!!!!!!!!!!!!!!!!! uncomment and txn ??
|
//store->setStatePathsInterval(intervalPaths, intervals); //TODO!!!!!!!!!!!!!!!!!!!!!! uncomment and txn ??
|
||||||
|
|
||||||
statePaths.insert(statePath); //Insert StatePath
|
|
||||||
rivisionMapping[statePath] = readRevisionNumber(drv); //Get current numbers
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//1.NEW TRANSACTION
|
//Start transaction
|
||||||
//TODO
|
//TODO
|
||||||
|
|
||||||
//TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! only update the root with newRevisionNumber, the rest with the value from rivisionMapping !!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
||||||
|
|
||||||
//Get new revision number
|
//Get new revision number
|
||||||
int newRevisionNumber = store->getNewRevisionNumber(root_statePath);
|
int newRevisionNumber = store->getNewRevisionNumber(root_statePath);
|
||||||
|
|
||||||
//Scan for new references, and update with revision number
|
//Scan for new references, and update with revision number
|
||||||
if(scanforReferences){
|
if(scanforReferences){
|
||||||
/*
|
|
||||||
for (PathSet::iterator i = statePaths.begin(); i != statePaths.end(); ++i) //fails ....
|
|
||||||
store->scanAndUpdateAllReferences(*i, newRevisionNumber, false);
|
|
||||||
*/
|
|
||||||
store->scanAndUpdateAllReferences(root_statePath, newRevisionNumber, true); //goes recursive
|
store->scanAndUpdateAllReferences(root_statePath, newRevisionNumber, true); //goes recursive
|
||||||
}
|
}
|
||||||
|
|
||||||
//Store the revision numbers in the database for this statePath with revision number
|
//Commit
|
||||||
store->setStateRevisions(root_statePath, rivisionMapping, newRevisionNumber);
|
|
||||||
|
|
||||||
//4. COMMIT
|
|
||||||
//TODO
|
//TODO
|
||||||
|
|
||||||
//Debugging
|
//Debugging
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue