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

before removing isStateComponentTxn

This commit is contained in:
Wouter den Breejen 2007-07-09 14:30:57 +00:00
parent 9257f16c85
commit b7654ab716
10 changed files with 151 additions and 111 deletions

View file

@ -466,7 +466,7 @@ void Database::splitStatePathRevision(const Path & revisionedStatePath, Path & s
int Database::getNewRevisionNumber(const Transaction & txn, TableId table, int Database::getNewRevisionNumber(const Transaction & txn, TableId table,
const Path & statePath) const Path & statePath, bool update)
{ {
//query //query
string data; string data;
@ -482,8 +482,10 @@ int Database::getNewRevisionNumber(const Transaction & txn, TableId table,
if(!succeed) if(!succeed)
throw Error(format("Malformed revision counter value of path '%1%'") % statePath); throw Error(format("Malformed revision counter value of path '%1%'") % statePath);
revision++; if(update){
setString(txn, table, statePath, int2String(revision)); revision++;
setString(txn, table, statePath, int2String(revision));
}
return revision; return revision;
} }

View file

@ -63,10 +63,6 @@ private:
/* TODO */ /* TODO */
bool lookupHighestRevivison(const Strings & keys, const Path & statePath, string & key, int lowerthan = -1); bool lookupHighestRevivison(const Strings & keys, const Path & statePath, string & key, int lowerthan = -1);
/* TODO */
int getNewRevisionNumber(const Transaction & txn, TableId table, const Path & statePath);
public: public:
Database(); Database();
~Database(); ~Database();
@ -126,6 +122,10 @@ public:
/* Returns all available revision numbers of the given state path */ /* Returns all available revision numbers of the given state path */
bool queryAvailableStateRevisions(const Transaction & txn, TableId table, bool queryAvailableStateRevisions(const Transaction & txn, TableId table,
const Path & statePath, RevisionNumbers & revisions); const Path & statePath, RevisionNumbers & revisions);
/* TODO */
int getNewRevisionNumber(const Transaction & txn, TableId table, const Path & statePath, bool update = true);
}; };

View file

@ -532,7 +532,7 @@ void setReferences(const Transaction & txn, const Path & store_or_statePath,
} }
void queryReferences(const Transaction & txn, void queryReferencesTxn(const Transaction & txn,
const Path & store_or_statePath, PathSet & references, const int revision) const Path & store_or_statePath, PathSet & references, const int revision)
{ {
Paths references2; Paths references2;
@ -551,10 +551,10 @@ void queryReferences(const Transaction & txn,
void LocalStore::queryReferences(const Path & storePath, void LocalStore::queryReferences(const Path & storePath,
PathSet & references, const int revision) PathSet & references, const int revision)
{ {
nix::queryReferences(noTxn, storePath, references, revision); nix::queryReferencesTxn(noTxn, storePath, references, revision);
} }
void queryStateReferences(const Transaction & txn, void queryStateReferencesTxn(const Transaction & txn,
const Path & store_or_statePath, PathSet & stateReferences, const int revision) const Path & store_or_statePath, PathSet & stateReferences, const int revision)
{ {
Paths stateReferences2; Paths stateReferences2;
@ -571,7 +571,22 @@ void queryStateReferences(const Transaction & txn,
void LocalStore::queryStateReferences(const Path & componentOrstatePath, PathSet & stateReferences, const int revision) void LocalStore::queryStateReferences(const Path & componentOrstatePath, PathSet & stateReferences, const int revision)
{ {
nix::queryStateReferences(noTxn, componentOrstatePath, stateReferences, revision); nix::queryStateReferencesTxn(noTxn, componentOrstatePath, stateReferences, revision);
}
void queryAllReferencesTxn(const Transaction & txn, const Path & path, PathSet & allReferences, const int revision)
{
PathSet references;
PathSet stateReferences;
queryReferencesTxn(txn, path, references, revision);
queryStateReferencesTxn(txn, path, stateReferences, revision);
allReferences = pathSets_union(references, stateReferences);
}
//TODO !!!!!!!!!!!!!!!!!!!!!!!!!!! make 1 function with 2 bools (component=t/f state=t/f) and 3 Pathsets (component, state, all)
void LocalStore::queryAllReferences(const Path & path, PathSet & allReferences, const int revision)
{
queryAllReferencesTxn(noTxn, path, allReferences, revision);
} }
void queryReferrers(const Transaction & txn, void queryReferrers(const Transaction & txn,
@ -649,16 +664,21 @@ void addStateDeriver(const Transaction & txn, const Path & storePath, const Path
} }
bool isStateComponentTxn(const Transaction & txn, const Path & storePath)
//TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! remove this entire function, replace by isValidStatePathTxn
bool isStateComponentTxn(const Transaction & txn, const Path & statePath)
{ {
isValidPathTxn(txn, storePath); //return isValidStatePathTxn(txn, statePath);
string data; string data;
return nixDB.queryString(txn, dbStateInfo, storePath, data); return nixDB.queryString(txn, dbStateInfo, statePath, data);
} }
bool LocalStore::isStateComponent(const Path & storePath) bool LocalStore::isStateComponent(const Path & statePath)
{ {
return nix::isStateComponentTxn(noTxn, storePath); return nix::isStateComponentTxn(noTxn, statePath);
} }
@ -1128,7 +1148,7 @@ void LocalStore::exportPath(const Path & path, bool sign,
writeString(path, hashAndWriteSink); writeString(path, hashAndWriteSink);
PathSet references; PathSet references;
nix::queryReferences(txn, path, references, -1); //TODO we can only now export the final revision nix::queryReferencesTxn(txn, path, references, -1); //TODO we can only now export the final revision
writeStringSet(references, hashAndWriteSink); writeStringSet(references, hashAndWriteSink);
Path deriver = queryDeriver(txn, path); Path deriver = queryDeriver(txn, path);
@ -1410,7 +1430,7 @@ void verifyStore(bool checkContents)
else { else {
bool isValid = validPaths.find(*i) != validPaths.end(); bool isValid = validPaths.find(*i) != validPaths.end();
PathSet references; PathSet references;
queryReferences(txn, *i, references, -1); //TODO queryReferencesTxn(txn, *i, references, -1); //TODO
for (PathSet::iterator j = references.begin(); for (PathSet::iterator j = references.begin();
j != references.end(); ++j) j != references.end(); ++j)
{ {
@ -1459,10 +1479,10 @@ void verifyStore(bool checkContents)
else { else {
PathSet references; PathSet references;
queryReferences(txn, from, references, -1); //TODO queryReferencesTxn(txn, from, references, -1); //TODO
PathSet stateReferences; //already a stateReferrers here! PathSet stateReferences; //already a stateReferrers here!
queryStateReferences(txn, from, stateReferences, -1); //TODO CHECK FOR ALL REVISIONS ! queryStateReferencesTxn(txn, from, stateReferences, -1); //TODO CHECK FOR ALL REVISIONS !
if (find(references.begin(), references.end(), to) == references.end()) { if (find(references.begin(), references.end(), to) == references.end()) {
printMsg(lvlError, format("adding missing referrer mapping from `%1%' to `%2%'") % from % to); printMsg(lvlError, format("adding missing referrer mapping from `%1%' to `%2%'") % from % to);
@ -1508,11 +1528,9 @@ void LocalStore::setStatePathsInterval(const PathSet & statePaths, const vector<
nix::setStatePathsInterval(statePaths, intervals, allZero); nix::setStatePathsInterval(statePaths, intervals, allZero);
} }
vector<int> getStatePathsInterval(const PathSet & statePaths) vector<int> getStatePathsIntervalTxn(const Transaction & txn, const PathSet & statePaths)
{ {
Transaction txn(nixDB); //TODO should u do a transaction here? ... this might delay the process ...
string data; string data;
Paths referers; Paths referers;
@ -1531,14 +1549,13 @@ vector<int> getStatePathsInterval(const PathSet & statePaths)
intervals.push_back(n); intervals.push_back(n);
} }
txn.commit();
return intervals; return intervals;
} }
vector<int> LocalStore::getStatePathsInterval(const PathSet & statePaths) vector<int> LocalStore::getStatePathsInterval(const PathSet & statePaths)
{ {
return nix::getStatePathsInterval(statePaths); return nix::getStatePathsIntervalTxn(noTxn, statePaths);
} }
@ -1671,11 +1688,11 @@ void getDependenciesAtBuildTime(const Transaction & txn, const Path & drvPath)
//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
, PathSet & newFoundComponentReferences, PathSet & newFoundStateReferences) //only for recursion , PathSet & newFoundComponentReferences, PathSet & newFoundStateReferences, const int revision) //only for recursion
{ {
//Check if is a state Path //Check if is a state Path
if(! isStateComponentTxn(txn, statePath)) if(! isStateComponentTxn(txn, statePath))
throw Error(format("This path '%1%' is not a state path") % statePath); throw Error(format("This path '%1%' is not a state path 1") % statePath);
//TODO check if path is not a shared path ! //TODO check if path is not a shared path !
//TODO //TODO
@ -1718,8 +1735,8 @@ void scanAndUpdateAllReferencesTxn(const Transaction & txn, const Path & statePa
//Retrieve old references //Retrieve old references
PathSet old_references; PathSet old_references;
PathSet old_state_references; PathSet old_state_references;
queryReferences(txn, statePath, old_references, -1); //get the latsest references queryReferencesTxn(txn, statePath, old_references, -1); //get the latsest references
queryStateReferences(txn, statePath, old_state_references, -1); queryStateReferencesTxn(txn, statePath, old_state_references, -1);
//Check for added and removed paths //Check for added and removed paths
PathSet diff_references_removed; PathSet diff_references_removed;
@ -1746,30 +1763,7 @@ void scanAndUpdateAllReferencesTxn(const Transaction & txn, const Path & statePa
for (PathSet::iterator i = diff_state_references_added.begin(); i != diff_state_references_added.end(); ++i) for (PathSet::iterator i = diff_state_references_added.begin(); i != diff_state_references_added.end(); ++i)
printMsg(lvlError, format("Added state reference found!: '%1%' in state path '%2%'") % (*i) % statePath); printMsg(lvlError, format("Added state reference found!: '%1%' in state path '%2%'") % (*i) % statePath);
//TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! //Finally register the paths valid with a new revision number
/*
Register Valid again if neccesary
Update the 2 references tables: all state paths get: Path statepath --> List(int revnumber, List(References))
TODO EDIT TABLES references,references_state,referrers,referrers_state
New table stateRevisionClosure: Path StatePath + int revision --> List(int revnumbers)
A1(STATEPATH) --> UPDATE ALL STATE REFERENCES IN DB (TRANSACTION)
A2(STATEPATH [+ REV]) --> GIVE ALL STATE REFERENCES IN DB
B1(STATEPATH) --> SCAN ALL REFERENCES IN DB, LINK TO REVISION NUMBERS (WITH CALL TO A2) (TRANSACTION)
B2(STATEPATH [+ REV]) --> GIVES ALL REFERENCES
//update all revision numbers (transaction) NEW FUN THAT UPDATES THE REVISIONS
//update all revision numbers + references (transaction)
//update all references
*/
/*
if(diff_references_added.size() != 0 || diff_state_references_added.size() != 0){ if(diff_references_added.size() != 0 || diff_state_references_added.size() != 0){
printMsg(lvlError, format("Updating new references for statepath: '%1%'")% statePath); printMsg(lvlError, format("Updating new references for statepath: '%1%'")% statePath);
Path drvPath = queryStatePathDrv(txn, statePath); Path drvPath = queryStatePathDrv(txn, statePath);
@ -1778,18 +1772,12 @@ void scanAndUpdateAllReferencesTxn(const Transaction & txn, const Path & statePa
Hash(), //emtpy hash Hash(), //emtpy hash
state_references, state_references,
state_stateReferences, state_stateReferences,
drvPath drvPath,
); revision);
}*/ }
} }
void LocalStore::scanAndUpdateAllReferences(const Path & statePath) void scanAndUpdateAllReferencesRecusively(const Transaction & txn, const Path & storeOrStatePath, const int revision) //TODO Can also work for statePaths???
{
PathSet empty;
return nix::scanAndUpdateAllReferencesTxn(noTxn, statePath, empty, empty);
}
void scanAndUpdateAllReferencesRecusively(const Transaction & txn, const Path & storeOrStatePath) //TODO Can also work for statePaths???
{ {
//get all state current state references recursively //get all state current state references recursively
PathSet statePaths; PathSet statePaths;
@ -1801,48 +1789,71 @@ void scanAndUpdateAllReferencesRecusively(const Transaction & txn, const Path &
//Scan, update, call recursively //Scan, update, call recursively
PathSet newFoundComponentReferences; PathSet newFoundComponentReferences;
PathSet newFoundStateReferences; PathSet newFoundStateReferences;
scanAndUpdateAllReferencesTxn(txn, *i, newFoundComponentReferences, newFoundStateReferences); scanAndUpdateAllReferencesTxn(txn, *i, newFoundComponentReferences, newFoundStateReferences, revision);
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)
scanAndUpdateAllReferencesRecusively(txn, *j); scanAndUpdateAllReferencesRecusively(txn, *j, revision);
} }
} }
void LocalStore::scanAndUpdateAllReferencesRecusively(const Path & storeOrStatePath) void scanAndUpdateAllReferencesTxn(const Transaction & txn, const Path & storeOrStatePath, const int revision, bool recursive)
{ {
return nix::scanAndUpdateAllReferencesRecusively(noTxn, storeOrStatePath); if(recursive)
nix::scanAndUpdateAllReferencesRecusively(txn, storeOrStatePath, revision);
else{
//TODO check if storeOrStatePath is a statePath, else throw error
PathSet empty;
nix::scanAndUpdateAllReferencesTxn(txn, storeOrStatePath, empty, empty, revision);
}
} }
void setStateRevisions(const Transaction & txn, const Path & statePath, const RevisionNumbersSet & revisions, const int revision) void LocalStore::scanAndUpdateAllReferences(const Path & storeOrStatePath, const int revision, bool recursive)
{
nix::scanAndUpdateAllReferencesTxn(noTxn, storeOrStatePath, revision, recursive);
}
void setStateRevisionsTxn(const Transaction & txn, const Path & statePath, const RevisionNumbersSet & revisions, const int revision)
{ {
nixDB.setStateRevisions(txn, dbStateRevisions, statePath, revisions, revision); nixDB.setStateRevisions(txn, dbStateRevisions, statePath, revisions, revision);
} }
void LocalStore::setStateRevisions(const Path & statePath, const RevisionNumbersSet & revisions, const int revision) void LocalStore::setStateRevisions(const Path & statePath, const RevisionNumbersSet & revisions, const int revision)
{ {
nix::setStateRevisions(noTxn, statePath, revisions, revision); nix::setStateRevisionsTxn(noTxn, statePath, revisions, revision);
} }
bool queryStateRevisions(const Transaction & txn, const Path & statePath, RevisionNumbers & revisions, const int revision) bool queryStateRevisionsTxn(const Transaction & txn, const Path & statePath, RevisionNumbers & revisions, const int revision)
{ {
return nixDB.queryStateRevisions(txn, dbStateRevisions, statePath, revisions, revision); return nixDB.queryStateRevisions(txn, dbStateRevisions, statePath, revisions, revision);
} }
bool LocalStore::queryStateRevisions(const Path & statePath, RevisionNumbers & revisions, const int revision) bool LocalStore::queryStateRevisions(const Path & statePath, RevisionNumbers & revisions, const int revision)
{ {
return nix::queryStateRevisions(noTxn, statePath, revisions, revision); return nix::queryStateRevisionsTxn(noTxn, statePath, revisions, revision);
} }
bool queryAvailableStateRevisions(const Transaction & txn, const Path & statePath, RevisionNumbers & revisions) bool queryAvailableStateRevisionsTxn(const Transaction & txn, const Path & statePath, RevisionNumbers & revisions)
{ {
return nixDB.queryAvailableStateRevisions(txn, dbStateRevisions, statePath, revisions); return nixDB.queryAvailableStateRevisions(txn, dbStateRevisions, statePath, revisions);
} }
bool LocalStore::queryAvailableStateRevisions(const Path & statePath, RevisionNumbers & revisions) bool LocalStore::queryAvailableStateRevisions(const Path & statePath, RevisionNumbers & revisions)
{ {
return nix::queryAvailableStateRevisions(noTxn, statePath, revisions); return nix::queryAvailableStateRevisionsTxn(noTxn, statePath, revisions);
}
int getNewRevisionNumberTxn(const Transaction & txn, const Path & statePath, const bool update)
{
return nixDB.getNewRevisionNumber(txn, dbStateRevisions, statePath, update);
}
int LocalStore::getNewRevisionNumber(const Path & statePath, bool update)
{
return nix::getNewRevisionNumberTxn(noTxn, statePath, update);
} }
@ -1916,7 +1927,7 @@ static void upgradeStore07()
} }
PathSet prevReferences; PathSet prevReferences;
queryReferences(txn, path, prevReferences, -1); queryReferencesTxn(txn, path, prevReferences, -1);
if (prevReferences.size() > 0 && references != prevReferences) if (prevReferences.size() > 0 && references != prevReferences)
printMsg(lvlError, format("warning: conflicting references for `%1%'") % path); printMsg(lvlError, format("warning: conflicting references for `%1%'") % path);

View file

@ -55,6 +55,8 @@ public:
void queryStateReferences(const Path & storePath, PathSet & stateReferences, const int revision); void queryStateReferences(const Path & storePath, PathSet & stateReferences, const int revision);
void queryAllReferences(const Path & path, PathSet & allReferences, const int revision);
void queryReferrers(const Path & path, PathSet & referrers, const int revision); void queryReferrers(const Path & path, PathSet & referrers, const int revision);
void queryStateReferrers(const Path & path, PathSet & stateReferrers, const int revision); void queryStateReferrers(const Path & path, PathSet & stateReferrers, const int revision);
@ -98,9 +100,7 @@ public:
void storePathRequisites(const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool & withComponents, const bool & withState, const int revision); void storePathRequisites(const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool & withComponents, const bool & withState, const int revision);
void scanAndUpdateAllReferences(const Path & statePath); void scanAndUpdateAllReferences(const Path & statePath, const int revision, bool recursive);
void scanAndUpdateAllReferencesRecusively(const Path & storeOrstatePath);
void setStateRevisions(const Path & statePath, const RevisionNumbersSet & revisions, const int revision); void setStateRevisions(const Path & statePath, const RevisionNumbersSet & revisions, const int revision);
@ -108,6 +108,8 @@ public:
bool queryAvailableStateRevisions(const Path & statePath, RevisionNumbers & revisions); bool queryAvailableStateRevisions(const Path & statePath, RevisionNumbers & revisions);
int getNewRevisionNumber(const Path & statePath, bool update = true);
}; };

View file

@ -238,6 +238,12 @@ void RemoteStore::queryStateReferences(const Path & path,
} }
void RemoteStore::queryAllReferences(const Path & path,
PathSet & allReferences, const int revision)
{
//TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
}
void RemoteStore::queryReferrers(const Path & path, void RemoteStore::queryReferrers(const Path & path,
PathSet & referrers, const int revision) PathSet & referrers, const int revision)
@ -463,13 +469,7 @@ void RemoteStore::storePathRequisites(const Path & storeOrstatePath, const bool
} }
//TODO //TODO
void RemoteStore::scanAndUpdateAllReferences(const Path & statePath) void RemoteStore::scanAndUpdateAllReferences(const Path & statePath, const int revision, bool recursive)
{
}
//TODO
void RemoteStore::scanAndUpdateAllReferencesRecusively(const Path & storeOrstatePath)
{ {
} }
@ -492,4 +492,10 @@ bool RemoteStore::queryAvailableStateRevisions(const Path & statePath, RevisionN
return false; return false;
} }
//TODO
int RemoteStore::getNewRevisionNumber(const Path & statePath, bool update)
{
return 0;
}
} }

View file

@ -43,6 +43,8 @@ public:
void queryStateReferences(const Path & storePath, PathSet & stateReferences, const int revision); void queryStateReferences(const Path & storePath, PathSet & stateReferences, const int revision);
void queryAllReferences(const Path & path, PathSet & allReferences, const int revision);
void queryReferrers(const Path & path, PathSet & referrers, const int revision); void queryReferrers(const Path & path, PathSet & referrers, const int revision);
void queryStateReferrers(const Path & path, PathSet & stateReferrers, const int revision); void queryStateReferrers(const Path & path, PathSet & stateReferrers, const int revision);
@ -86,15 +88,15 @@ public:
void storePathRequisites(const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool & withComponents, const bool & withState, const int revision); void storePathRequisites(const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool & withComponents, const bool & withState, const int revision);
void scanAndUpdateAllReferences(const Path & statePath); void scanAndUpdateAllReferences(const Path & statePath, const int revision, bool recursive);
void scanAndUpdateAllReferencesRecusively(const Path & storeOrstatePath);
void setStateRevisions(const Path & statePath, const RevisionNumbersSet & revisions, const int revision); void setStateRevisions(const Path & statePath, const RevisionNumbersSet & revisions, const int revision);
bool queryStateRevisions(const Path & statePath, RevisionNumbers & revisions, const int revision); bool queryStateRevisions(const Path & statePath, RevisionNumbers & revisions, const int revision);
bool queryAvailableStateRevisions(const Path & statePath, RevisionNumbers & revisions); bool queryAvailableStateRevisions(const Path & statePath, RevisionNumbers & revisions);
int getNewRevisionNumber(const Path & statePath, bool update = true);
private: private:
AutoCloseFD fdSocket; AutoCloseFD fdSocket;

View file

@ -87,6 +87,8 @@ public:
The result is not cleared. */ The result is not cleared. */
virtual void queryStateReferences(const Path & storePath, PathSet & stateReferences, const int revision) = 0; virtual void queryStateReferences(const Path & storePath, PathSet & stateReferences, const int revision) = 0;
virtual void queryAllReferences(const Path & path, PathSet & allReferences, const int revision) = 0;
/* Queries the set of incoming FS references for a store path. /* Queries the set of incoming FS references for a store path.
The result is not cleared. */ The result is not cleared. */
virtual void queryReferrers(const Path & path, virtual void queryReferrers(const Path & path,
@ -218,10 +220,7 @@ public:
virtual void storePathRequisites(const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool & withComponents, const bool & withState, const int revision) = 0; virtual void storePathRequisites(const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool & withComponents, const bool & withState, const int revision) = 0;
/* TODO */ /* TODO */
virtual void scanAndUpdateAllReferences(const Path & statePath) = 0; virtual void scanAndUpdateAllReferences(const Path & statePath, const int revision, bool recursive) = 0;
/* TODO */
virtual void scanAndUpdateAllReferencesRecusively(const Path & storeOrstatePath) = 0;
/* TODO */ /* TODO */
virtual void setStateRevisions(const Path & statePath, const RevisionNumbersSet & revisions, const int revision) = 0; virtual void setStateRevisions(const Path & statePath, const RevisionNumbersSet & revisions, const int revision) = 0;
@ -231,6 +230,9 @@ public:
/* TODO */ /* TODO */
virtual bool queryAvailableStateRevisions(const Path & statePath, RevisionNumbers & revisions) = 0; virtual bool queryAvailableStateRevisions(const Path & statePath, RevisionNumbers & revisions) = 0;
/* TODO */
virtual int getNewRevisionNumber(const Path & statePath, bool update = true) = 0;
}; };

View file

@ -10,7 +10,6 @@
#include "help.txt.hh" #include "help.txt.hh"
#include "local-store.hh" #include "local-store.hh"
#include "derivations.hh" #include "derivations.hh"
#include "store-api.hh" //TODO REMOVE
using namespace nix; using namespace nix;
using std::cin; using std::cin;
@ -23,6 +22,7 @@ typedef void (* Operation) (Strings opFlags, Strings opArgs);
string stateIdentifier; string stateIdentifier;
string username; string username;
int revision_arg; int revision_arg;
bool scanforReferences = false;
/************************* Build time Functions ******************************/ /************************* Build time Functions ******************************/
@ -346,7 +346,8 @@ static void opRunComponent(Strings opFlags, Strings opArgs)
//******************* With everything in place, we call the commit script on all statePaths ********************** //******************* With everything in place, we call the commit script on all statePaths **********************
RevisionNumbersSet rivisionMapping; PathSet statePaths;
RevisionNumbersSet rivisionMapping;
for (PathSet::iterator d = root_drvs.begin(); d != root_drvs.end(); ++d) //TODO first commit own state path? for (PathSet::iterator d = root_drvs.begin(); d != root_drvs.end(); ++d) //TODO first commit own state path?
{ {
@ -378,7 +379,7 @@ static void opRunComponent(Strings opFlags, Strings opArgs)
intervalPaths.insert(fullstatedir); intervalPaths.insert(fullstatedir);
} }
} }
vector<int> intervals = store->getStatePathsInterval(intervalPaths); vector<int> intervals = store->getStatePathsInterval(intervalPaths); //TODO !!!!!!!!!!!!! txn ??
int intervalAt=0; int intervalAt=0;
for (DerivationStateOutputDirs::const_reverse_iterator i = stateOutputDirs.rbegin(); i != stateOutputDirs.rend(); ++i){ for (DerivationStateOutputDirs::const_reverse_iterator i = stateOutputDirs.rbegin(); i != stateOutputDirs.rend(); ++i){
@ -446,22 +447,33 @@ static void opRunComponent(Strings opFlags, Strings opArgs)
runProgram_AndPrintOutput(nixLibexecDir + "/nix/nix-statecommit.sh", true, p_args, "svn"); runProgram_AndPrintOutput(nixLibexecDir + "/nix/nix-statecommit.sh", true, p_args, "svn");
//Update the intervals again //Update the intervals again
//store->setStatePathsInterval(intervalPaths, intervals); //TODO!!!!!!!!!!!!!!!!!!!!!! uncomment //store->setStatePathsInterval(intervalPaths, intervals); //TODO!!!!!!!!!!!!!!!!!!!!!! uncomment and txn ??
//TODO statePaths.insert(statePath); //Insert StatePath
//Scan if needed //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! needs a new revision number
if(false)
store->scanAndUpdateAllReferencesRecusively(statePath);
rivisionMapping[statePath] = readRevisionNumber(drv); //Get current numbers rivisionMapping[statePath] = readRevisionNumber(drv); //Get current numbers
} }
//Store the revision numbers in the database for this statePath to a new revision //1.NEW TRANSACTION
store->setStateRevisions(root_statePath, rivisionMapping, -1); //TODO
//Get new revision number
int newRevisionNumber = store->getNewRevisionNumber(root_statePath);
//Scan for new references, and update with revision number
if(scanforReferences){
for (PathSet::iterator i = statePaths.begin(); i != statePaths.end(); ++i)
store->scanAndUpdateAllReferences(*i, newRevisionNumber, true);
}
//Store the revision numbers in the database for this statePath with revision number
store->setStateRevisions(root_statePath, rivisionMapping, newRevisionNumber);
//4. COMMIT
//TODO
//Debugging
RevisionNumbers getRivisions; RevisionNumbers getRivisions;
bool b = store->queryStateRevisions(root_statePath, getRivisions, -1); bool b = store->queryStateRevisions(root_statePath, getRivisions, -1);
for (RevisionNumbers::iterator i = getRivisions.begin(); i != getRivisions.end(); ++i){ for (RevisionNumbers::iterator i = getRivisions.begin(); i != getRivisions.end(); ++i){
printMsg(lvlError, format("REV %1%") % int2String(*i)); printMsg(lvlError, format("REV %1%") % int2String(*i));
} }
@ -629,6 +641,8 @@ void run(Strings args)
*/ */
else if (arg == "--scanreferences")
scanforReferences = true;
else if (arg.substr(0,13) == "--identifier=") else if (arg.substr(0,13) == "--identifier=")
stateIdentifier = arg.substr(13,arg.length()); stateIdentifier = arg.substr(13,arg.length());
else if (arg.substr(0,7) == "--user=") else if (arg.substr(0,7) == "--user=")

View file

@ -111,11 +111,12 @@ void printDotGraph(const PathSet & roots)
cout << makeNode(path, symbolicName(path), "#ff0000"); cout << makeNode(path, symbolicName(path), "#ff0000");
PathSet references; PathSet allReferences;
store->queryReferences(path, references, -1); //TODO maybe also include state paths? store->queryAllReferences(path, allReferences, -1);
for (PathSet::iterator i = references.begin(); for (PathSet::iterator i = allReferences.begin();
i != references.end(); ++i) i != allReferences.end(); ++i)
{ {
if (*i != path) { if (*i != path) {
workList.insert(*i); workList.insert(*i);

View file

@ -211,8 +211,8 @@ static void printTree(const Path & path,
cout << format("%1%%2%\n") % firstPad % path; cout << format("%1%%2%\n") % firstPad % path;
PathSet references; PathSet allReferences;
store->queryReferences(path, references, -1); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! Adjust printTree, include state paths! store->queryAllReferences(path, allReferences, -1);
#if 0 #if 0
for (PathSet::iterator i = drv.inputSrcs.begin(); for (PathSet::iterator i = drv.inputSrcs.begin();
@ -224,7 +224,7 @@ static void printTree(const Path & path,
closure(B). That is, if derivation A is an (possibly indirect) closure(B). That is, if derivation A is an (possibly indirect)
input of B, then A is printed first. This has the effect of input of B, then A is printed first. This has the effect of
flattening the tree, preventing deeply nested structures. */ flattening the tree, preventing deeply nested structures. */
Paths sorted = topoSortPaths(references); Paths sorted = topoSortPaths(allReferences);
reverse(sorted.begin(), sorted.end()); reverse(sorted.begin(), sorted.end());
for (Paths::iterator i = sorted.begin(); i != sorted.end(); ++i) { for (Paths::iterator i = sorted.begin(); i != sorted.end(); ++i) {
@ -362,7 +362,7 @@ static void opQuery(Strings opFlags, Strings opArgs)
} }
break; break;
case qTree: { //TODO include state path? case qTree: {
PathSet done; PathSet done;
for (Strings::iterator i = opArgs.begin(); for (Strings::iterator i = opArgs.begin();
i != opArgs.end(); ++i) i != opArgs.end(); ++i)