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

Fixed some more remote-store store bugs. Users can now add state store components with nix-env. Paths in /nix/state are now chowned and chmodded to their owners

This commit is contained in:
Wouter den Breejen 2007-08-30 18:20:20 +00:00
parent 627afcc1aa
commit 30cf65af26
24 changed files with 327 additions and 255 deletions

View file

@ -1083,7 +1083,7 @@ static string makeValidityRegistration(const PathSet & paths,
s += deriver + "\n";
PathSet references;
store->queryReferences(*i, references, -1); //TODO check if this is ok
store->queryReferences(*i, references, 0); //TODO check if this is ok
s += (format("%1%\n") % references.size()).str();
@ -1200,7 +1200,7 @@ DerivationGoal::HookReply DerivationGoal::tryBuildHook()
*probably* already has it.) */
PathSet allInputs;
allInputs.insert(inputPaths.begin(), inputPaths.end());
computeFSClosure(drvPath, allInputs, true, false, -1); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!! WE (MAY) ALSO NEED TO COPY STATE
computeFSClosure(drvPath, allInputs, true, false, 0); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!! WE (MAY) ALSO NEED TO COPY STATE
string s;
for (PathSet::iterator i = allInputs.begin();
@ -1323,8 +1323,8 @@ bool DerivationGoal::prepareBuild()
Derivation inDrv = derivationFromPathTxn(noTxn, i->first);
for (StringSet::iterator j = i->second.begin(); j != i->second.end(); ++j)
if (inDrv.outputs.find(*j) != inDrv.outputs.end()){
computeFSClosure(inDrv.outputs[*j].path, inputPaths, true, false, -1); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!! WE (MAY) ALSO NEED TO COPY STATE (done?)
computeFSClosure(inDrv.outputs[*j].path, inputStatePaths, false, true, -1); //TODO!!!!!!!!!!!!! HOW CAN THESE PATHS ALREADY BE VALID ..... ?????????????????????
computeFSClosure(inDrv.outputs[*j].path, inputPaths, true, false, 0); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!! WE (MAY) ALSO NEED TO COPY STATE (done?)
computeFSClosure(inDrv.outputs[*j].path, inputStatePaths, false, true, 0); //TODO!!!!!!!!!!!!! HOW CAN THESE PATHS ALREADY BE VALID ..... ?????????????????????
}
else
throw BuildError(
@ -1334,8 +1334,8 @@ bool DerivationGoal::prepareBuild()
/* Second, the input sources. */
for (PathSet::iterator i = drv.inputSrcs.begin(); i != drv.inputSrcs.end(); ++i){
computeFSClosure(*i, inputPaths, true, false, -1); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!! WE (MAY) ALSO NEED TO COPY STATE (done?)
computeFSClosure(*i, inputStatePaths, false, true, -1);
computeFSClosure(*i, inputPaths, true, false, 0); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!! WE (MAY) ALSO NEED TO COPY STATE (done?)
computeFSClosure(*i, inputStatePaths, false, true, 0);
}
debug(format("added input paths %1%") % showPaths(inputPaths));
@ -1400,7 +1400,7 @@ void DerivationGoal::startBuilder()
checkStatePath(drv);
if(drv.stateOutputs.find("state")->second.getCreateDirsBeforeInstall())
createStateDirsTxn(noTxn, drv.stateOutputDirs, drv.stateOutputs);
createSubStateDirsTxn(noTxn, drv.stateOutputDirs, drv.stateOutputs);
}
/* For convenience, set an environment pointing to the top build
@ -1463,7 +1463,7 @@ void DerivationGoal::startBuilder()
/* Write closure info to `fileName'. */
PathSet refs;
computeFSClosure(storePath, refs, true, false, -1); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!! WE (MAY) ALSO NEED TO COPY STATE
computeFSClosure(storePath, refs, true, false, 0); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!! WE (MAY) ALSO NEED TO COPY STATE
/* !!! in secure Nix, the writing should be done on the
build uid for security (maybe). */
writeStringToFile(tmpDir + "/" + fileName,
@ -1640,7 +1640,7 @@ void DerivationGoal::computeClosure()
//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.find("state")->second.getCreateDirsBeforeInstall())
createStateDirsTxn(noTxn, drv.stateOutputDirs, drv.stateOutputs);
createSubStateDirsTxn(noTxn, drv.stateOutputDirs, drv.stateOutputs);
/*
for (PathSet::iterator i = allPaths.begin(); i != allPaths.end(); ++i)
@ -1795,7 +1795,7 @@ void DerivationGoal::computeClosure()
contentHashes[i->second.path],
allReferences[i->second.path], //set of component-references
allStateReferences[i->second.path], //set of state-references
drvPath, -1);
drvPath, 0);
}
//Register the state path valid
@ -1808,7 +1808,7 @@ void DerivationGoal::computeClosure()
Hash(), //emtpy hash
state_references,
state_stateReferences,
drvPath, -1);
drvPath, 0);
//Commit state (we only include our own state in the rivisionMapping (but other build component states might have been changed !!!! TODO)
RevisionClosure rivisionMapping;
@ -1827,6 +1827,10 @@ void DerivationGoal::computeClosure()
//Set in database
setSharedStateTxn(txn, sharedState, statePath);
}
//If not shared: create the dir and set the rights
else{
setStatePathRights(statePath, queryCallingUsername(), "nixbld", "700");
}
}
txn.commit();
@ -2049,7 +2053,7 @@ void SubstitutionGoal::init()
/* To maintain the closure invariant, we first have to realise the
paths referenced by this one. */
store->queryReferences(storePath, references, -1);
store->queryReferences(storePath, references, 0);
for (PathSet::iterator i = references.begin();
i != references.end(); ++i)

View file

@ -449,25 +449,25 @@ void Database::enumTable(const Transaction & txn, TableId table,
/* State specific db functions */
Path Database::mergeToDBKey(const Path & statePath, const int revision)
Path Database::mergeToDBKey(const Path & statePath, const unsigned int intvalue)
{
string prefix = "-KEY-";
return statePath + prefix + int2String(revision);
return statePath + prefix + unsignedInt2String(intvalue);
}
void Database::splitDBKey(const Path & revisionedStatePath, Path & statePath, int & revision)
void Database::splitDBKey(const Path & revisionedStatePath, Path & statePath, unsigned int & intvalue)
{
string prefix = "-KEY-";
int pos = revisionedStatePath.find_last_of(prefix);
statePath = revisionedStatePath.substr(0, pos - prefix.length() + 1);
//printMsg(lvlError, format("'%2%' - '%1%'") % revisionedStatePath.substr(pos+1, revisionedStatePath.length()) % int2String(pos));
bool succeed = string2Int(revisionedStatePath.substr(pos+1, revisionedStatePath.length()), revision);
bool succeed = string2UnsignedInt(revisionedStatePath.substr(pos+1, revisionedStatePath.length()), intvalue);
if(!succeed)
throw Error(format("Malformed revision value of path '%1%'") % revisionedStatePath);
}
int Database::getNewRevisionNumber(const Transaction & txn, TableId table,
unsigned int Database::getNewRevisionNumber(const Transaction & txn, TableId table,
const Path & statePath)
{
//query
@ -476,23 +476,23 @@ int Database::getNewRevisionNumber(const Transaction & txn, TableId table,
if(!notEmpty){
setString(txn, table, statePath, int2String(1));
return 1;
return 1; //we begin counting from 1 since 0 is a special value representing the last revision
}
int revision;
bool succeed = string2Int(data, revision);
unsigned int revision;
bool succeed = string2UnsignedInt(data, revision);
if(!succeed)
throw Error(format("Malformed revision counter value of path '%1%'") % statePath);
revision++;
setString(txn, table, statePath, int2String(revision));
setString(txn, table, statePath, unsignedInt2String(revision));
return revision;
}
bool Database::lookupHighestRevivison(const Strings & keys, const Path & statePath, string & key, int lowerthan)
bool Database::lookupHighestRevivison(const Strings & keys, const Path & statePath, string & key, unsigned int lowerthan)
{
int highestRev = -1;
unsigned int highestRev = 0;
//Lookup which key we need
for (Strings::const_iterator i = keys.begin(); i != keys.end(); ++i) {
@ -502,11 +502,11 @@ bool Database::lookupHighestRevivison(const Strings & keys, const Path & statePa
//printMsg(lvlError, format("'%1%' - '%2%'") % *i % statePath);
Path getStatePath;
int getRevision;
unsigned int getRevision;
splitDBKey(*i, getStatePath, getRevision);
if(getRevision > highestRev){
if(lowerthan != -1){
if(lowerthan != 0){
if(getRevision <= lowerthan) //if we have an uppper limit, see to it that we downt go over it
highestRev = getRevision;
}
@ -515,14 +515,14 @@ bool Database::lookupHighestRevivison(const Strings & keys, const Path & statePa
}
}
if(highestRev == -1) //no records found
if(highestRev == 0) //no records found
return false;
key = mergeToDBKey(statePath, highestRev); //final key that matches revision + statePath
return true;
}
bool Database::revisionToTimeStamp(const Transaction & txn, TableId revisions_table, const Path & statePath, const int revision, int & timestamp)
bool Database::revisionToTimeStamp(const Transaction & txn, TableId revisions_table, const Path & statePath, const int revision, unsigned int & timestamp)
{
string key = mergeToDBKey(statePath, revision);
Strings references;
@ -539,14 +539,16 @@ bool Database::revisionToTimeStamp(const Transaction & txn, TableId revisions_ta
}
void Database::setStateReferences(const Transaction & txn, TableId references_table, TableId revisions_table,
const Path & statePath, const Strings & references, int revision, int timestamp)
const Path & statePath, const Strings & references, const unsigned int revision, const unsigned int timestamp)
{
//printMsg(lvlError, format("setStateReferences '%1%' for '%2%'") % references_table % statePath);
if(revision == -1 && timestamp == -1)
timestamp = getTimeStamp();
if(revision != -1 && timestamp == -1){
bool found = revisionToTimeStamp(txn, revisions_table, statePath, revision, timestamp);
//Find the timestamp if we need
unsigned int timestamp2 = timestamp;
if(revision == 0 && timestamp == 0)
timestamp2 = getTimeStamp();
else if(revision != 0 && timestamp == 0){
bool found = revisionToTimeStamp(txn, revisions_table, statePath, revision, timestamp2);
if(!found)
throw Error(format("Revision '%1%' cannot be matched to a timestamp...") % revision);
}
@ -556,12 +558,12 @@ void Database::setStateReferences(const Transaction & txn, TableId references_ta
//Warning if it already exists
Strings empty;
if( queryStrings(txn, references_table, mergeToDBKey(statePath, timestamp), empty) )
if( queryStrings(txn, references_table, mergeToDBKey(statePath, timestamp2), empty) )
printMsg(lvlError, format("Warning: The timestamp '%1%' (now: '%5%') / revision '%4%' already exists for set-references of path '%2%' with db '%3%'")
% timestamp % statePath % references_table % revision % getTimeStamp());
% timestamp2 % statePath % references_table % revision % getTimeStamp());
//Create the key
string key = mergeToDBKey(statePath, timestamp);
string key = mergeToDBKey(statePath, timestamp2);
//printMsg(lvlError, format("Set references '%1%'") % key);
//for (Strings::const_iterator i = references.begin(); i != references.end(); ++i)
@ -572,13 +574,14 @@ void Database::setStateReferences(const Transaction & txn, TableId references_ta
}
bool Database::queryStateReferences(const Transaction & txn, TableId references_table, TableId revisions_table,
const Path & statePath, Strings & references, int revision, int timestamp)
const Path & statePath, Strings & references, const unsigned int revision, const unsigned int timestamp)
{
//printMsg(lvlError, format("queryStateReferences '%1%' with revision '%2%'") % references_table % revision);
//Convert revision to timestamp number useing the revisions_table
if(timestamp == -1 && revision != -1){
bool found = revisionToTimeStamp(txn, revisions_table, statePath, revision, timestamp);
unsigned int timestamp2 = timestamp;
if(timestamp == 0 && revision != 0){
bool found = revisionToTimeStamp(txn, revisions_table, statePath, revision, timestamp2);
if(!found) //we are asked for references of some revision, but there are no references registered yet, so we return false;
return false;
}
@ -588,7 +591,7 @@ bool Database::queryStateReferences(const Transaction & txn, TableId references_
//Mabye we need the latest timestamp?
string key = "";
if(timestamp == -1){
if(timestamp2 == 0){
bool foundsomething = lookupHighestRevivison(keys, statePath, key);
if(!foundsomething)
return false;
@ -597,21 +600,21 @@ bool Database::queryStateReferences(const Transaction & txn, TableId references_
}
//If a specific key is given: check if this timestamp exists key in the table
key = mergeToDBKey(statePath, timestamp);
key = mergeToDBKey(statePath, timestamp2);
bool found = false;
for (Strings::const_iterator i = keys.begin(); i != keys.end(); ++i) {
if(key == *i){
found = true;
key = mergeToDBKey(statePath, timestamp);
key = mergeToDBKey(statePath, timestamp2);
}
}
//If it doesn't exist in the table then find the highest key lower than it
if(!found){
bool foundsomething = lookupHighestRevivison(keys, statePath, key, -1);
bool foundsomething = lookupHighestRevivison(keys, statePath, key, 0);
if(!foundsomething)
return false;
//printMsg(lvlError, format("Warning: References for timestamp '%1%' not was not found, so taking the highest rev-key possible for statePath '%2%'") % timestamp % statePath);
//printMsg(lvlError, format("Warning: References for timestamp '%1%' not was not found, so taking the highest rev-key possible for statePath '%2%'") % timestamp2 % statePath);
}
return queryStrings(txn, references_table, key, references); //now that we have the key, we can query the references
@ -623,11 +626,11 @@ void Database::setStateRevisions(const Transaction & txn, TableId revisions_tabl
if( !isStatePath(rootStatePath) ) //weak check on statePath
throw Error(format("StatePath '%1%' is not a statepath") % rootStatePath);
int ts = getTimeStamp();
unsigned int timestamp = getTimeStamp();
//Insert all ss_epochs into snapshots_table with the current ts.
for (RevisionClosure::const_iterator i = revisions.begin(); i != revisions.end(); ++i){
string key = mergeToDBKey((*i).first, ts);
string key = mergeToDBKey((*i).first, timestamp);
Strings data;
//the map<> takes care of the sorting on the Path
for (Snapshots::const_iterator j = (*i).second.begin(); j != (*i).second.end(); ++j)
@ -639,25 +642,25 @@ void Database::setStateRevisions(const Transaction & txn, TableId revisions_tabl
for (RevisionClosure::const_iterator i = revisions.begin(); i != revisions.end(); ++i){
Path statePath = (*i).first;
int revision = getNewRevisionNumber(txn, revisions_table, statePath); //get a new revision number
unsigned int revision = getNewRevisionNumber(txn, revisions_table, statePath); //get a new revision number
string key = mergeToDBKey(statePath, revision);
//get all its requisites
PathSet statePath_references;
storePathRequisitesTxn(txn, statePath, false, statePath_references, false, true, -1);
storePathRequisitesTxn(txn, statePath, false, statePath_references, false, true, 0);
statePath_references.insert(statePath);
//save in db
Strings data;
for (PathSet::const_iterator j = statePath_references.begin(); j != statePath_references.end(); ++j)
data.push_back(mergeToDBKey(*j, ts));
data.push_back(mergeToDBKey(*j, timestamp));
setStrings(txn, revisions_table, key, data, false); //The false makes sure also empty revisions are set
//save the date and comments
Strings metadata;
metadata.push_back(int2String(ts));
metadata.push_back(unsignedInt2String(timestamp));
//get all paths that point to the same state (using shareing) and check if one of them equals the rootStatePath
PathSet sharedWith = getSharedWithPathSetRecTxn(txn, statePath);
@ -671,11 +674,11 @@ void Database::setStateRevisions(const Transaction & txn, TableId revisions_tabl
}
bool Database::queryStateRevisions(const Transaction & txn, TableId revisions_table, TableId snapshots_table,
const Path & statePath, RevisionClosure & revisions, RevisionClosureTS & timestamps, int root_revision)
const Path & statePath, RevisionClosure & revisions, RevisionClosureTS & timestamps, const unsigned int root_revision)
{
string key;
if(root_revision == -1){
if(root_revision == 0){
Strings keys;
enumTable(txn, revisions_table, keys); //get all revisions
bool foundsomething = lookupHighestRevivison(keys, statePath, key);
@ -690,13 +693,13 @@ bool Database::queryStateRevisions(const Transaction & txn, TableId revisions_ta
bool notempty = queryStrings(txn, revisions_table, key, statePaths);
if(!notempty)
throw Error(format("Root revision '%1%' not found of statePath '%2%'") % int2String(root_revision) % statePath);
throw Error(format("Root revision '%1%' not found of statePath '%2%'") % unsignedInt2String(root_revision) % statePath);
//For each statePath add the revisions
for (Strings::iterator i = statePaths.begin(); i != statePaths.end(); ++i){
Path getStatePath;
int getTimestamp;
unsigned int getTimestamp;
splitDBKey(*i, getStatePath, getTimestamp);
//query state versioined directorys/files
@ -732,7 +735,6 @@ bool Database::queryStateRevisions(const Transaction & txn, TableId revisions_ta
timestamps[getStatePath] = getTimestamp;
}
return notempty;
}
@ -749,7 +751,7 @@ bool Database::queryAvailableStateRevisions(const Transaction & txn, TableId rev
continue;
Path getStatePath;
int getRevision;
unsigned int getRevision;
splitDBKey(*i, getStatePath, getRevision);
//save the date and comments

View file

@ -61,10 +61,10 @@ private:
void open2(const string & path, bool removeOldEnv);
/* TODO */
bool lookupHighestRevivison(const Strings & keys, const Path & statePath, string & key, int lowerthan = -1);
bool lookupHighestRevivison(const Strings & keys, const Path & statePath, string & key, unsigned int lowerthan = 0);
/* TODO */
int getNewRevisionNumber(const Transaction & txn, TableId table, const Path & statePath);
unsigned int getNewRevisionNumber(const Transaction & txn, TableId table, const Path & statePath);
public:
Database();
@ -97,21 +97,21 @@ public:
Strings & keys, const string & keyPrefix = "");
/* TODO */
Path mergeToDBKey(const Path & statePath, const int revision);
Path mergeToDBKey(const Path & statePath, const unsigned int intvalue);
/* TODO */
void splitDBKey(const Path & revisionedStatePath, Path & statePath, int & revision);
void splitDBKey(const Path & revisionedStatePath, Path & statePath, unsigned int & intvalue);
/* TODO */
bool revisionToTimeStamp(const Transaction & txn, TableId revisions_table, const Path & statePath, const int revision, int & timestamp);
bool revisionToTimeStamp(const Transaction & txn, TableId revisions_table, const Path & statePath, const int revision, unsigned int & timestamp);
/* Set the stateReferences for a specific revision (and older until the next higher revision number in the table) */
void setStateReferences(const Transaction & txn, TableId references_table, TableId revisions_table,
const Path & statePath, const Strings & references, int revision = -1, int timestamp = -1);
const Path & statePath, const Strings & references, const unsigned int revision = 0, const unsigned int timestamp = 0);
/* Returns the references for a specific revision (and older until the next higher revision number in the table) */
bool queryStateReferences(const Transaction & txn, TableId references_table, TableId revisions_table,
const Path & statePath, Strings & references, int revision = -1, int timestamp = -1);
const Path & statePath, Strings & references, const unsigned int revision = 0, const unsigned int timestamp = 0);
/* Set the revision number of the statePath and the revision numbers of all state paths in the references closure */
void setStateRevisions(const Transaction & txn, TableId revisions_table, TableId revisions_comments,
@ -119,7 +119,7 @@ public:
/* Returns all the revision numbers of the state references closure of the given state path */
bool queryStateRevisions(const Transaction & txn, TableId revisions_table, TableId snapshots_table,
const Path & statePath, RevisionClosure & revisions, RevisionClosureTS & timestamps, int root_revision = -1);
const Path & statePath, RevisionClosure & revisions, RevisionClosureTS & timestamps, const unsigned int root_revision = 0);
/* Returns all available revision numbers of the given state path */
bool queryAvailableStateRevisions(const Transaction & txn, TableId revisions_table, TableId revisions_comments,

View file

@ -406,7 +406,7 @@ static void dfsVisit(const PathSet & paths, const Path & path,
PathSet references;
if (store->isValidPath(path))
store->queryReferences(path, references, -1); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
store->queryReferences(path, references, 0); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
for (PathSet::iterator i = references.begin();
i != references.end(); ++i)
@ -469,7 +469,7 @@ void LocalStore::collectGarbage(GCAction action, const PathSet & pathsToDelete,
roots under the `references' relation. */
PathSet livePaths;
for (PathSet::const_iterator i = roots.begin(); i != roots.end(); ++i)
computeFSClosure(canonPath(*i), livePaths, true, false, -1); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!! WE (MAY) ALSO NEED TO DELETE STATE??
computeFSClosure(canonPath(*i), livePaths, true, false, 0); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!! WE (MAY) ALSO NEED TO DELETE STATE??
if (gcKeepDerivations) {
for (PathSet::iterator i = livePaths.begin();
@ -480,7 +480,7 @@ void LocalStore::collectGarbage(GCAction action, const PathSet & pathsToDelete,
turned off). */
Path deriver = store->queryDeriver(*i);
if (deriver != "" && store->isValidPath(deriver))
computeFSClosure(deriver, livePaths, true, false, -1); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!! WE (MAY) ALSO NEED TO KEEP STATE
computeFSClosure(deriver, livePaths, true, false, 0); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!! WE (MAY) ALSO NEED TO KEEP STATE
}
}
@ -493,7 +493,7 @@ void LocalStore::collectGarbage(GCAction action, const PathSet & pathsToDelete,
for (DerivationOutputs::iterator j = drv.outputs.begin();
j != drv.outputs.end(); ++j)
if (store->isValidPath(j->second.path))
computeFSClosure(j->second.path, livePaths, true, false, -1); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!! WE (MAY) ALSO NEED TO KEEP STATE
computeFSClosure(j->second.path, livePaths, true, false, 0); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!! WE (MAY) ALSO NEED TO KEEP STATE
}
}
@ -518,7 +518,7 @@ void LocalStore::collectGarbage(GCAction action, const PathSet & pathsToDelete,
PathSet tempRootsClosed;
for (PathSet::iterator i = tempRoots.begin(); i != tempRoots.end(); ++i)
if (store->isValidPath(*i))
computeFSClosure(*i, tempRootsClosed, true, false, -1); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!! WE (MAY) ALSO NEED TO .... STATE
computeFSClosure(*i, tempRootsClosed, true, false, 0); //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!! WE (MAY) ALSO NEED TO .... STATE
else
tempRootsClosed.insert(*i);

View file

@ -29,7 +29,7 @@ string thisSystem = "unset";
unsigned int maxSilentTime = 0;
static bool settingsRead = false;
uid_t callingUID = 0; //A root user will not set this value, so the default uid is 0
bool debugWorker = false; //TODO still experimental
bool debugWorker = false; //TODO Still experimental ! this gives an store already open at the second call
static std::map<string, Strings> settings;

View file

@ -140,7 +140,7 @@ static TableId dbStateRevisions = 0;
*/
static TableId dbStateRevisionsComments = 0;
/* dbStateSnapshots :: StatePath -> IntVector
/* dbStateSnapshots :: StatePath -> RevisionClosure
*
* This table stores the snapshot numbers the sub state files/folders
* at a certain timestamp. These snapshot numbers are just timestamps
@ -446,7 +446,7 @@ static string stripPrefix(const string & prefix, const string & s)
void setReferences(const Transaction & txn, const Path & store_or_statePath,
const PathSet & references, const PathSet & stateReferences, const int revision)
const PathSet & references, const PathSet & stateReferences, const unsigned int revision)
{
/* For unrealisable paths, we can only clear the references. */
if (references.size() > 0 && !isRealisableComponentOrStatePath(txn, store_or_statePath))
@ -482,11 +482,11 @@ void setReferences(const Transaction & txn, const Path & store_or_statePath,
else if(isRealisableStatePath(txn, store_or_statePath))
{
printMsg(lvlError, format("Setting references for statepath '%1%' (revision:%2%)") % store_or_statePath % int2String(revision));
printMsg(lvlError, format("Setting references for statepath '%1%' (revision:%2%)") % store_or_statePath % unsignedInt2String(revision));
//Write references to a special revision (since there are multiple revisions of a statePath)
//query the references of revision (-1 is query the latest references)
//query the references of revision (0 is query the latest references)
Paths oldStateReferences_s_c;
Paths oldStateReferences_s_s;
nixDB.queryStateReferences(txn, dbStateComponentReferences, dbStateRevisions, store_or_statePath, oldStateReferences_s_c, revision);
@ -495,7 +495,7 @@ void setReferences(const Transaction & txn, const Path & store_or_statePath,
PathSet oldReferences = PathSet(oldStateReferences_s_c.begin(), oldStateReferences_s_c.end());
PathSet oldStateReferences = PathSet(oldStateReferences_s_s.begin(), oldStateReferences_s_s.end());
//set the references of revision (-1 insert as a new timestamp)
//set the references of revision (0 insert as a new timestamp)
nixDB.setStateReferences(txn, dbStateComponentReferences, dbStateRevisions, store_or_statePath, Paths(references.begin(), references.end()), revision);
nixDB.setStateReferences(txn, dbStateStateReferences, dbStateRevisions, store_or_statePath, Paths(stateReferences.begin(), stateReferences.end()), revision);
}
@ -504,7 +504,7 @@ void setReferences(const Transaction & txn, const Path & store_or_statePath,
}
void queryXReferencesTxn(const Transaction & txn, const Path & store_or_statePath, PathSet & references, const bool component_or_state, const int revision, int timestamp)
void queryXReferencesTxn(const Transaction & txn, const Path & store_or_statePath, PathSet & references, const bool component_or_state, const unsigned int revision, const unsigned int timestamp)
{
Paths references2;
TableId table1;
@ -531,17 +531,17 @@ void queryXReferencesTxn(const Transaction & txn, const Path & store_or_statePat
references.insert(references2.begin(), references2.end());
}
void LocalStore::queryReferences(const Path & storePath, PathSet & references, const int revision)
void LocalStore::queryReferences(const Path & storePath, PathSet & references, const unsigned int revision)
{
nix::queryXReferencesTxn(noTxn, storePath, references, revision, true);
}
void LocalStore::queryStateReferences(const Path & componentOrstatePath, PathSet & stateReferences, const int revision)
void LocalStore::queryStateReferences(const Path & componentOrstatePath, PathSet & stateReferences, const unsigned int revision)
{
nix::queryXReferencesTxn(noTxn, componentOrstatePath, stateReferences, revision, false);
}
static PathSet getXReferrers(const Transaction & txn, const Path & store_or_statePath, const bool component_or_state, const int revision)
static PathSet getXReferrers(const Transaction & txn, const Path & store_or_statePath, const bool component_or_state, const unsigned int revision)
{
TableId table = 0;
Path path;
@ -592,8 +592,8 @@ static PathSet getXReferrers(const Transaction & txn, const Path & store_or_stat
//printMsg(lvlError, format("we need state references: '%1%' '%2%' '%3%'") % path % store_or_statePath % table);
//Now in references of ALL referrers, (possibly lookup their latest TS based on revision)
int timestamp;
if(revision != -1){
unsigned int timestamp;
if(revision != 0){
bool succeed = nixDB.revisionToTimeStamp(txn, dbStateRevisions, path, revision, timestamp);
if(!succeed)
throw Error(format("Getreferrers cannot find timestamp for revision: '%1%'") % revision);
@ -601,16 +601,16 @@ static PathSet getXReferrers(const Transaction & txn, const Path & store_or_stat
Strings keys;
nixDB.enumTable(txn, table, keys);
map<string, int> latest;
map<string, unsigned int> latest;
for (Strings::const_iterator i = keys.begin(); i != keys.end(); ++i){
Path getStatePath;
int getRevision;
unsigned int getRevision;
nixDB.splitDBKey(*i, getStatePath, getRevision);
if(latest[getStatePath] == 0) //either it is unset
latest[getStatePath] = getRevision;
else if(latest[getStatePath] < getRevision){
if(revision != -1 && getRevision <= timestamp) //or it is greater, but not greater then the timestamp
if(revision != 0 && getRevision <= timestamp) //or it is greater, but not greater then the timestamp //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!! WERE COMPARING A REVISION TO A TIMESTAMP ???
latest[getStatePath] = getRevision;
else //we need the latest so greater is good
latest[getStatePath] = getRevision;
@ -619,7 +619,7 @@ static PathSet getXReferrers(const Transaction & txn, const Path & store_or_stat
//now check if they refer to 'path' (if you cant find it, then they dont referr to it)
PathSet referrers;
for (map<string, int>::const_iterator i = latest.begin(); i != latest.end(); ++i){
for (map<string, unsigned int>::const_iterator i = latest.begin(); i != latest.end(); ++i){
//printMsg(lvlError, format("AAAAA '%1%'") % (*i).first);
@ -635,18 +635,18 @@ static PathSet getXReferrers(const Transaction & txn, const Path & store_or_stat
}
}
static PathSet getReferrersTxn(const Transaction & txn, const Path & store_or_statePath, const int revision)
static PathSet getReferrersTxn(const Transaction & txn, const Path & store_or_statePath, const unsigned int revision)
{
return getXReferrers(txn, store_or_statePath, true, revision);
}
static PathSet getStateReferrersTxn(const Transaction & txn, const Path & store_or_statePath, const int revision)
static PathSet getStateReferrersTxn(const Transaction & txn, const Path & store_or_statePath, const unsigned int revision)
{
return getXReferrers(txn, store_or_statePath, false, revision);
}
void queryReferrersTxn(const Transaction & txn,
const Path & storePath, PathSet & referrers, const int revision)
const Path & storePath, PathSet & referrers, const unsigned int revision)
{
if (!isRealisableComponentOrStatePath(txn, storePath))
throw Error(format("path `%1%' is not valid") % storePath);
@ -655,12 +655,12 @@ void queryReferrersTxn(const Transaction & txn,
}
void LocalStore::queryReferrers(const Path & storePath,
PathSet & referrers, const int revision)
PathSet & referrers, const unsigned int revision)
{
nix::queryReferrersTxn(noTxn, storePath, referrers, revision);
}
void queryStateReferrersTxn(const Transaction & txn, const Path & storePath, PathSet & stateReferrers, const int revision)
void queryStateReferrersTxn(const Transaction & txn, const Path & storePath, PathSet & stateReferrers, const unsigned int revision)
{
if (!isRealisableComponentOrStatePath(txn, storePath))
throw Error(format("path `%1%' is not valid") % storePath);
@ -668,7 +668,7 @@ void queryStateReferrersTxn(const Transaction & txn, const Path & storePath, Pat
stateReferrers.insert(stateReferrers2.begin(), stateReferrers2.end());
}
void LocalStore::queryStateReferrers(const Path & storePath, PathSet & stateReferrers, const int revision)
void LocalStore::queryStateReferrers(const Path & storePath, PathSet & stateReferrers, const unsigned int revision)
{
nix::queryStateReferrersTxn(noTxn, storePath, stateReferrers, revision);
}
@ -1026,7 +1026,7 @@ Path LocalStore::queryStatePathDrv(const Path & statePath)
void registerValidPath(const Transaction & txn,
const Path & component_or_state_path, const Hash & hash,
const PathSet & references, const PathSet & stateReferences,
const Path & deriver, const int revision)
const Path & deriver, const unsigned int revision)
{
ValidPathInfo info;
info.path = component_or_state_path;
@ -1237,7 +1237,7 @@ void LocalStore::exportPath(const Path & path, bool sign,
writeString(path, hashAndWriteSink);
PathSet references;
nix::queryXReferencesTxn(txn, path, references, true, -1); //TODO we can only now export the final revision //TODO also export the state references ???
nix::queryXReferencesTxn(txn, path, references, true, 0); //TODO we can only now export the final revision //TODO also export the state references ???
writeStringSet(references, hashAndWriteSink);
Path deriver = nix::queryDeriver(txn, path);
@ -1618,12 +1618,12 @@ IntVector LocalStore::getStatePathsInterval(const PathSet & statePaths)
TODO Change comment, this can also take state paths
*/
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 unsigned int revision)
{
nix::storePathRequisitesTxn(noTxn, storeOrstatePath, includeOutputs, paths, withComponents, withState, revision);
}
void storePathRequisitesTxn(const Transaction & txn, const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool withComponents, const bool withState, const int revision)
void storePathRequisitesTxn(const Transaction & txn, const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool withComponents, const bool withState, const unsigned int revision)
{
computeFSClosureTxn(txn, storeOrstatePath, paths, withComponents, withState, revision);
@ -1640,7 +1640,7 @@ void storePathRequisitesTxn(const Transaction & txn, const Path & storeOrstatePa
}
}
void LocalStore::storePathRequisites(const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool withComponents, const bool withState, const int revision)
void LocalStore::storePathRequisites(const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool withComponents, const bool withState, const unsigned int revision)
{
nix::storePathRequisites(storeOrstatePath, includeOutputs, paths, withComponents, withState, revision);
}
@ -1672,12 +1672,12 @@ void LocalStore::setStateRevisions(const RevisionClosure & revisions, const Path
nix::setStateRevisionsTxn(noTxn, revisions, rootStatePath, comment);
}
bool queryStateRevisionsTxn(const Transaction & txn, const Path & statePath, RevisionClosure & revisions, RevisionClosureTS & timestamps, const int revision)
bool queryStateRevisionsTxn(const Transaction & txn, const Path & statePath, RevisionClosure & revisions, RevisionClosureTS & timestamps, const unsigned int revision)
{
return nixDB.queryStateRevisions(txn, dbStateRevisions, dbStateSnapshots, statePath, revisions, timestamps, revision);
}
bool LocalStore::queryStateRevisions(const Path & statePath, RevisionClosure & revisions, RevisionClosureTS & timestamps, const int revision)
bool LocalStore::queryStateRevisions(const Path & statePath, RevisionClosure & revisions, RevisionClosureTS & timestamps, const unsigned int revision)
{
return nix::queryStateRevisionsTxn(noTxn, statePath, revisions, timestamps, revision);
}
@ -1735,6 +1735,18 @@ void setSharedStateTxn(const Transaction & txn, const Path & fromExisting, const
nixDB.setString(txn, dbSharedState, toNew, fromExisting);
}
void LocalStore::setSharedState(const Path & fromExisting, const Path & toNew)
{
//TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! LEGALITY CHECK IF THE PATH MAY BE SHARED !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//TODO
//
Transaction txn(nixDB);
setSharedStateTxn(txn, fromExisting, toNew);
txn.commit();
}
bool querySharedStateTxn(const Transaction & txn, const Path & statePath, Path & shared_with)
{
return nixDB.queryString(txn, dbSharedState, statePath, shared_with);
@ -1768,12 +1780,12 @@ PathSet LocalStore::toNonSharedPathSet(const PathSet & statePaths)
return toNonSharedPathSetTxn(noTxn, statePaths);
}
void setStateComponentReferencesTxn(const Transaction & txn, const Path & statePath, const Strings & references, int revision, int timestamp)
void setStateComponentReferencesTxn(const Transaction & txn, const Path & statePath, const Strings & references, const unsigned int revision, const unsigned int timestamp)
{
nixDB.setStateReferences(txn, dbStateComponentReferences, dbStateRevisions, statePath, references, revision, timestamp);
}
void setStateStateReferencesTxn(const Transaction & txn, const Path & statePath, const Strings & references, int revision, int timestamp)
void setStateStateReferencesTxn(const Transaction & txn, const Path & statePath, const Strings & references, const unsigned int revision, const unsigned int timestamp)
{
nixDB.setStateReferences(txn, dbStateStateReferences, dbStateRevisions, statePath, references, revision, timestamp);
}
@ -1821,7 +1833,7 @@ PathSet getSharedWithPathSetRecTxn(const Transaction & txn, const Path & statePa
}
void LocalStore::revertToRevision(const Path & componentPath, const Path & derivationPath, const Path & statePath, const int revision_arg, const bool recursive)
void LocalStore::revertToRevision(const Path & componentPath, const Path & derivationPath, const Path & statePath, const unsigned int revision_arg, const bool recursive)
{
Transaction txn(nixDB);
revertToRevisionTxn(txn, componentPath, derivationPath, statePath, revision_arg, recursive);

View file

@ -51,13 +51,13 @@ public:
Path queryStatePathDrv(const Path & statePath);
void queryReferences(const Path & path, PathSet & references, const int revision);
void queryReferences(const Path & path, PathSet & references, const unsigned int revision);
void queryStateReferences(const Path & storePath, PathSet & stateReferences, const int revision);
void queryStateReferences(const Path & storePath, PathSet & stateReferences, const unsigned int revision);
void queryReferrers(const Path & path, PathSet & referrers, const int revision);
void queryReferrers(const Path & path, PathSet & referrers, const unsigned int revision);
void queryStateReferrers(const Path & path, PathSet & stateReferrers, const int revision);
void queryStateReferrers(const Path & path, PathSet & stateReferrers, const unsigned int revision);
Path addToStore(const Path & srcPath, bool fixed = false,
bool recursive = false, string hashAlgo = "",
@ -94,11 +94,11 @@ public:
bool isStateComponent(const Path & storePath);
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 unsigned int revision);
void setStateRevisions(const RevisionClosure & revisions, const Path & rootStatePath, const string & comment);
bool queryStateRevisions(const Path & statePath, RevisionClosure & revisions, RevisionClosureTS & timestamps, const int revision);
bool queryStateRevisions(const Path & statePath, RevisionClosure & revisions, RevisionClosureTS & timestamps, const unsigned int revision);
bool queryAvailableStateRevisions(const Path & statePath, RevisionInfos & revisions);
@ -112,7 +112,9 @@ public:
PathSet toNonSharedPathSet(const PathSet & statePaths);
void revertToRevision(const Path & componentPath, const Path & derivationPath, const Path & statePath, const int revision_arg, const bool recursive);
void revertToRevision(const Path & componentPath, const Path & derivationPath, const Path & statePath, const unsigned int revision_arg, const bool recursive);
void setSharedState(const Path & fromExisting, const Path & toNew);
};
@ -138,7 +140,7 @@ void clearSubstitutes();
void registerValidPath(const Transaction & txn,
const Path & component_or_state_path, const Hash & hash,
const PathSet & references, const PathSet & stateReferences,
const Path & deriver, const int revision);
const Path & deriver, const unsigned int revision);
struct ValidPathInfo
{
@ -147,7 +149,7 @@ struct ValidPathInfo
Hash hash;
PathSet references;
PathSet stateReferences;
int revision;
int unsigned revision;
};
typedef list<ValidPathInfo> ValidPathInfos;
@ -174,7 +176,7 @@ bool isValidPathTxn(const Transaction & txn, const Path & path);
-1 for revision means overwrite the last revision
*/
void setReferences(const Transaction & txn, const Path & store_or_statePath,
const PathSet & references, const PathSet & stateReferences, const int revision);
const PathSet & references, const PathSet & stateReferences, const unsigned int revision);
/* Sets the deriver of a store path. Use with care! */
void setDeriver(const Transaction & txn, const Path & path,
@ -219,17 +221,17 @@ bool isStateDrv(const Derivation & drv);
void queryAllValidPathsTxn(const Transaction & txn, PathSet & allComponentPaths, PathSet & allStatePaths);
bool isValidStatePathTxn(const Transaction & txn, const Path & path);
void queryXReferencesTxn(const Transaction & txn, const Path & path, PathSet & references, const bool component_or_state, const int revision, int timestamp = -1);
void queryXReferencesTxn(const Transaction & txn, const Path & path, PathSet & references, const bool component_or_state, const unsigned int revision, const unsigned int timestamp = 0);
//TODO THESE DONT BELONG HERE, REFACTOR CODE, EG MOVE FUNCTIONS AROUND
void setStateComponentReferencesTxn(const Transaction & txn, const Path & statePath, const Strings & references, int revision, int timestamp);
void setStateStateReferencesTxn(const Transaction & txn, const Path & statePath, const Strings & references, int revision, int timestamp);
void setStateComponentReferencesTxn(const Transaction & txn, const Path & statePath, const Strings & references, const unsigned int revision, const unsigned int timestamp);
void setStateStateReferencesTxn(const Transaction & txn, const Path & statePath, const Strings & references, const unsigned int revision, const unsigned int timestamp);
void queryReferrersTxn(const Transaction & txn, const Path & storePath, PathSet & referrers, const int revision);
void queryStateReferrersTxn(const Transaction & txn, const Path & storePath, PathSet & stateReferrers, const int revision);
void queryReferrersTxn(const Transaction & txn, const Path & storePath, PathSet & referrers, const unsigned int revision);
void queryStateReferrersTxn(const Transaction & txn, const Path & storePath, PathSet & stateReferrers, const unsigned int revision);
Path queryStatePathDrvTxn(const Transaction & txn, const Path & statePath);
void storePathRequisitesTxn(const Transaction & txn, const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool withComponents, const bool withState, const int revision);
void storePathRequisitesTxn(const Transaction & txn, const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool withComponents, const bool withState, const unsigned int revision);
void setStateRevisionsTxn(const Transaction & txn, const RevisionClosure & revisions, const Path & rootStatePath, const string & comment);
bool isValidPathTxn(const Transaction & txn, const Path & path);
@ -246,7 +248,7 @@ PathSet getSharedWithPathSetRecTxn(const Transaction & txn, const Path & statePa
void ensurePathTxn(const Transaction & txn, const Path & path);
IntVector getStatePathsIntervalTxn(const Transaction & txn, const PathSet & statePaths);
bool queryStateRevisionsTxn(const Transaction & txn, const Path & statePath, RevisionClosure & revisions, RevisionClosureTS & timestamps, const 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);
}

View file

@ -142,7 +142,7 @@ void queryMissing(const PathSet & targets,
if (store->hasSubstitutes(p))
willSubstitute.insert(p);
PathSet refs;
store->queryReferences(p, todo, -1); //TODO?
store->queryReferences(p, todo, 0); //TODO?
}
}
}

View file

@ -216,22 +216,22 @@ Path RemoteStore::queryStatePathDrv(const Path & statePath)
}
void RemoteStore::queryReferences(const Path & path,
PathSet & references, const int revision)
PathSet & references, const unsigned int revision)
{
writeInt(wopQueryReferences, to);
writeString(path, to);
writeInt(revision, to);
writeBigUnsignedInt(revision, to);
processStderr();
PathSet references2 = readStorePaths(from);
references.insert(references2.begin(), references2.end());
}
void RemoteStore::queryStateReferences(const Path & path,
PathSet & stateReferences, const int revision)
PathSet & stateReferences, const unsigned int revision)
{
writeInt(wopQueryStateReferences, to);
writeString(path, to);
writeInt(revision, to);
writeBigUnsignedInt(revision, to);
processStderr();
PathSet stateReferences2 = readStorePaths(from);
stateReferences.insert(stateReferences2.begin(), stateReferences2.end());
@ -239,11 +239,11 @@ void RemoteStore::queryStateReferences(const Path & path,
void RemoteStore::queryReferrers(const Path & path,
PathSet & referrers, const int revision)
PathSet & referrers, const unsigned int revision)
{
writeInt(wopQueryReferrers, to);
writeString(path, to);
writeInt(revision, to);
writeBigUnsignedInt(revision, to);
processStderr();
PathSet referrers2 = readStorePaths(from);
referrers.insert(referrers2.begin(), referrers2.end());
@ -251,11 +251,11 @@ void RemoteStore::queryReferrers(const Path & path,
}
void RemoteStore::queryStateReferrers(const Path & path,
PathSet & stateReferrers, const int revision)
PathSet & stateReferrers, const unsigned int revision)
{
writeInt(wopQueryStateReferrers, to);
writeString(path, to);
writeInt(revision, to);
writeBigUnsignedInt(revision, to);
processStderr();
PathSet stateReferrers2 = readStorePaths(from);
stateReferrers.insert(stateReferrers2.begin(), stateReferrers2.end());
@ -439,7 +439,7 @@ bool RemoteStore::isStateComponent(const Path & path)
return reply != 0;
}
void RemoteStore::storePathRequisites(const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool withComponents, const bool withState, const int revision)
void RemoteStore::storePathRequisites(const Path & storeOrstatePath, const bool includeOutputs, PathSet & paths, const bool withComponents, const bool withState, const unsigned int revision)
{
writeInt(wopStorePathRequisites, to);
writeString(storeOrstatePath, to);
@ -447,7 +447,7 @@ void RemoteStore::storePathRequisites(const Path & storeOrstatePath, const bool
writeStringSet(paths, to);
writeInt(withComponents ? 1 : 0, to);
writeInt(withState ? 1 : 0, to);
writeInt(revision, to);
writeBigUnsignedInt(revision, to);
processStderr();
readInt(from);
}
@ -462,16 +462,16 @@ void RemoteStore::setStateRevisions(const RevisionClosure & revisions, const Pat
readInt(from);
}
bool RemoteStore::queryStateRevisions(const Path & statePath, RevisionClosure & revisions, RevisionClosureTS & timestamps, const int revision)
bool RemoteStore::queryStateRevisions(const Path & statePath, RevisionClosure & revisions, RevisionClosureTS & timestamps, const unsigned int revision)
{
writeInt(wopQueryStateRevisions, to);
writeString(statePath, to);
writeInt(revision, to);
writeBigUnsignedInt(revision, to);
processStderr();
RevisionClosure revisions2 = readRevisionClosure(from);
RevisionClosureTS timestamps2 = readRevisionClosureTS(from);
revisions = revisions2; //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
timestamps = timestamps2; //TODO !!!!!!!!!!!!!!!!!!!! COPY BY VALUE I THINK
processStderr();
unsigned int reply = readInt(from);
return reply != 0;
}
@ -480,9 +480,9 @@ bool RemoteStore::queryAvailableStateRevisions(const Path & statePath, RevisionI
{
writeInt(wopQueryAvailableStateRevisions, to);
writeString(statePath, to);
processStderr();
RevisionInfos revisions2 = readRevisionInfos(from);
revisions = revisions2; //TODO !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
processStderr();
unsigned int reply = readInt(from);
return reply != 0;
}
@ -513,18 +513,26 @@ PathSet RemoteStore::toNonSharedPathSet(const PathSet & statePaths)
return readStringSet(from); //TODO !!!!!!!!!!!!!!! create a readStatePaths just like readStorePaths
}
void RemoteStore::revertToRevision(const Path & componentPath, const Path & derivationPath, const Path & statePath, const int revision_arg, const bool recursive)
void RemoteStore::revertToRevision(const Path & componentPath, const Path & derivationPath, const Path & statePath, const unsigned int revision_arg, const bool recursive)
{
writeInt(wopRevertToRevision, to);
writeString(componentPath, to);
writeString(derivationPath, to);
writeString(statePath, to);
writeInt(revision_arg, to);
writeBigUnsignedInt(revision_arg, to);
writeInt(recursive ? 1 : 0, to);
processStderr();
readInt(from);
}
void RemoteStore::setSharedState(const Path & fromExisting, const Path & toNew)
{
writeString(fromExisting, to);
writeString(toNew, to);
processStderr();
readInt(from);
}
void RemoteStore::processStderr(Sink * sink, Source * source)
{
@ -556,5 +564,4 @@ void RemoteStore::processStderr(Sink * sink, Source * source)
}
}

View file

@ -39,13 +39,13 @@ public:
Path queryStatePathDrv(const Path & statePath);
void queryReferences(const Path & path, PathSet & references, const int revision);
void queryReferences(const Path & path, PathSet & references, const unsigned int revision);
void queryStateReferences(const Path & storePath, PathSet & stateReferences, const int revision);
void queryStateReferences(const Path & storePath, PathSet & stateReferences, const unsigned int revision);
void queryReferrers(const Path & path, PathSet & referrers, const int revision);
void queryReferrers(const Path & path, PathSet & referrers, const unsigned int revision);
void queryStateReferrers(const Path & path, PathSet & stateReferrers, const int revision);
void queryStateReferrers(const Path & path, PathSet & stateReferrers, const unsigned int revision);
Path addToStore(const Path & srcPath, bool fixed = false,
bool recursive = false, string hashAlgo = "",
@ -80,11 +80,11 @@ public:
bool isStateComponent(const Path & path);
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 unsigned int revision);
void setStateRevisions(const RevisionClosure & revisions, const Path & rootStatePath, const string & comment);
bool queryStateRevisions(const Path & statePath, RevisionClosure & revisions, RevisionClosureTS & timestamps, const int revision);
bool queryStateRevisions(const Path & statePath, RevisionClosure & revisions, RevisionClosureTS & timestamps, const unsigned int revision);
bool queryAvailableStateRevisions(const Path & statePath, RevisionInfos & revisions);
@ -98,7 +98,9 @@ public:
PathSet toNonSharedPathSet(const PathSet & statePaths);
void revertToRevision(const Path & componentPath, const Path & derivationPath, const Path & statePath, const int revision_arg, const bool recursive);
void revertToRevision(const Path & componentPath, const Path & derivationPath, const Path & statePath, const unsigned int revision_arg, const bool recursive);
void setSharedState(const Path & fromExisting, const Path & toNew);
private:
AutoCloseFD fdSocket;

View file

@ -81,20 +81,20 @@ public:
/* Queries the set of outgoing FS references for a store path.
The result is not cleared. */
virtual void queryReferences(const Path & path,
PathSet & references, const int revision) = 0;
PathSet & references, const unsigned int revision) = 0;
/* Queries the set of outgoing FS state-references for a store path.
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 unsigned int revision) = 0;
/* Queries the set of incoming FS references for a store path.
The result is not cleared. */
virtual void queryReferrers(const Path & path,
PathSet & referrers, const int revision) = 0;
PathSet & referrers, const unsigned int revision) = 0;
/* Queries the set of incoming FS state-references for a store path.
The result is not cleared. */
virtual void queryStateReferrers(const Path & path, PathSet & stateReferrers, const int revision) = 0;
virtual void queryStateReferrers(const Path & path, PathSet & stateReferrers, const unsigned int revision) = 0;
/* Copy the contents of a path to the store and register the
validity the resulting path. The resulting path is returned.
@ -209,13 +209,13 @@ public:
virtual bool isStateComponent(const Path & path) = 0;
/* TODO */
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 unsigned int revision) = 0;
/* TODO */
virtual void setStateRevisions(const RevisionClosure & revisions, const Path & rootStatePath, const string & comment) = 0;
/* TODO */
virtual bool queryStateRevisions(const Path & statePath, RevisionClosure & revisions, RevisionClosureTS & timestamps, const int revision) = 0;
virtual bool queryStateRevisions(const Path & statePath, RevisionClosure & revisions, RevisionClosureTS & timestamps, const unsigned int revision) = 0;
/* TODO */
virtual bool queryAvailableStateRevisions(const Path & statePath, RevisionInfos & revisions) = 0;
@ -237,7 +237,10 @@ public:
virtual PathSet toNonSharedPathSet(const PathSet & statePaths) = 0;
/* TODO */
virtual void revertToRevision(const Path & componentPath, const Path & derivationPath, const Path & statePath, const int revision_arg, const bool recursive) = 0;
virtual void revertToRevision(const Path & componentPath, const Path & derivationPath, const Path & statePath, const unsigned int revision_arg, const bool recursive) = 0;
/* TODO */
virtual void setSharedState(const Path & fromExisting, const Path & toNew) = 0;
};

View file

@ -29,7 +29,7 @@ void updatedStateDerivation(Path storePath)
}
*/
void createStateDirsTxn(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;
string stateDir = statePath;
@ -57,7 +57,7 @@ void createStateDirsTxn(const Transaction & txn, const DerivationStateOutputDirs
Path fullstatedir = stateDir + "/" + thisdir;
ensureDirExists(fullstatedir);
setStatePathRights(fullstatedir, queryCallingUsername(), "nixbld");
if(d.type == "interval"){
intervalPaths.insert(fullstatedir);
@ -100,7 +100,7 @@ void revertToRevisionTxn(const Transaction & txn, const Path & componentPath, co
statePaths.insert(derivationPath); //Insert direct state path
//get a new timestamp for the references update
int newTimestamp = getTimeStamp();
unsigned int newTimestamp = getTimeStamp();
//Get the revisions recursively to also roll them back
RevisionClosure getRivisions;
@ -111,7 +111,7 @@ void revertToRevisionTxn(const Transaction & txn, const Path & componentPath, co
for (RevisionClosure::iterator i = getRivisions.begin(); i != getRivisions.end(); ++i){
Path statePath = (*i).first;
Snapshots revisioned_paths = (*i).second;
int timestamp = getTimestamps[statePath];
unsigned int timestamp = getTimestamps[statePath];
//get its derivation-state-items
Derivation statePath_drv = derivationFromPathTxn(txn, queryStatePathDrvTxn(noTxn, statePath));
@ -183,13 +183,13 @@ void revertToRevisionTxn(const Transaction & txn, const Path & componentPath, co
//Query the references of the old revision (already converted to a timestamp)
PathSet state_references;
queryXReferencesTxn(txn, statePath, state_references, true, -1, timestamp);
queryXReferencesTxn(txn, statePath, state_references, true, 0, timestamp);
PathSet state_stateReferences;
queryXReferencesTxn(txn, statePath, state_stateReferences, false, -1, timestamp);
queryXReferencesTxn(txn, statePath, state_stateReferences, false, 0, timestamp);
//Now set these old references as the new references at the new (just created) Timestamp
setStateComponentReferencesTxn(txn, statePath, Strings(state_references.begin(), state_references.end()), -1, newTimestamp);
setStateStateReferencesTxn(txn, statePath, Strings(state_stateReferences.begin(), state_stateReferences.end()), -1, newTimestamp);
setStateComponentReferencesTxn(txn, statePath, Strings(state_references.begin(), state_references.end()), 0, newTimestamp);
setStateStateReferencesTxn(txn, statePath, Strings(state_stateReferences.begin(), state_stateReferences.end()), 0, newTimestamp);
printMsg(lvlError, format("Reverted state of '%1%' to revision '%2%'") % statePath % revision_arg);
}
@ -309,8 +309,8 @@ void scanAndUpdateAllReferencesTxn(const Transaction & txn, const Path & statePa
//Retrieve old references
PathSet old_references;
PathSet old_state_references;
queryXReferencesTxn(txn, statePath, old_references, true, -1); //get the latsest references
queryXReferencesTxn(txn, statePath, old_state_references, false, -1);
queryXReferencesTxn(txn, statePath, old_references, true, 0); //get the latsest references
queryXReferencesTxn(txn, statePath, old_state_references, false, 0);
//Check for added and removed paths
PathSet diff_references_removed;
@ -347,7 +347,7 @@ void scanAndUpdateAllReferencesTxn(const Transaction & txn, const Path & statePa
state_references,
state_stateReferences,
drvPath,
-1); //Set at a new timestamp
0); //Set at a new timestamp
}
void scanAndUpdateAllReferencesRecusivelyTxn(const Transaction & txn, const Path & statePath)
@ -357,7 +357,7 @@ void scanAndUpdateAllReferencesRecusivelyTxn(const Transaction & txn, const Path
//get all state current state references recursively
PathSet statePaths;
storePathRequisitesTxn(txn, statePath, false, statePaths, false, true, -1); //Get all current state dependencies
storePathRequisitesTxn(txn, statePath, false, statePaths, false, true, 0); //Get all current state dependencies
//Add own statePath (may already be in there, but its a set, so no doubles)
statePaths.insert(statePath);

View file

@ -8,7 +8,7 @@
namespace nix {
/* Create a state directory. */
void createStateDirsTxn(const Transaction & txn, const DerivationStateOutputDirs & stateOutputDirs, const DerivationStateOutputs & stateOutputs);
void createSubStateDirsTxn(const Transaction & txn, const DerivationStateOutputDirs & stateOutputDirs, const DerivationStateOutputs & stateOutputs);
/* TODO */
Snapshots commitStatePathTxn(const Transaction & txn, const Path & statePath);

View file

@ -10,7 +10,7 @@ namespace nix {
typedef enum {
wopQuit,
wopQuit, //0
wopIsValidPath,
wopIsValidStatePath,
wopIsValidComponentOrStatePath,
@ -20,7 +20,7 @@ typedef enum {
wopQueryStatePathDrv,
wopQueryReferences,
wopQueryStateReferences,
wopQueryReferrers,
wopQueryReferrers, //10
wopQueryStateReferrers,
wopAddToStore,
wopAddTextToStore,
@ -30,23 +30,23 @@ typedef enum {
wopAddIndirectRoot,
wopSyncWithGC,
wopFindRoots,
wopCollectGarbage,
wopCollectGarbage, //20
wopExportPath,
wopImportPath,
wopQueryDeriver,
wopQueryDerivers,
wopSetStatePathsInterval,
wopGetStatePathsInterval,
wopIsStateComponent,
wopStorePathRequisites,
wopSetStateRevisions,
wopQueryStateRevisions,
wopQueryStateRevisions, //30
wopQueryAvailableStateRevisions,
wopCommitStatePath,
wopScanAndUpdateAllReferences,
wopToNonSharedPathSet,
wopRevertToRevision,
wopSetSharedState,
} WorkerOp;

View file

@ -38,6 +38,11 @@ void writeInt(unsigned int n, Sink & sink)
sink(buf, sizeof(buf));
}
void writeBigUnsignedInt(unsigned int n, Sink & sink)
{
writeString(unsignedInt2String(n), sink); //TODO better way?
}
void writeString(const string & s, Sink & sink)
{
@ -58,8 +63,8 @@ void writeStringSet(const StringSet & ss, Sink & sink)
void writeIntVector(const IntVector & iv, Sink & sink)
{
writeInt(iv.size(), sink);
for(int i=0;i < iv.size(); i++)
writeString(int2String(iv.at(i)), sink);
for(unsigned int i=0;i < iv.size(); i++)
writeString(int2String(iv.at(i)), sink); //TODO !!!!!!!!!!!!!!!!!!! writeInts ???????????
}
void writeRevisionClosure(const RevisionClosure & rc, Sink & sink)
@ -76,7 +81,7 @@ void writeSnapshots(const Snapshots & ss, Sink & sink)
writeInt(ss.size(), sink);
for (Snapshots::const_iterator i = ss.begin(); i != ss.end(); ++i){
writeString((*i).first, sink);
writeInt((*i).second, sink); //TODO MUST BE UNSGINED INT
writeBigUnsignedInt((*i).second, sink);
}
}
@ -85,7 +90,7 @@ void writeRevisionClosureTS(const RevisionClosureTS & rc, Sink & sink)
writeInt(rc.size(), sink);
for (RevisionClosureTS::const_iterator i = rc.begin(); i != rc.end(); ++i){
writeString((*i).first, sink);
writeInt((*i).second, sink);
writeBigUnsignedInt((*i).second, sink);
}
}
@ -93,10 +98,10 @@ void writeRevisionInfos(const RevisionInfos & ri, Sink & sink)
{
writeInt(ri.size(), sink);
for (RevisionInfos::const_iterator i = ri.begin(); i != ri.end(); ++i){
writeInt((*i).first, sink);
writeBigUnsignedInt((*i).first, sink);
RevisionInfo rvi = (*i).second;
writeString(rvi.comment, sink);
writeInt(rvi.timestamp, sink); //TODO MUST BE UNSGINED INT
writeBigUnsignedInt(rvi.timestamp, sink);
}
}
@ -111,13 +116,12 @@ void readPadding(unsigned int len, Source & source)
}
}
unsigned int readInt(Source & source)
{
unsigned char buf[8];
source(buf, sizeof(buf));
if (buf[4] || buf[5] || buf[6] || buf[7])
throw Error("implementation cannot deal with > 32-bit integers"); //TODO !!!!!!!!!!!!!!!!! unsigned Int reader
throw Error("implementation cannot deal with > 32-bit integers");
return
buf[0] |
(buf[1] << 8) |
@ -125,6 +129,15 @@ unsigned int readInt(Source & source)
(buf[3] << 24);
}
unsigned int readBigUnsignedInt(Source & source)
{
string s = readString(source);
unsigned int i;
if(! string2UnsignedInt(s, i) )
throw Error(format("Serialize: readBigUnsignedInt cannot read int: '%1%'") % s);
return i;
}
string readString(Source & source)
{
@ -146,30 +159,12 @@ StringSet readStringSet(Source & source)
return ss;
}
/*
//IntVector
//RevisionClosure
//RevisionClosureTS
//RevisionInfos
struct RevisionInfo
{
string comment;
unsigned int timestamp;
};
typedef map<int, RevisionInfo> RevisionInfos;
typedef map<Path, unsigned int> Snapshots; //Automatically sorted on Path :)
typedef map<Path, Snapshots> RevisionClosure;
typedef map<Path, int> RevisionClosureTS;
*/
IntVector readIntVector(Source & source)
{
unsigned int count = readInt(source);
IntVector iv;
while (count--){
string s = readString(source);
string s = readString(source); //TODO !!!!!!!!!!!!!!!!!!!! readInt ???????????????
int i;
if (!string2Int(s, i))
throw Error(format("`%1%' is corrupt in readIntVector") % s);
@ -197,7 +192,7 @@ Snapshots readSnapshots(Source & source)
Snapshots ss;
while (count--){
string path = readString(source);
unsigned int ri = readInt(source); //TODO MUST BE UNSGINED INT
unsigned int ri = readBigUnsignedInt(source);
ss[path] = ri;
}
return ss;
@ -210,7 +205,7 @@ RevisionClosureTS readRevisionClosureTS(Source & source)
RevisionClosureTS rc;
while (count--){
string path = readString(source);
int ri = readInt(source);
int ri = readBigUnsignedInt(source);
rc[path] = ri;
}
return rc;
@ -221,11 +216,13 @@ RevisionInfos readRevisionInfos(Source & source)
unsigned int count = readInt(source);
RevisionInfos ri;
while (count--){
readInt(source);
unsigned int revision = readBigUnsignedInt(source);
RevisionInfo rvi;
rvi.comment = readString(source);
rvi.timestamp = readInt(source);
rvi.timestamp = readBigUnsignedInt(source);
ri[revision] = rvi;
}
return ri;
}
}

View file

@ -95,6 +95,7 @@ struct StringSource : Source
void writePadding(unsigned int len, Sink & sink);
void writeInt(unsigned int n, Sink & sink);
void writeBigUnsignedInt(unsigned int n, Sink & sink);
void writeString(const string & s, Sink & sink);
void writeStringSet(const StringSet & ss, Sink & sink);
@ -106,6 +107,7 @@ void writeRevisionInfos(const RevisionInfos & ri, Sink & sink);
void readPadding(unsigned int len, Source & source);
unsigned int readInt(Source & source);
unsigned int readBigUnsignedInt(Source & source);
string readString(Source & source);
StringSet readStringSet(Source & source);

View file

@ -59,16 +59,17 @@ typedef list<Path> Paths;
typedef set<Path> PathSet;
//state types
typedef vector<int> IntVector; //the Strings (list) of StateReferences and this list are connected by position
typedef vector<int> IntVector; //the Strings (list) of StateReferences and this list are connected by position //TODO
typedef vector<unsigned int> UnsignedIntVector;
struct RevisionInfo
{
string comment;
unsigned int timestamp;
};
typedef map<int, RevisionInfo> RevisionInfos;
typedef map<unsigned int, RevisionInfo> RevisionInfos;
typedef map<Path, unsigned int> Snapshots; //Automatically sorted on Path :)
typedef map<Path, Snapshots> RevisionClosure;
typedef map<Path, int> RevisionClosureTS;
typedef map<Path, unsigned int> RevisionClosureTS; //Paht with a timestamp about when the revision was made.
typedef map<int, Strings> StateReferences;

View file

@ -919,28 +919,26 @@ Strings unpackStrings(const string & s)
return strings;
}
string packRevisionNumbers(const IntVector & revs)
/*
string packRevisionNumbers(const UnsignedIntVector & revs)
{
string seperator = "|";
string d = "";
for (IntVector::const_iterator i = revs.begin();
i != revs.end(); ++i){
d += int2String(*i) + seperator;
for (UnsignedIntVector::const_iterator i = revs.begin(); i != revs.end(); ++i){
d += unsignedInt2String(*i) + seperator;
}
return d;
}
IntVector unpackRevisionNumbers(const string & packed)
UnsignedIntVector unpackRevisionNumbers(const string & packed)
{
string seperator = "|";
Strings ss = tokenizeString(packed, seperator);
IntVector revs;
for (Strings::const_iterator i = ss.begin();
i != ss.end(); ++i){
UnsignedIntVector revs;
for (Strings::const_iterator i = ss.begin(); i != ss.end(); ++i){
int rev;
bool succeed = string2Int(*i, rev);
bool succeed = string2UnsignedInt(*i, rev);
if(!succeed)
throw Error(format("Corrupted revisions db entry: `%1%'") % packed);
revs.push_back(rev);
@ -948,7 +946,7 @@ IntVector unpackRevisionNumbers(const string & packed)
return revs;
}
*/
Strings tokenizeString(const string & s, const string & separators)
{
@ -1141,10 +1139,10 @@ void executeShellCommand(const string & command)
}
}
int getTimeStamp()
unsigned int getTimeStamp()
{
const time_t now = time(0);
int i = now;
unsigned int i = now;
return i;
}
@ -1243,6 +1241,22 @@ void ensureDirExists(const Path & path)
runProgram_AndPrintOutput("mkdir", true, p_args, "mkdir"); //TODO ensurePath
}
void setStatePathRights(const Path & statePath, const string & user, const string & group, const string & chmod)
{
ensureDirExists(statePath);
Strings p_args;
p_args.push_back(user + "." + group);
p_args.push_back(statePath);
runProgram_AndPrintOutput("chown", true, p_args, "chown");
if(chmod != "") {
p_args.clear();
p_args.push_back(chmod);
p_args.push_back(statePath);
runProgram_AndPrintOutput("chmod", true, p_args, "chmod");
}
}
string padd(const string & s, char c , unsigned int size, bool front)
{
string ss = s;

View file

@ -308,7 +308,7 @@ void executeShellCommand(const string & command);
//
void runProgram_AndPrintOutput(Path program, bool searchPath, const Strings & args, const string outputPrefix);
int getTimeStamp();
unsigned int getTimeStamp();
//string getCallingUserName();
@ -318,8 +318,12 @@ PathSet pathSets_union(const PathSet & paths1, const PathSet & paths2);
/* TODO */
void pathSets_difference(const PathSet & oldpaths, const PathSet & newpaths, PathSet & addedpaths, PathSet & removedpaths);
/* TODO */
void ensureDirExists(const Path & path);
/* TODO */
void setStatePathRights(const Path & statePath, const string & user, const string & group, const string & chmod = "");
string padd(const string & s, char c , unsigned int size, bool front = false);
void sharePath(const Path & fromExisting, const Path & toNew);

View file

@ -403,7 +403,7 @@ static void queryInstSources(EvalState & state,
if (isDerivation(*i)) {
elem.setDrvPath(*i);
elem.setOutPath(findOutput(derivationFromPathTxn(noTxn, *i), "out"));
elem.setOutPath(findOutput(derivationFromPath(*i), "out"));
if (name.size() >= drvExtension.size() &&
string(name, name.size() - drvExtension.size()) == drvExtension)
@ -543,7 +543,7 @@ static void installDerivations(Globals & globals,
for (DrvInfos::iterator j = newElems.begin(); j != newElems.end(); ++j) {
DrvName newDrvName(j->name);
if(newDrvName.name == drvName.name){
Derivation newDrv = derivationFromPathTxn(noTxn, j->queryDrvPath(globals.state));
Derivation newDrv = derivationFromPath(j->queryDrvPath(globals.state));
DerivationStateOutputs newStateOutputs = newDrv.stateOutputs;
newStateIdentifier = newStateOutputs.find("state")->second.stateIdentifier;
newStatePath = newDrv.stateOutputs.find("state")->second.statepath;
@ -563,12 +563,12 @@ static void installDerivations(Globals & globals,
string oldStatePath;
//query old state path
PathSet derivers = store->queryDerivers(i->queryOutPath(globals.state), newStateIdentifier, int2String(geteuid())); //TODO Check if username if ok
PathSet derivers = store->queryDerivers(i->queryOutPath(globals.state), newStateIdentifier, queryCurrentUsername()); //TODO Check if username if ok
if(derivers.size() != 1)
throw Error(format("Internal Error: There is not exactly one deriver with state_identifier '%1%' for path '%2%'")
% newStateIdentifier % i->queryOutPath(globals.state));
Path oldDrvPath = *(derivers.begin());
Derivation oldDrv = derivationFromPathTxn(noTxn, oldDrvPath);
Derivation oldDrv = derivationFromPath(oldDrvPath);
oldStatePath = oldDrv.stateOutputs.find("state")->second.statepath;
//SharePaths
@ -605,7 +605,7 @@ static void installDerivations(Globals & globals,
sharePath(i->first, i->second); //Share new statepath to the old statepath
//Set in database
setSharedStateTxn(noTxn, i->first, i->second);
store->setSharedState(i->first, i->second);
}

View file

@ -27,7 +27,7 @@ typedef void (* Operation) (Strings opFlags, Strings opArgs);
string stateIdentifier;
string username;
string comment;
int revision_arg;
unsigned int revision_arg;
bool scanforReferences = false;
bool only_commit = false;
bool revert_recursively = false;
@ -213,7 +213,7 @@ static void queryAvailableStateRevisions(Strings opFlags, Strings opArgs)
}
//Sort ourselfes to create a nice output
IntVector revisions_sort;
UnsignedIntVector revisions_sort;
int highestrev;
for (RevisionInfos::iterator i = revisions.begin(); i != revisions.end(); ++i){
int rev = (*i).first;
@ -224,7 +224,7 @@ static void queryAvailableStateRevisions(Strings opFlags, Strings opArgs)
sort(revisions_sort.begin(), revisions_sort.end());
int max_size = int2String(highestrev).length();
for (IntVector::iterator i = revisions_sort.begin(); i != revisions_sort.end(); ++i)
for (UnsignedIntVector::iterator i = revisions_sort.begin(); i != revisions_sort.end(); ++i)
{
int rev = *i;
string rev_s = padd(int2String(rev), '0' , max_size, true); //pad revisions with a 0
@ -297,7 +297,7 @@ static void opRunComponent(Strings opFlags, Strings opArgs)
//get all current (maybe updated by the scan) dependecies (if neccecary | recusively) of all state components that need to be updated
PathSet statePaths;
store->storePathRequisites(root_componentPath, false, statePaths, false, true, -1);
store->storePathRequisites(root_componentPath, false, statePaths, false, true, 0);
statePaths.insert(root_statePath);
//Start transaction TODO
@ -321,12 +321,16 @@ static void opRunComponent(Strings opFlags, Strings opArgs)
//Debugging
RevisionClosure getRivisions;
RevisionClosureTS empty;
bool b = store->queryStateRevisions(root_statePath, getRivisions, empty, -1);
bool b = store->queryStateRevisions(root_statePath, getRivisions, empty, 0);
for (RevisionClosure::iterator i = getRivisions.begin(); i != getRivisions.end(); ++i){
//printMsg(lvlError, format("State %1% has revision %2%") % (*i).first % int2String((*i).second));
printMsg(lvlError, format("State '%1%' has revision") % (*i).first);
}
}
void testUI(unsigned int i)
{
printMsg(lvlError, format("Int: %1%") % i);
}
@ -409,12 +413,12 @@ void run(Strings args)
Database nixDB;
Path statePath = "afsdsdafsadf-sda-fsda-f-sdaf-sdaf";
int revision = 5;
unsigned int revision = 5;
Path statePath2;
Path gets = nixDB.makeStatePathRevision(statePath, revision);
int revision2;
nixDB.splitStatePathRevision(gets, statePath2, revision2);
printMsg(lvlError, format("'%1%' '%2%'") % statePath2 % int2String(revision2));
printMsg(lvlError, format("'%1%' '%2%'") % statePath2 % unsignedInt2String(revision2));
store = openStore();
Derivation drv = derivationFromPath("/nix/store/r2lvhrd8zhb877n07cqvcyp11j9ws5p0-hellohardcodedstateworld-dep1-1.0.drv");
@ -477,10 +481,17 @@ void run(Strings args)
printMsg(lvlError, format("Username fail: '%1%'") % uidToUsername(23423)); //Segfaults correctly
int b = -1;
unsigned int c = b;
std::cout << "UNSIGNED INT: " << c << "\n"; //prints 4294967295 !!!!!!
store = openStore();
RevisionClosure revisions;
RevisionClosureTS timestamps;
bool b = store->queryStateRevisions("/nix/state/aacs4qpi9jzg4vmhj09d0ichframh22x-hellohardcodedstateworld-1.0-test", revisions, timestamps, 0);
return;
*/
/* test */
for (Strings::iterator i = args.begin(); i != args.end(); ) {
@ -502,7 +513,7 @@ void run(Strings args)
op = queryAvailableStateRevisions;
else if (arg.substr(0,21) == "--revert-to-revision="){
op = revertToRevision;
bool succeed = string2Int(arg.substr(21,arg.length()), revision_arg);
bool succeed = string2UnsignedInt(arg.substr(21,arg.length()), revision_arg);
if(!succeed)
throw UsageError("The given revision is not a valid number");
}

View file

@ -115,8 +115,8 @@ void printDotGraph(const PathSet & roots)
//Lookup all references
PathSet references;
PathSet stateReferences;
store->queryReferences(path, references, -1);
store->queryStateReferences(path, stateReferences, -1);
store->queryReferences(path, references, 0);
store->queryStateReferences(path, stateReferences, 0);
PathSet allReferences = pathSets_union(references, stateReferences);
for (PathSet::iterator i = allReferences.begin();

View file

@ -214,8 +214,8 @@ static void printTree(const Path & path,
//Lookup all references
PathSet references;
PathSet stateReferences;
store->queryReferences(path, references, -1);
store->queryStateReferences(path, stateReferences, -1);
store->queryReferences(path, references, 0);
store->queryStateReferences(path, stateReferences, 0);
PathSet allReferences = pathSets_union(references, stateReferences);
#if 0
@ -250,7 +250,7 @@ static void opQuery(Strings opFlags, Strings opArgs)
bool includeOutputs = false;
bool forceRealise = false;
string bindingName;
int revision = -1; //last revision
unsigned int revision = 0; //last revision
for (Strings::iterator i = opFlags.begin();
i != opFlags.end(); ++i)
@ -280,7 +280,7 @@ static void opQuery(Strings opFlags, Strings opArgs)
else if (*i == "--force-realise" || *i == "-f") forceRealise = true;
else if (*i == "--include-outputs") includeOutputs = true;
else if ((*i).substr(0,11) == "--revision="){
bool succeed = string2Int((*i).substr(11,(*i).length()), revision);
bool succeed = string2UnsignedInt((*i).substr(11,(*i).length()), revision);
if(!succeed)
throw UsageError("The given revision is not a valid number");
}

View file

@ -295,7 +295,7 @@ static void performOp(Source & from, Sink & to, unsigned int op)
case wopQueryReferences:
case wopQueryReferrers: {
Path path = readStorePath(from);
int revision = readInt(from);
unsigned int revision = readBigUnsignedInt(from);
startWork();
PathSet paths;
if (op == wopQueryReferences)
@ -310,7 +310,7 @@ static void performOp(Source & from, Sink & to, unsigned int op)
case wopQueryStateReferences:
case wopQueryStateReferrers: {
Path path = readStorePath(from);
int revision = readInt(from);
unsigned int revision = readBigUnsignedInt(from);
startWork();
PathSet paths;
if (op == wopQueryStateReferences)
@ -505,7 +505,7 @@ static void performOp(Source & from, Sink & to, unsigned int op)
PathSet paths = readStringSet(from);
bool withComponents = readInt(from) == 1;
bool withState = readInt(from) == 1;
int revision = readInt(from);
unsigned int revision = readBigUnsignedInt(from);
startWork();
store->storePathRequisites(storeOrstatePath, includeOutputs, paths, withComponents, withState, revision);
stopWork();
@ -525,8 +525,9 @@ static void performOp(Source & from, Sink & to, unsigned int op)
}
case wopQueryStateRevisions: {
printMsg(lvlError, format("queryStateRevisions nix-worker"));
Path statePath = readString(from);
int revision = readInt(from);
unsigned int revision = readBigUnsignedInt(from);
RevisionClosure revisions;
RevisionClosureTS timestamps;
startWork();
@ -581,7 +582,7 @@ static void performOp(Source & from, Sink & to, unsigned int op)
Path componentPath = readString(from);
Path derivationPath = readString(from);
Path statePath = readString(from);
int revision_arg = readInt(from);
unsigned int revision_arg = readBigUnsignedInt(from);
bool recursive = readInt(from) == 1;
startWork();
store->revertToRevision(componentPath, derivationPath, statePath, revision_arg, recursive);
@ -590,6 +591,16 @@ static void performOp(Source & from, Sink & to, unsigned int op)
break;
}
case wopSetSharedState: {
Path fromExisting = readString(from);
Path toNew = readString(from);
startWork();
store->setSharedState(fromExisting, toNew);
stopWork();
writeInt(1, to);
break;
}
default:
throw Error(format("invalid operation %1%") % op);
}