mirror of
https://github.com/NixOS/nix.git
synced 2025-11-26 20:20:58 +01:00
This commit is contained in:
parent
a07ba681cc
commit
dc4395b737
16 changed files with 164 additions and 168 deletions
|
|
@ -1812,10 +1812,6 @@ void DerivationGoal::computeClosure()
|
|||
//Commit state
|
||||
commitStatePathTxn(txn, statePath);
|
||||
|
||||
//Set first revision (if we committed something)
|
||||
if(readRevisionNumber(statePath) == 1)
|
||||
updateRevisionsRecursivelyTxn(txn, statePath);
|
||||
|
||||
//Shared state
|
||||
Path sharedState = drv.stateOutputs.find("state")->second.sharedState;
|
||||
if(sharedState != ""){
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
#include "db.hh"
|
||||
#include "util.hh"
|
||||
#include "pathlocks.hh"
|
||||
#include "derivations.hh"
|
||||
#include "local-store.hh"
|
||||
#include "misc.hh"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
|
@ -595,25 +598,39 @@ void Database::setStateRevisions(const Transaction & txn, TableId table,
|
|||
int root_revision = getNewRevisionNumber(txn, table, statePath);
|
||||
|
||||
//Sort based on statePath to RevisionNumbersClosure
|
||||
RevisionNumbers sorted_revisions;
|
||||
vector<Path> sortedStatePaths;
|
||||
for (RevisionNumbersSet::const_iterator i = revisions.begin(); i != revisions.end(); ++i)
|
||||
sortedStatePaths.push_back((*i).first);
|
||||
sort(sortedStatePaths.begin(), sortedStatePaths.end());
|
||||
for (vector<Path>::const_iterator i = sortedStatePaths.begin(); i != sortedStatePaths.end(); ++i)
|
||||
sorted_revisions.push_back(revisions.at(*i));
|
||||
|
||||
vector<RevisionNumbers> sorted_revisions;
|
||||
for (vector<Path>::const_iterator i = sortedStatePaths.begin(); i != sortedStatePaths.end(); ++i){
|
||||
map<Path, unsigned int> ss_revisions = revisions.at(*i);
|
||||
|
||||
//Sort the set of paths that have revisions based on
|
||||
vector<Path> sorted_ssp;
|
||||
for (map<Path, unsigned int>::const_iterator j = ss_revisions.begin(); j != ss_revisions.end(); ++j)
|
||||
sorted_ssp.push_back((*j).first);
|
||||
sort(sorted_ssp.begin(), sorted_ssp.end());
|
||||
|
||||
//Insert into sorted_ss_revs based on the sorted order
|
||||
RevisionNumbers sorted_ss_revs;
|
||||
for (vector<Path>::const_iterator j = sorted_ssp.begin(); j != sorted_ssp.end(); ++j)
|
||||
sorted_ss_revs.push_back(ss_revisions.at(*j));
|
||||
|
||||
//Insert ......
|
||||
sorted_revisions.push_back(sorted_ss_revs);
|
||||
}
|
||||
|
||||
//Debugging
|
||||
for (vector<Path>::const_iterator i = sortedStatePaths.begin(); i != sortedStatePaths.end(); ++i)
|
||||
printMsg(lvlError, format("Insert: %1% into %2%") % int2String(revisions.at(*i)) % *i);
|
||||
//for (vector<Path>::const_iterator i = sortedStatePaths.begin(); i != sortedStatePaths.end(); ++i)
|
||||
// printMsg(lvlError, format("Insert: %1% into %2%") % revisions.at(*i) % *i);
|
||||
|
||||
//Convert the int's into Strings
|
||||
//Convert the vector<RevisionNumbers> into Strings
|
||||
Strings data;
|
||||
for (RevisionNumbers::const_iterator i = sorted_revisions.begin(); i != sorted_revisions.end(); ++i) {
|
||||
int revisionnumber = *i;
|
||||
data.push_back(int2String(revisionnumber));
|
||||
}
|
||||
|
||||
for (vector<RevisionNumbers>::const_iterator i = sorted_revisions.begin(); i != sorted_revisions.end(); ++i)
|
||||
data.push_back(packRevisionNumbers(*i));
|
||||
|
||||
//Create the key
|
||||
string key = makeStatePathRevision(statePath, root_revision);
|
||||
|
||||
|
|
@ -651,14 +668,32 @@ bool Database::queryStateRevisions(const Transaction & txn, TableId table, const
|
|||
|
||||
//Convert the Strings into int's and match them to the sorted statePaths
|
||||
for (vector<Path>::const_iterator i = sortedStatePaths.begin(); i != sortedStatePaths.end(); ++i){
|
||||
string getRevisionS = data.front();
|
||||
|
||||
RevisionNumbers ss_revisions = unpackRevisionNumbers(data.front());
|
||||
data.pop_front();
|
||||
|
||||
int getRevision;
|
||||
bool succeed = string2Int(getRevisionS, getRevision);
|
||||
if(!succeed)
|
||||
throw Error(format("Cannot read revision number from db of path '%1%'") % statePath);
|
||||
revisions[*i] = getRevision;
|
||||
//query state versioined directorys/files
|
||||
vector<Path> sortedPaths;
|
||||
Derivation drv = derivationFromPath(queryStatePathDrvTxn(txn, statePath));
|
||||
DerivationStateOutputs stateOutputs = drv.stateOutputs;
|
||||
DerivationStateOutputDirs stateOutputDirs = drv.stateOutputDirs;
|
||||
for (DerivationStateOutputDirs::const_iterator j = stateOutputDirs.begin(); j != stateOutputDirs.end(); ++j){
|
||||
string thisdir = (j->second).path;
|
||||
string fullstatedir = statePath + "/" + thisdir;
|
||||
if(thisdir == "/") //exception for the root dir
|
||||
fullstatedir = statePath + "/";
|
||||
sortedPaths.push_back(fullstatedir);
|
||||
}
|
||||
sort(sortedPaths.begin(), sortedPaths.end()); //sort
|
||||
|
||||
//link
|
||||
map<Path, unsigned int> revisions_ss;
|
||||
for (vector<Path>::const_iterator j = sortedPaths.begin(); j != sortedPaths.end(); ++j){
|
||||
revisions_ss[*j] = ss_revisions.front();
|
||||
ss_revisions.pop_front();
|
||||
}
|
||||
|
||||
revisions[*i] = revisions_ss;
|
||||
}
|
||||
|
||||
if(!notempty)
|
||||
|
|
|
|||
|
|
@ -1700,11 +1700,6 @@ void LocalStore::commitStatePath(const Path & statePath)
|
|||
nix::commitStatePathTxn(noTxn, statePath);
|
||||
}
|
||||
|
||||
void LocalStore::updateRevisionsRecursively(const Path & statePath)
|
||||
{
|
||||
nix::updateRevisionsRecursivelyTxn(noTxn, statePath);
|
||||
}
|
||||
|
||||
void setSolidStateReferencesTxn(const Transaction & txn, const Path & statePath, const PathSet & paths)
|
||||
{
|
||||
Strings ss = Strings(paths.begin(), paths.end());
|
||||
|
|
|
|||
|
|
@ -107,8 +107,6 @@ public:
|
|||
bool queryAvailableStateRevisions(const Path & statePath, RevisionNumbers & revisions);
|
||||
|
||||
void commitStatePath(const Path & statePath);
|
||||
|
||||
void updateRevisionsRecursively(const Path & statePath);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -492,10 +492,4 @@ void RemoteStore::commitStatePath(const Path & statePath)
|
|||
|
||||
}
|
||||
|
||||
//TODO
|
||||
void RemoteStore::updateRevisionsRecursively(const Path & statePath)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -96,8 +96,6 @@ public:
|
|||
|
||||
void commitStatePath(const Path & statePath);
|
||||
|
||||
void updateRevisionsRecursively(const Path & statePath);
|
||||
|
||||
private:
|
||||
AutoCloseFD fdSocket;
|
||||
FdSink to;
|
||||
|
|
|
|||
|
|
@ -229,8 +229,6 @@ public:
|
|||
virtual bool queryAvailableStateRevisions(const Path & statePath, RevisionNumbers & revisions) = 0;
|
||||
|
||||
virtual void commitStatePath(const Path & statePath) = 0;
|
||||
|
||||
virtual void updateRevisionsRecursively(const Path & statePath) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -34,40 +34,17 @@ void createStateDirs(const DerivationStateOutputDirs & stateOutputDirs, const De
|
|||
Path statePath = stateOutputs.find("state")->second.statepath;
|
||||
string stateDir = statePath;
|
||||
|
||||
/*
|
||||
|
||||
string svnbin = nixSVNPath + "/svn";
|
||||
string svnadminbin = nixSVNPath + "/svnadmin";
|
||||
|
||||
PathSet intervalPaths;
|
||||
|
||||
//check if we can create state and staterepos dirs
|
||||
//check if we can create state dirs
|
||||
//TODO
|
||||
|
||||
//Create a repository for this state location
|
||||
string repos = getStateReposPath("stateOutput:staterepospath", stateDir);
|
||||
|
||||
printMsg(lvlTalkative, format("Adding statedir '%1%' from repository '%2%'") % stateDir % repos);
|
||||
|
||||
if(IsDirectory(repos))
|
||||
printMsg(lvlTalkative, format("Repos %1% already exists, so we use that repository") % repos);
|
||||
else{
|
||||
Strings p_args;
|
||||
p_args.push_back("create");
|
||||
p_args.push_back(repos);
|
||||
runProgram_AndPrintOutput(svnadminbin, true, p_args, "svnadmin"); //TODO create as nixbld.nixbld chmod 700... can you still commit then ??
|
||||
}
|
||||
|
||||
string statedir_svn = stateDir + "/.svn/";
|
||||
if( ! IsDirectory(statedir_svn) ){
|
||||
Strings p_args;
|
||||
p_args.push_back("checkout");
|
||||
p_args.push_back("file://" + repos);
|
||||
p_args.push_back(stateDir);
|
||||
runProgram_AndPrintOutput(svnbin, true, p_args, "svn"); //TODO checkout as user
|
||||
/*
|
||||
if( ! IsDirectory( ....... ) ){
|
||||
}
|
||||
else
|
||||
printMsg(lvlTalkative, format("Statedir %1% already exists, so dont check out its repository again") % statedir_svn);
|
||||
printMsg(lvlTalkative, format("Statedir %1% already exists, so dont ........ ???? ") % ...);
|
||||
*/
|
||||
|
||||
for (DerivationStateOutputDirs::const_reverse_iterator i = stateOutputDirs.rbegin(); i != stateOutputDirs.rend(); ++i){
|
||||
DerivationStateOutputDir d = i->second;
|
||||
|
|
@ -93,36 +70,22 @@ void createStateDirs(const DerivationStateOutputDirs & stateOutputDirs, const De
|
|||
//Initialize the counters for the statePaths that have an interval to 0
|
||||
vector<int> empty;
|
||||
store->setStatePathsInterval(intervalPaths, empty, true);
|
||||
|
||||
*/
|
||||
}
|
||||
|
||||
void commitStatePathTxn(const Transaction & txn, const Path & statePath)
|
||||
{
|
||||
//TODO: include code from: updateRevisionsRecursivelyTxn(txn, root_statePath);
|
||||
|
||||
if(!isValidStatePathTxn(txn, statePath))
|
||||
throw Error(format("path `%1%' is not a valid state path") % statePath);
|
||||
|
||||
|
||||
//queryDeriversStatePath??
|
||||
Derivation drv = derivationFromPath(queryStatePathDrvTxn(txn, statePath));
|
||||
|
||||
//Extract the neccecary info from each Drv
|
||||
DerivationStateOutputs stateOutputs = drv.stateOutputs;
|
||||
//Path statePath = stateOutputs.find("state")->second.statepath;
|
||||
DerivationStateOutputDirs stateOutputDirs = drv.stateOutputDirs;
|
||||
|
||||
//Specifiy the SVN binarys
|
||||
string svnbin = nixSVNPath + "/svn";
|
||||
string svnadminbin = nixSVNPath + "/svnadmin";
|
||||
printMsg(lvlError, format("Snapshotting statePath: %1%") % statePath);
|
||||
|
||||
//Print
|
||||
printMsg(lvlError, format("Committing statePath: %1%") % statePath);
|
||||
|
||||
//Vector includeing all commit scripts:
|
||||
vector<string> subversionedpaths;
|
||||
vector<bool> subversionedpathsCommitBoolean;
|
||||
vector<string> nonversionedpaths; //of type none, no versioning needed
|
||||
|
||||
//Get all the inverals from the database at once
|
||||
PathSet intervalPaths;
|
||||
for (DerivationStateOutputDirs::const_reverse_iterator i = stateOutputDirs.rbegin(); i != stateOutputDirs.rend(); ++i){
|
||||
|
|
@ -135,10 +98,10 @@ void commitStatePathTxn(const Transaction & txn, const Path & statePath)
|
|||
intervalPaths.insert(fullstatedir);
|
||||
}
|
||||
}
|
||||
vector<int> intervals = store->getStatePathsInterval(intervalPaths); //TODO !!!!!!!!!!!!! txn ??
|
||||
vector<int> intervals = store->getStatePathsInterval(intervalPaths); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! txn
|
||||
|
||||
int intervalAt=0;
|
||||
for (DerivationStateOutputDirs::const_reverse_iterator i = stateOutputDirs.rbegin(); i != stateOutputDirs.rend(); ++i){
|
||||
for (DerivationStateOutputDirs::const_iterator i = stateOutputDirs.begin(); i != stateOutputDirs.end(); ++i){
|
||||
DerivationStateOutputDir d = i->second;
|
||||
string thisdir = d.path;
|
||||
|
||||
|
|
@ -147,61 +110,50 @@ void commitStatePathTxn(const Transaction & txn, const Path & statePath)
|
|||
fullstatedir = statePath + "/";
|
||||
|
||||
if(d.type == "none"){
|
||||
nonversionedpaths.push_back(fullstatedir);
|
||||
continue;
|
||||
}
|
||||
|
||||
subversionedpaths.push_back(fullstatedir);
|
||||
|
||||
if(d.type == "interval"){
|
||||
//Get the interval-counter from the database
|
||||
int interval_counter = intervals[intervalAt];
|
||||
int interval = d.getInterval();
|
||||
subversionedpathsCommitBoolean.push_back(interval_counter % interval == 0);
|
||||
|
||||
|
||||
//update the interval
|
||||
intervals[intervalAt] = interval_counter + 1;
|
||||
intervalAt++;
|
||||
|
||||
if(interval_counter % interval != 0){ return; }
|
||||
}
|
||||
else if(d.type == "full")
|
||||
subversionedpathsCommitBoolean.push_back(true);
|
||||
else if(d.type == "manual") //TODO !!!!!
|
||||
subversionedpathsCommitBoolean.push_back(false);
|
||||
else if(d.type == "full"){ }
|
||||
else if(d.type == "manual"){ return; } //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
else
|
||||
throw Error(format("interval '%1%' is not handled in nix-state") % d.type);
|
||||
}
|
||||
|
||||
//Get the a repository for this state location
|
||||
string repos = getStateReposPath("stateOutput:staterepospath", statePath); //this is a copy from store-state.cc
|
||||
string checkoutcommand = svnbin + " --ignore-externals checkout file://" + repos + " " + statePath;
|
||||
throw Error(format("Type '%1%' is not handled in nix-state") % d.type);
|
||||
|
||||
//Call the commit script with the appropiate paramenters
|
||||
string subversionedstatepathsarray;
|
||||
for (vector<string>::iterator i = subversionedpaths.begin(); i != subversionedpaths.end(); ++i)
|
||||
subversionedstatepathsarray += *(i) + " ";
|
||||
|
||||
string subversionedpathsCommitBooleansarray;
|
||||
for (vector<bool>::iterator i = subversionedpathsCommitBoolean.begin(); i != subversionedpathsCommitBoolean.end(); ++i)
|
||||
subversionedpathsCommitBooleansarray += bool2string(*i) + " ";
|
||||
|
||||
string nonversionedstatepathsarray;
|
||||
for (vector<string>::iterator i = nonversionedpaths.begin(); i != nonversionedpaths.end(); ++i)
|
||||
nonversionedstatepathsarray += *(i) + " ";
|
||||
//We got here so we need to commit
|
||||
|
||||
unsigned int epoch_time;
|
||||
|
||||
if(pathExists(fullstatedir) || FileExist(fullstatedir)){
|
||||
epoch_time = take_snapshot(fullstatedir);
|
||||
printMsg(lvlError, format("Snapshotted '%1%' with id '%2%'") % fullstatedir % epoch_time);
|
||||
}
|
||||
else
|
||||
{
|
||||
//TODO !!!!!!!!!!!!!!
|
||||
}
|
||||
|
||||
//Put in database !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
//TODO
|
||||
}
|
||||
|
||||
//make the call to the commit script
|
||||
Strings p_args;
|
||||
p_args.push_back(svnbin);
|
||||
p_args.push_back(subversionedstatepathsarray);
|
||||
p_args.push_back(subversionedpathsCommitBooleansarray);
|
||||
p_args.push_back(nonversionedstatepathsarray);
|
||||
p_args.push_back(checkoutcommand);
|
||||
p_args.push_back(statePath);
|
||||
runProgram_AndPrintOutput(nixLibexecDir + "/nix/nix-statecommit.sh", true, p_args, "svn");
|
||||
|
||||
//Update the intervals again
|
||||
//setStatePathsIntervalTxn(txn, intervalPaths, intervals); //TODO!!!!!!!!!!!!!!!!!!!!!! uncomment and txn ??
|
||||
//setStatePathsIntervalTxn(txn, intervalPaths, intervals); //TODO!!!!!!!!!!!!!!!!!!!!!!!!!!!!! uncomment
|
||||
}
|
||||
|
||||
/*
|
||||
* This function takes all state requisites (references) and revision numbers and stores them ...
|
||||
*/
|
||||
/*
|
||||
void updateRevisionsRecursivelyTxn(const Transaction & txn, const Path & statePath)
|
||||
{
|
||||
//Save all revisions for the call to
|
||||
|
|
@ -229,13 +181,6 @@ void updateRevisionsRecursivelyTxn(const Transaction & txn, const Path & statePa
|
|||
|
||||
int readRevisionNumber(Path statePath)
|
||||
{
|
||||
string s = "/media/ext3cow/cca/";
|
||||
const char* ss = s.c_str();
|
||||
unsigned int i = take_snapshot(ss);
|
||||
printMsg(lvlError, format("SS: '%1%'") % i);
|
||||
|
||||
////////
|
||||
/*
|
||||
string svnbin = nixSVNPath + "/svn";
|
||||
RevisionNumbers revisions;
|
||||
|
||||
|
|
@ -257,8 +202,12 @@ int readRevisionNumber(Path statePath)
|
|||
throw Error(format("Cannot read revision number of path '%1%'") % repos);
|
||||
|
||||
return revision;
|
||||
*/
|
||||
return 0;
|
||||
}
|
||||
*/
|
||||
|
||||
// string s = "/media/ext3cow/cca/";
|
||||
// unsigned int i = take_snapshot(s);
|
||||
// printMsg(lvlError, format("SS: '%1%'") % i);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,10 +14,10 @@ void createStateDirs(const DerivationStateOutputDirs & stateOutputDirs, const De
|
|||
void commitStatePathTxn(const Transaction & txn, const Path & statePath);
|
||||
|
||||
/* TODO */
|
||||
void updateRevisionsRecursivelyTxn(const Transaction & txn, const Path & statePath);
|
||||
//void updateRevisionsRecursivelyTxn(const Transaction & txn, const Path & statePath);
|
||||
|
||||
/* TODO */
|
||||
int readRevisionNumber(Path statePath);
|
||||
//int readRevisionNumber(Path statePath);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue