mirror of
https://github.com/NixOS/nix.git
synced 2025-11-26 12:10:59 +01:00
This commit is contained in:
parent
53e31381fa
commit
1747d649c5
14 changed files with 131 additions and 157 deletions
|
|
@ -1483,13 +1483,12 @@ void DerivationGoal::startBuilder()
|
||||||
tmpDir = createTempDir();
|
tmpDir = createTempDir();
|
||||||
|
|
||||||
/* Create the state directory where the component can store it's state files place */
|
/* Create the state directory where the component can store it's state files place */
|
||||||
//TODO MOVEEEEEEEEEEE
|
|
||||||
//We only create state dirs when state is enabled and when the dirs need to be created before the installation
|
//We only create state dirs when state is enabled and when the dirs need to be created before the installation
|
||||||
if(drv.stateOutputs.size() != 0){
|
if(drv.stateOutputs.size() != 0){
|
||||||
|
|
||||||
/* we check the recalculated state path at build time with the correct user for securiyt */
|
/* we check the recalculated state path at build time with the correct user for securiyt */
|
||||||
checkStatePath(drv);
|
checkStatePath(drv);
|
||||||
|
|
||||||
if(drv.stateOutputs.find("state")->second.getCreateDirsBeforeInstall())
|
if(drv.stateOutputs.find("state")->second.getCreateDirsBeforeInstall())
|
||||||
createSubStateDirsTxn(noTxn, drv.stateOutputDirs, drv.stateOutputs);
|
createSubStateDirsTxn(noTxn, drv.stateOutputDirs, drv.stateOutputs);
|
||||||
}
|
}
|
||||||
|
|
@ -1727,7 +1726,6 @@ void DerivationGoal::computeClosure()
|
||||||
PathSet state_stateReferences; //all state references in statepath
|
PathSet state_stateReferences; //all state references in statepath
|
||||||
map<Path, Hash> contentHashes;
|
map<Path, Hash> contentHashes;
|
||||||
|
|
||||||
//TODO MOVE THIS TO A PLACE THAT ALSO GETS CALLED WHEN WE DONT NEED TO BUILD ANYTHING
|
|
||||||
//We create state dirs only when state is enabled and when the dirs need to be created after the installation
|
//We create state dirs only when state is enabled and when the dirs need to be created after the installation
|
||||||
if(drv.stateOutputs.size() != 0)
|
if(drv.stateOutputs.size() != 0)
|
||||||
if(!drv.stateOutputs.find("state")->second.getCreateDirsBeforeInstall())
|
if(!drv.stateOutputs.find("state")->second.getCreateDirsBeforeInstall())
|
||||||
|
|
@ -1920,8 +1918,10 @@ void DerivationGoal::computeClosure()
|
||||||
setStateRevisionsTxn(txn, rivisionMapping, statePath, "Initial build revision.");
|
setStateRevisionsTxn(txn, rivisionMapping, statePath, "Initial build revision.");
|
||||||
|
|
||||||
//Convert stateInfo from drv to DB format
|
//Convert stateInfo from drv to DB format
|
||||||
|
//And set all interval-ed paths to zero to begin with
|
||||||
DerivationStateOutputDirs stateOutputDirs = drv.stateOutputDirs;
|
DerivationStateOutputDirs stateOutputDirs = drv.stateOutputDirs;
|
||||||
StateInfos infos;
|
StateInfos infos;
|
||||||
|
CommitIntervals intervals;
|
||||||
for (DerivationStateOutputDirs::const_reverse_iterator j = stateOutputDirs.rbegin(); j != stateOutputDirs.rend(); ++j){
|
for (DerivationStateOutputDirs::const_reverse_iterator j = stateOutputDirs.rbegin(); j != stateOutputDirs.rend(); ++j){
|
||||||
DerivationStateOutputDir d = j->second;
|
DerivationStateOutputDir d = j->second;
|
||||||
StateInfo si;
|
StateInfo si;
|
||||||
|
|
@ -1936,7 +1936,12 @@ void DerivationGoal::computeClosure()
|
||||||
else
|
else
|
||||||
si.interval = 0;
|
si.interval = 0;
|
||||||
infos.push_back(si);
|
infos.push_back(si);
|
||||||
|
|
||||||
|
|
||||||
|
if(d.type == "interval")
|
||||||
|
intervals[d.path] = 0;
|
||||||
}
|
}
|
||||||
|
setStatePathsIntervalTxn(txn, statePath, intervals); //Set intervals to zero
|
||||||
setVersionedStateEntriesTxn(txn, statePath, infos); //register subdirs/files and their types of versioning
|
setVersionedStateEntriesTxn(txn, statePath, infos); //register subdirs/files and their types of versioning
|
||||||
setStateUserGroupTxn(txn, statePath, queryCallingUsername(), "nixbld", 700); //register the user and group
|
setStateUserGroupTxn(txn, statePath, queryCallingUsername(), "nixbld", 700); //register the user and group
|
||||||
|
|
||||||
|
|
@ -1945,6 +1950,7 @@ void DerivationGoal::computeClosure()
|
||||||
if(sharedState != ""){
|
if(sharedState != ""){
|
||||||
shareStateTxn(txn, sharedState, statePath, false);
|
shareStateTxn(txn, sharedState, statePath, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
//If not shared: create the dir and set the rights
|
//If not shared: create the dir and set the rights
|
||||||
else{
|
else{
|
||||||
ensureStateDir(statePath, queryCallingUsername(), "nixbld", "700");
|
ensureStateDir(statePath, queryCallingUsername(), "nixbld", "700");
|
||||||
|
|
|
||||||
|
|
@ -582,22 +582,6 @@ void LocalStore::collectGarbage(GCAction action, const PathSet & pathsToDelete,
|
||||||
allLiveStatePaths = pathSets_union(getSharedWithPathSetRecTxn(noTxn, *i), allLiveStatePaths);
|
allLiveStatePaths = pathSets_union(getSharedWithPathSetRecTxn(noTxn, *i), allLiveStatePaths);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* Lookup all derivations, of all state paths, because they need to be kept for comitting //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
||||||
*/
|
|
||||||
PathSet allStatePathDerivations;
|
|
||||||
for (PathSet::iterator i = allLiveStatePaths.begin(); i != allLiveStatePaths.end(); ++i){
|
|
||||||
//printMsg(lvlError, format("Live state path `%1%'") % *i);
|
|
||||||
Path stateDrv = queryStatePathDrvTxn(noTxn, *i);
|
|
||||||
allStatePathDerivations.insert(stateDrv);
|
|
||||||
//printMsg(lvlError, format("Live state path drv `%1%'") % stateDrv);
|
|
||||||
|
|
||||||
//TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! TODO put back on
|
|
||||||
if(!store->isValidPath(stateDrv))
|
|
||||||
{} // throw Error(format("deriver `%1%' of state component `%2%' in GC is not valid") % stateDrv % *i);
|
|
||||||
|
|
||||||
// computeFSClosure(stateDrv, livePaths, true, true, 0); //TODO .................. should we do this ?????????????
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Read the Nix store and state directory's to find all currently existing
|
/* Read the Nix store and state directory's to find all currently existing
|
||||||
paths. */
|
paths. */
|
||||||
|
|
@ -661,11 +645,6 @@ void LocalStore::collectGarbage(GCAction action, const PathSet & pathsToDelete,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (allStatePathDerivations.find(*i) != allStatePathDerivations.end()) {
|
|
||||||
debug(format("Keeping statePath derivation `%1%'") % *i);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
debug(format("dead path `%1%'") % *i);
|
debug(format("dead path `%1%'") % *i);
|
||||||
result.insert(*i);
|
result.insert(*i);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1470,57 +1470,41 @@ void verifyStore(bool checkContents)
|
||||||
txn.commit();
|
txn.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setStatePathsIntervalTxn(const Transaction & txn, const PathSet & statePaths, const IntVector & intervals, bool allZero)
|
void setStatePathsIntervalTxn(const Transaction & txn, const Path & statePath, const CommitIntervals & intervals)
|
||||||
{
|
{
|
||||||
if(!allZero && statePaths.size() != intervals.size()){
|
Strings data;
|
||||||
throw Error("the number of statepaths and intervals must be equal");
|
for (CommitIntervals::const_iterator i = intervals.begin(); i != intervals.end(); ++i)
|
||||||
}
|
data.push_back(mergeToDBRevKey((*i).first, (*i).second));
|
||||||
|
|
||||||
int n=0;
|
nixDB.setStrings(txn, dbStateCounters, statePath, data);
|
||||||
for (PathSet::iterator i = statePaths.begin(); i != statePaths.end(); ++i)
|
|
||||||
{
|
|
||||||
//printMsg(lvlError, format("Set interval of PATH: %1%") % *i);
|
|
||||||
|
|
||||||
int interval=0;
|
|
||||||
if(!allZero)
|
|
||||||
interval = intervals.at(n);
|
|
||||||
|
|
||||||
nixDB.setString(txn, dbStateCounters, *i, int2String(interval));
|
|
||||||
n++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void LocalStore::setStatePathsInterval(const PathSet & statePaths, const IntVector & intervals, bool allZero)
|
void LocalStore::setStatePathsInterval(const Path & statePath, const CommitIntervals & intervals)
|
||||||
{
|
{
|
||||||
Transaction txn(nixDB);
|
Transaction txn(nixDB);
|
||||||
nix::setStatePathsIntervalTxn(txn, statePaths, intervals, allZero);
|
nix::setStatePathsIntervalTxn(txn, statePath, intervals);
|
||||||
txn.commit();
|
txn.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
IntVector getStatePathsIntervalTxn(const Transaction & txn, const PathSet & statePaths)
|
CommitIntervals getStatePathsIntervalTxn(const Transaction & txn, const Path & statePath)
|
||||||
{
|
{
|
||||||
string data;
|
Strings data;
|
||||||
Paths referers;
|
nixDB.queryStrings(txn, dbStateCounters, statePath, data);
|
||||||
|
CommitIntervals intervals;
|
||||||
IntVector intervals;
|
for (Strings::iterator i = data.begin(); i != data.end(); ++i)
|
||||||
for (PathSet::iterator i = statePaths.begin(); i != statePaths.end(); ++i)
|
|
||||||
{
|
{
|
||||||
nixDB.queryString(txn, dbStateCounters, *i, data);
|
Path p;
|
||||||
|
unsigned int interval;
|
||||||
//Check if every key returns a value from the db
|
splitDBRevKey(*i, p, interval);
|
||||||
int n;
|
intervals[p] = interval;
|
||||||
if (!string2Int(data, n))
|
|
||||||
throw Error(format("Statepath `%1%' has returned no valid interval from the database") % *i);
|
|
||||||
intervals.push_back(n);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return intervals;
|
return intervals;
|
||||||
}
|
}
|
||||||
|
|
||||||
IntVector LocalStore::getStatePathsInterval(const PathSet & statePaths)
|
CommitIntervals LocalStore::getStatePathsInterval(const Path & statePath)
|
||||||
{
|
{
|
||||||
return nix::getStatePathsIntervalTxn(noTxn, statePaths);
|
return nix::getStatePathsIntervalTxn(noTxn, statePath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -110,9 +110,9 @@ public:
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
|
|
||||||
void setStatePathsInterval(const PathSet & statePath, const IntVector & intervals, bool allZero = false);
|
void setStatePathsInterval(const Path & statePath, const CommitIntervals & intervals);
|
||||||
|
|
||||||
IntVector getStatePathsInterval(const PathSet & statePaths);
|
CommitIntervals getStatePathsInterval(const Path & statePath);
|
||||||
|
|
||||||
bool isStateComponent(const Path & storePath);
|
bool isStateComponent(const Path & storePath);
|
||||||
|
|
||||||
|
|
@ -267,10 +267,11 @@ Path toNonSharedPathTxn(const Transaction & txn, const Path & statePath);
|
||||||
PathSet getSharedWithPathSetRecTxn(const Transaction & txn, const Path & statePath);
|
PathSet getSharedWithPathSetRecTxn(const Transaction & txn, const Path & statePath);
|
||||||
|
|
||||||
void ensurePathTxn(const Transaction & txn, const Path & path);
|
void ensurePathTxn(const Transaction & txn, const Path & path);
|
||||||
IntVector getStatePathsIntervalTxn(const Transaction & txn, const PathSet & statePaths);
|
|
||||||
|
CommitIntervals getStatePathsIntervalTxn(const Transaction & txn, const Path & statePath);
|
||||||
|
void setStatePathsIntervalTxn(const Transaction & txn, const Path & statePath, const CommitIntervals & intervals);
|
||||||
|
|
||||||
bool queryStateRevisionsTxn(const Transaction & txn, const Path & statePath, RevisionClosure & revisions, RevisionClosureTS & timestamps, const unsigned int revision);
|
bool queryStateRevisionsTxn(const Transaction & txn, const Path & statePath, RevisionClosure & revisions, RevisionClosureTS & timestamps, const unsigned int revision);
|
||||||
void setStatePathsIntervalTxn(const Transaction & txn, const PathSet & statePath, const IntVector & intervals, bool allZero = false);
|
|
||||||
bool querySharedStateTxn(const Transaction & txn, const Path & statePath, Path & shared_with);
|
bool querySharedStateTxn(const Transaction & txn, const Path & statePath, Path & shared_with);
|
||||||
|
|
||||||
void setStateComponentTxn(const Transaction & txn, const Path & storePath);
|
void setStateComponentTxn(const Transaction & txn, const Path & storePath);
|
||||||
|
|
|
||||||
|
|
@ -461,22 +461,21 @@ PathSet RemoteStore::queryDerivers(const Path & storePath, const string & identi
|
||||||
return readStorePaths(from); //TODO is this ok ??
|
return readStorePaths(from); //TODO is this ok ??
|
||||||
}
|
}
|
||||||
|
|
||||||
void RemoteStore::setStatePathsInterval(const PathSet & statePaths, const IntVector & intervals, bool allZero)
|
void RemoteStore::setStatePathsInterval(const Path & statePath, const CommitIntervals & intervals)
|
||||||
{
|
{
|
||||||
writeInt(wopSetStatePathsInterval, to);
|
writeInt(wopSetStatePathsInterval, to);
|
||||||
writeStringSet(statePaths, to);
|
writeString(statePath, to);
|
||||||
writeIntVector(intervals, to);
|
writeCommitIntervals(intervals, to);
|
||||||
writeInt(allZero ? 1 : 0, to);
|
|
||||||
processStderr();
|
processStderr();
|
||||||
readInt(from);
|
readInt(from);
|
||||||
}
|
}
|
||||||
|
|
||||||
IntVector RemoteStore::getStatePathsInterval(const PathSet & statePaths)
|
CommitIntervals RemoteStore::getStatePathsInterval(const Path & statePath)
|
||||||
{
|
{
|
||||||
writeInt(wopGetStatePathsInterval, to);
|
writeInt(wopGetStatePathsInterval, to);
|
||||||
writeStringSet(statePaths, to);
|
writeString(statePath, to);
|
||||||
processStderr();
|
processStderr();
|
||||||
return readIntVector(from);
|
return readCommitIntervals(from);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool RemoteStore::isStateComponent(const Path & path)
|
bool RemoteStore::isStateComponent(const Path & path)
|
||||||
|
|
|
||||||
|
|
@ -76,9 +76,9 @@ public:
|
||||||
void collectGarbage(GCAction action, const PathSet & pathsToDelete,
|
void collectGarbage(GCAction action, const PathSet & pathsToDelete,
|
||||||
bool ignoreLiveness, PathSet & result, unsigned long long & bytesFreed);
|
bool ignoreLiveness, PathSet & result, unsigned long long & bytesFreed);
|
||||||
|
|
||||||
void setStatePathsInterval(const PathSet & statePath, const IntVector & intervals, bool allZero = false);
|
void setStatePathsInterval(const Path & statePath, const CommitIntervals & intervals);
|
||||||
|
|
||||||
IntVector getStatePathsInterval(const PathSet & statePaths);
|
CommitIntervals getStatePathsInterval(const Path & statePath);
|
||||||
|
|
||||||
bool isStateComponent(const Path & path);
|
bool isStateComponent(const Path & path);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -183,10 +183,10 @@ public:
|
||||||
bool ignoreLiveness, PathSet & result, unsigned long long & bytesFreed) = 0;
|
bool ignoreLiveness, PathSet & result, unsigned long long & bytesFreed) = 0;
|
||||||
|
|
||||||
/* TODO */
|
/* TODO */
|
||||||
virtual void setStatePathsInterval(const PathSet & statePath, const IntVector & intervals, bool allZero = false) = 0;
|
virtual void setStatePathsInterval(const Path & statePath, const CommitIntervals & intervals) = 0;
|
||||||
|
|
||||||
/* TODO */
|
/* TODO */
|
||||||
virtual IntVector getStatePathsInterval(const PathSet & statePaths) = 0;
|
virtual CommitIntervals getStatePathsInterval(const Path & statePath) = 0;
|
||||||
|
|
||||||
/* Checks whether a path is a component path that has a statePath. */
|
/* Checks whether a path is a component path that has a statePath. */
|
||||||
virtual bool isStateComponent(const Path & path) = 0;
|
virtual bool isStateComponent(const Path & path) = 0;
|
||||||
|
|
|
||||||
|
|
@ -21,32 +21,17 @@
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
/*
|
|
||||||
void updatedStateDerivation(Path storePath)
|
|
||||||
{
|
|
||||||
//We dont remove the old .svn folders
|
|
||||||
//update in database?
|
|
||||||
|
|
||||||
printMsg(lvlTalkative, format("Resetting state drv settings"));
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This gets called before a stateDir might be valid, so we get the data
|
||||||
|
* from the drv and not from the database
|
||||||
|
*/
|
||||||
void createSubStateDirsTxn(const Transaction & txn, const DerivationStateOutputDirs & stateOutputDirs, const DerivationStateOutputs & stateOutputs)
|
void createSubStateDirsTxn(const Transaction & txn, const DerivationStateOutputDirs & stateOutputDirs, const DerivationStateOutputs & stateOutputs)
|
||||||
{
|
{
|
||||||
Path statePath = stateOutputs.find("state")->second.statepath;
|
Path statePath = stateOutputs.find("state")->second.statepath;
|
||||||
string stateDir = statePath;
|
string stateDir = statePath;
|
||||||
|
|
||||||
PathSet intervalPaths;
|
PathSet intervalPaths;
|
||||||
|
|
||||||
//check if we can create state dirs
|
|
||||||
//TODO
|
|
||||||
|
|
||||||
/*
|
|
||||||
if( ! DirectoryExists( ....... ) ){
|
|
||||||
}
|
|
||||||
else
|
|
||||||
printMsg(lvlTalkative, format("Statedir %1% already exists, so dont ........ ???? ") % ...);
|
|
||||||
*/
|
|
||||||
|
|
||||||
for (DerivationStateOutputDirs::const_reverse_iterator i = stateOutputDirs.rbegin(); i != stateOutputDirs.rend(); ++i){
|
for (DerivationStateOutputDirs::const_reverse_iterator i = stateOutputDirs.rbegin(); i != stateOutputDirs.rend(); ++i){
|
||||||
DerivationStateOutputDir d = i->second;
|
DerivationStateOutputDir d = i->second;
|
||||||
|
|
@ -68,12 +53,19 @@ void createSubStateDirsTxn(const Transaction & txn, const DerivationStateOutputD
|
||||||
|
|
||||||
setChown(statePath, queryCallingUsername(), "nixbld", true); //Set all dirs in the statePath recursively to their owners
|
setChown(statePath, queryCallingUsername(), "nixbld", true); //Set all dirs in the statePath recursively to their owners
|
||||||
printMsg(lvlTalkative, format("Set CHOWN '%1%'") % (statePath + "-" + queryCallingUsername()));
|
printMsg(lvlTalkative, format("Set CHOWN '%1%'") % (statePath + "-" + queryCallingUsername()));
|
||||||
|
|
||||||
//Initialize the counters for the statePaths that have an interval to 0
|
|
||||||
IntVector empty;
|
|
||||||
setStatePathsIntervalTxn(txn, intervalPaths, empty, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* TODO
|
||||||
|
*/
|
||||||
|
void updatePaths()
|
||||||
|
{
|
||||||
|
//set in db
|
||||||
|
|
||||||
|
//update setStatePathsIntervalTxn(txn, intervalPaths, empty, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Input: store (or statePath?)
|
* Input: store (or statePath?)
|
||||||
* Returns all the drv's of the statePaths (in)directly referenced.
|
* Returns all the drv's of the statePaths (in)directly referenced.
|
||||||
|
|
@ -143,7 +135,7 @@ void revertToRevisionTxn(const Transaction & txn, const Path & statePath, const
|
||||||
if(revertPathOrFile.substr(revertPathOrFile.length() -1 , revertPathOrFile.length()) == "/"){
|
if(revertPathOrFile.substr(revertPathOrFile.length() -1 , revertPathOrFile.length()) == "/"){
|
||||||
revertPathOrFile_e = revertPathOrFile.substr(0 , revertPathOrFile.length() -1) + "@" + unsignedInt2String(epoch) + "/";
|
revertPathOrFile_e = revertPathOrFile.substr(0 , revertPathOrFile.length() -1) + "@" + unsignedInt2String(epoch) + "/";
|
||||||
|
|
||||||
//TODO IF IS FILE: REMOVE THE FILE
|
//TODO IF IS FILE: REMOVE THE FILE todo MOVE THIS INTO RSYNCPATHS???
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
revertPathOrFile_e = revertPathOrFile + "@" + unsignedInt2String(epoch);
|
revertPathOrFile_e = revertPathOrFile + "@" + unsignedInt2String(epoch);
|
||||||
|
|
@ -175,65 +167,55 @@ void revertToRevisionTxn(const Transaction & txn, const Path & statePath, const
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//TODO maybe add user ID ?
|
|
||||||
Snapshots commitStatePathTxn(const Transaction & txn, const Path & statePath)
|
Snapshots commitStatePathTxn(const Transaction & txn, const Path & statePath)
|
||||||
{
|
{
|
||||||
if(!isValidStatePathTxn(txn, statePath))
|
if(!isValidStatePathTxn(txn, statePath))
|
||||||
throw Error(format("path `%1%' is not a valid state path") % statePath);
|
throw Error(format("path `%1%' is not a valid state path") % statePath);
|
||||||
|
|
||||||
//queryDeriversStatePath??
|
|
||||||
Derivation drv = derivationFromPathTxn(txn, queryStatePathDrvTxn(txn, statePath));
|
|
||||||
DerivationStateOutputs stateOutputs = drv.stateOutputs;
|
|
||||||
DerivationStateOutputDirs stateOutputDirs = drv.stateOutputDirs;
|
|
||||||
|
|
||||||
printMsg(lvlError, format("Snapshotting statePath: %1%") % statePath);
|
printMsg(lvlError, format("Snapshotting statePath: %1%") % statePath);
|
||||||
|
|
||||||
//Get all the inverals from the database at once
|
//Get all paths from the db
|
||||||
PathSet intervalPaths;
|
StateInfos infos;
|
||||||
for (DerivationStateOutputDirs::const_reverse_iterator i = stateOutputDirs.rbegin(); i != stateOutputDirs.rend(); ++i){
|
getVersionedStateEntriesTxn(txn, statePath, infos);
|
||||||
DerivationStateOutputDir d = i->second;
|
|
||||||
|
|
||||||
string thisdir = d.path;
|
|
||||||
string fullstatedir = statePath + "/" + thisdir;
|
|
||||||
|
|
||||||
if(d.type == "interval"){
|
|
||||||
intervalPaths.insert(fullstatedir);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
IntVector intervals = getStatePathsIntervalTxn(txn, intervalPaths);
|
|
||||||
|
|
||||||
|
//Get all interval counters
|
||||||
|
CommitIntervals intervals = getStatePathsIntervalTxn(txn, statePath);
|
||||||
|
|
||||||
Snapshots revisions_list;
|
Snapshots revisions_list;
|
||||||
|
|
||||||
int intervalAt=0;
|
for (StateInfos::const_iterator i = infos.begin(); i != infos.end(); ++i){
|
||||||
for (DerivationStateOutputDirs::const_iterator i = stateOutputDirs.begin(); i != stateOutputDirs.end(); ++i){
|
|
||||||
DerivationStateOutputDir d = i->second;
|
|
||||||
string thisdir = d.path;
|
|
||||||
|
|
||||||
string fullstatedir = statePath + "/" + thisdir;
|
string thisdir = (*i).path;
|
||||||
if(thisdir == "/") //exception for the root dir
|
string type = (*i).type;
|
||||||
fullstatedir = statePath + "/";
|
unsigned int interval = (*i).interval;
|
||||||
|
|
||||||
if(d.type == "none"){
|
if(type == "none"){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(d.type == "interval"){
|
if(type == "interval"){
|
||||||
//Get the interval-counter from the database
|
unsigned int interval_counter = intervals[thisdir];
|
||||||
int interval_counter = intervals[intervalAt];
|
|
||||||
int interval = d.getInterval();
|
|
||||||
|
|
||||||
//update the interval
|
|
||||||
intervals[intervalAt] = interval_counter + 1;
|
|
||||||
intervalAt++;
|
|
||||||
|
|
||||||
if(interval_counter % interval != 0){ continue; }
|
|
||||||
}
|
|
||||||
else if(d.type == "full"){ }
|
|
||||||
else if(d.type == "manual"){ continue; } //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
||||||
else
|
|
||||||
throw Error(format("Type '%1%' is not handled in nix-state") % d.type);
|
|
||||||
|
|
||||||
//We got here so we need to commit
|
//update the interval
|
||||||
|
intervals[thisdir] = (interval_counter + 1);
|
||||||
|
|
||||||
|
//We continue if we dont have to commit now
|
||||||
|
if(interval_counter % interval != 0)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else if(type == "full"){ }
|
||||||
|
else if(type == "manual"){ continue; } //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
|
else
|
||||||
|
throw Error(format("Type '%1%' is not handled in nix-state") % type);
|
||||||
|
|
||||||
|
/////////// We got here so we need to commit
|
||||||
|
|
||||||
|
//We get all info from the orignal path, but we snapshot on the shared path
|
||||||
|
Path sharedWith = toNonSharedPathTxn(txn, statePath);
|
||||||
|
string fullstatedir = sharedWith + "/" + thisdir;
|
||||||
|
if(thisdir == "/") //exception for the root dir
|
||||||
|
fullstatedir = sharedWith + "/";
|
||||||
|
|
||||||
unsigned int revision_number;
|
unsigned int revision_number;
|
||||||
if(pathExists(fullstatedir) || FileExist(fullstatedir)){
|
if(pathExists(fullstatedir) || FileExist(fullstatedir)){
|
||||||
revision_number = take_snapshot(fullstatedir);
|
revision_number = take_snapshot(fullstatedir);
|
||||||
|
|
@ -245,11 +227,11 @@ Snapshots commitStatePathTxn(const Transaction & txn, const Path & statePath)
|
||||||
revisions_list[fullstatedir] = revision_number;
|
revisions_list[fullstatedir] = revision_number;
|
||||||
//printMsg(lvlError, format("FSD %1% RN %2%") % fullstatedir % revision_number);
|
//printMsg(lvlError, format("FSD %1% RN %2%") % fullstatedir % revision_number);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Update the intervals again
|
||||||
|
setStatePathsIntervalTxn(txn, statePath, intervals);
|
||||||
|
|
||||||
return revisions_list;
|
return revisions_list;
|
||||||
|
|
||||||
//Update the intervals again
|
|
||||||
//setStatePathsIntervalTxn(txn, intervalPaths, intervals); //TODO!!!!!!!!!!!!!!!!!!!!!!!!!!!!! uncomment
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO include this call in the validate function
|
//TODO include this call in the validate function
|
||||||
|
|
@ -703,6 +685,7 @@ bool queryStateRevisions(Database & nixDB, const Transaction & txn, TableId revi
|
||||||
splitDBRevKey(*i, getStatePath, getTimestamp);
|
splitDBRevKey(*i, getStatePath, getTimestamp);
|
||||||
|
|
||||||
//query state versioined directorys/files
|
//query state versioined directorys/files
|
||||||
|
//TODO REMOVE
|
||||||
/*
|
/*
|
||||||
vector<Path> sortedPaths;
|
vector<Path> sortedPaths;
|
||||||
Derivation drv = derivationFromPathTxn(txn, queryStatePathDrvTxn(txn, getStatePath));
|
Derivation drv = derivationFromPathTxn(txn, queryStatePathDrvTxn(txn, getStatePath));
|
||||||
|
|
|
||||||
|
|
@ -105,6 +105,17 @@ void writeRevisionInfos(const RevisionInfos & ri, Sink & sink)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void writeCommitIntervals(const CommitIntervals ci, Sink & sink)
|
||||||
|
{
|
||||||
|
writeInt(ci.size(), sink);
|
||||||
|
for (CommitIntervals::const_iterator i = ci.begin(); i != ci.end(); ++i){
|
||||||
|
writeString((*i).first, sink);
|
||||||
|
writeBigUnsignedInt((*i).second, sink);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////
|
||||||
|
|
||||||
void readPadding(unsigned int len, Source & source)
|
void readPadding(unsigned int len, Source & source)
|
||||||
{
|
{
|
||||||
if (len % 8) {
|
if (len % 8) {
|
||||||
|
|
@ -205,7 +216,7 @@ RevisionClosureTS readRevisionClosureTS(Source & source)
|
||||||
RevisionClosureTS rc;
|
RevisionClosureTS rc;
|
||||||
while (count--){
|
while (count--){
|
||||||
string path = readString(source);
|
string path = readString(source);
|
||||||
int ri = readBigUnsignedInt(source);
|
unsigned int ri = readBigUnsignedInt(source);
|
||||||
rc[path] = ri;
|
rc[path] = ri;
|
||||||
}
|
}
|
||||||
return rc;
|
return rc;
|
||||||
|
|
@ -225,4 +236,16 @@ RevisionInfos readRevisionInfos(Source & source)
|
||||||
return ri;
|
return ri;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CommitIntervals readCommitIntervals(Source & source)
|
||||||
|
{
|
||||||
|
unsigned int count = readInt(source);
|
||||||
|
CommitIntervals ci;
|
||||||
|
while (count--){
|
||||||
|
string path = readString(source);
|
||||||
|
unsigned int ri = readBigUnsignedInt(source);
|
||||||
|
ci[path] = ri;
|
||||||
|
}
|
||||||
|
return ci;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -104,6 +104,7 @@ void writeRevisionClosure(const RevisionClosure & rc, Sink & sink);
|
||||||
void writeSnapshots(const Snapshots & ss, Sink & sink);
|
void writeSnapshots(const Snapshots & ss, Sink & sink);
|
||||||
void writeRevisionClosureTS(const RevisionClosureTS & rc, Sink & sink);
|
void writeRevisionClosureTS(const RevisionClosureTS & rc, Sink & sink);
|
||||||
void writeRevisionInfos(const RevisionInfos & ri, Sink & sink);
|
void writeRevisionInfos(const RevisionInfos & ri, Sink & sink);
|
||||||
|
void writeCommitIntervals(const CommitIntervals ci, Sink & sink);
|
||||||
|
|
||||||
void readPadding(unsigned int len, Source & source);
|
void readPadding(unsigned int len, Source & source);
|
||||||
unsigned int readInt(Source & source);
|
unsigned int readInt(Source & source);
|
||||||
|
|
@ -116,6 +117,7 @@ RevisionClosure readRevisionClosure(Source & source);
|
||||||
Snapshots readSnapshots(Source & source);
|
Snapshots readSnapshots(Source & source);
|
||||||
RevisionClosureTS readRevisionClosureTS(Source & source);
|
RevisionClosureTS readRevisionClosureTS(Source & source);
|
||||||
RevisionInfos readRevisionInfos(Source & source);
|
RevisionInfos readRevisionInfos(Source & source);
|
||||||
|
CommitIntervals readCommitIntervals(Source & source);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,7 @@ typedef set<Path> PathSet;
|
||||||
//state types
|
//state types
|
||||||
typedef vector<int> IntVector; //the Strings (list) of StateReferences and this list are connected by position //TODO
|
typedef vector<int> IntVector; //the Strings (list) of StateReferences and this list are connected by position //TODO
|
||||||
typedef vector<unsigned int> UnsignedIntVector;
|
typedef vector<unsigned int> UnsignedIntVector;
|
||||||
|
typedef map<Path, unsigned int> CommitIntervals;
|
||||||
struct RevisionInfo
|
struct RevisionInfo
|
||||||
{
|
{
|
||||||
string comment;
|
string comment;
|
||||||
|
|
|
||||||
|
|
@ -663,7 +663,7 @@ static void installDerivations(Globals & globals,
|
||||||
|
|
||||||
//TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
//TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||||
//TODO && (the users are equal || OR SHARED BETWEEN USERS) isnt this already user specific?
|
//TODO && (the users are equal || OR SHARED BETWEEN USERS) isnt this already user specific?
|
||||||
//TODO
|
//TODO
|
||||||
if( newSharedState == ""
|
if( newSharedState == ""
|
||||||
&&
|
&&
|
||||||
(oldStateIdentifier == newStateIdentifier
|
(oldStateIdentifier == newStateIdentifier
|
||||||
|
|
|
||||||
|
|
@ -374,9 +374,6 @@ static void opRunComponent(Strings opFlags, Strings opArgs)
|
||||||
|
|
||||||
//Start transaction TODO
|
//Start transaction TODO
|
||||||
|
|
||||||
//Replace all shared paths in the set for their real paths
|
|
||||||
statePaths = store->toNonSharedPathSet(statePaths);
|
|
||||||
|
|
||||||
//Commit all statePaths
|
//Commit all statePaths
|
||||||
RevisionClosure rivisionMapping;
|
RevisionClosure rivisionMapping;
|
||||||
for (PathSet::iterator i = statePaths.begin(); i != statePaths.end(); ++i) //TODO first commit own state path?
|
for (PathSet::iterator i = statePaths.begin(); i != statePaths.end(); ++i) //TODO first commit own state path?
|
||||||
|
|
|
||||||
|
|
@ -473,22 +473,21 @@ static void performOp(Source & from, Sink & to, unsigned int op)
|
||||||
}
|
}
|
||||||
|
|
||||||
case wopSetStatePathsInterval: {
|
case wopSetStatePathsInterval: {
|
||||||
PathSet statePaths = readStringSet(from);
|
Path statePath = readStatePath(from);
|
||||||
IntVector intervals = readIntVector(from);
|
CommitIntervals intervals = readCommitIntervals(from);
|
||||||
bool allZero = readInt(from) == 1;
|
|
||||||
startWork();
|
startWork();
|
||||||
store->setStatePathsInterval(statePaths, intervals, allZero);
|
store->setStatePathsInterval(statePath, intervals);
|
||||||
stopWork();
|
stopWork();
|
||||||
writeInt(1, to);
|
writeInt(1, to);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
case wopGetStatePathsInterval: {
|
case wopGetStatePathsInterval: {
|
||||||
PathSet statePaths = readStringSet(from);
|
Path statePath = readStatePath(from);
|
||||||
startWork();
|
startWork();
|
||||||
IntVector iv = store->getStatePathsInterval(statePaths);
|
CommitIntervals ci = store->getStatePathsInterval(statePath);
|
||||||
stopWork();
|
stopWork();
|
||||||
writeIntVector(iv, to);
|
writeCommitIntervals(ci, to);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue