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

Fixed bugs in revertToRevision and getSharedWithPathSetRecTxn. Users can now also revert to older revisions.

This commit is contained in:
Wouter den Breejen 2007-09-03 12:13:22 +00:00
parent 094c69ad19
commit 68cb244c90
10 changed files with 69 additions and 31 deletions

View file

@ -664,6 +664,13 @@ void Database::setStateRevisions(const Transaction & txn, TableId revisions_tabl
//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);
/*
printMsg(lvlError, format("SP RootSP '%1%' - '%2%'") % statePath % rootStatePath);
for (PathSet::const_iterator j = sharedWith.begin(); j != sharedWith.end(); ++j)
printMsg(lvlError, format("SP SW '%1%'") % *j);
*/
if(statePath == rootStatePath || sharedWith.find(rootStatePath) != sharedWith.end())
metadata.push_back(comment);
else

View file

@ -1791,7 +1791,7 @@ void setStateStateReferencesTxn(const Transaction & txn, const Path & statePath,
}
//Lookups which statePaths directy share (point to) statePath
PathSet getSharedWithPathSetTxn(const Transaction & txn, const Path & statePath)
PathSet getDirectlySharedWithPathSetTxn(const Transaction & txn, const Path & statePath)
{
PathSet statePaths;
@ -1812,31 +1812,51 @@ PathSet getSharedWithPathSetTxn(const Transaction & txn, const Path & statePath)
PathSet getSharedWithPathSetRecTxn_private(const Transaction & txn, const Path & statePath, PathSet & statePaths)
{
//Get all paths pointing to statePath
PathSet newStatePaths = getSharedWithPathSetTxn(txn, statePath);
PathSet newStatePaths = getDirectlySharedWithPathSetTxn(txn, statePath);
/*
printMsg(lvlError, format("getSharedWithPathSetRecTxn_private: '%1%'") % statePath);
for (PathSet::const_iterator j = newStatePaths.begin(); j != newStatePaths.end(); ++j)
printMsg(lvlError, format("newStatePaths '%1%'") % *j);
*/
//go into recursion to see if there are more paths indirectly pointing to statePath
for (PathSet::iterator i = newStatePaths.begin(); i != newStatePaths.end(); ++i)
for (PathSet::iterator i = newStatePaths.begin(); i != newStatePaths.end(); ++i){
//Only recurse on the really new statePaths to prevent infinite recursion
if(statePaths.find(*i) == statePaths.end())
statePaths = pathSets_union(statePaths, getSharedWithPathSetRecTxn_private(txn, *i, statePaths));
{
statePaths.insert(*i);
statePaths = pathSets_union(statePaths, getSharedWithPathSetRecTxn_private(txn, *i, statePaths)); //TODO !!!!!!!!!!!!!!!!!!!!!!
}
}
return statePaths;
}
//Note: Also returns statePath in the PathSet
PathSet getSharedWithPathSetRecTxn(const Transaction & txn, const Path & statePath)
{
//To no shared state path
Path statePath_ns = toNonSharedPathTxn(txn, statePath);
PathSet empty;
return getSharedWithPathSetRecTxn_private(txn, statePath_ns, empty);
//Also insert non-shared state path if it doenst equal statePath
PathSet statePaths;
if(statePath_ns != statePath)
statePaths.insert(statePath_ns);
//Make the call to get all shared with paths
PathSet result = getSharedWithPathSetRecTxn_private(txn, statePath_ns, statePaths);
//Remove yourself from the list eventually
result.erase(statePath);
return result;
}
void LocalStore::revertToRevision(const Path & componentPath, const Path & derivationPath, const Path & statePath, const unsigned int revision_arg, const bool recursive)
void LocalStore::revertToRevision(const Path & statePath, const unsigned int revision_arg, const bool recursive)
{
Transaction txn(nixDB);
revertToRevisionTxn(txn, componentPath, derivationPath, statePath, revision_arg, recursive);
revertToRevisionTxn(txn, statePath, revision_arg, recursive);
txn.commit();
}

View file

@ -112,7 +112,7 @@ public:
PathSet toNonSharedPathSet(const PathSet & statePaths);
void revertToRevision(const Path & componentPath, const Path & derivationPath, const Path & statePath, const unsigned int revision_arg, const bool recursive);
void revertToRevision(const Path & statePath, const unsigned int revision_arg, const bool recursive);
void setSharedState(const Path & fromExisting, const Path & toNew);
};
@ -243,6 +243,10 @@ bool querySolidStateReferencesTxn(const Transaction & txn, const Path & statePat
void setSharedStateTxn(const Transaction & txn, const Path & fromExisting, const Path & toNew);
PathSet toNonSharedPathSetTxn(const Transaction & txn, const PathSet & statePaths);
Path toNonSharedPathTxn(const Transaction & txn, const Path & statePath);
/*
* Returns a pathset with all paths (including itself) that eventually share the same statePath
*/
PathSet getSharedWithPathSetRecTxn(const Transaction & txn, const Path & statePath);
void ensurePathTxn(const Transaction & txn, const Path & path);

View file

@ -513,11 +513,9 @@ 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 unsigned int revision_arg, const bool recursive)
void RemoteStore::revertToRevision(const Path & statePath, const unsigned int revision_arg, const bool recursive)
{
writeInt(wopRevertToRevision, to);
writeString(componentPath, to);
writeString(derivationPath, to);
writeString(statePath, to);
writeBigUnsignedInt(revision_arg, to);
writeInt(recursive ? 1 : 0, to);

View file

@ -98,7 +98,7 @@ public:
PathSet toNonSharedPathSet(const PathSet & statePaths);
void revertToRevision(const Path & componentPath, const Path & derivationPath, const Path & statePath, const unsigned int revision_arg, const bool recursive);
void revertToRevision(const Path & statePath, const unsigned int revision_arg, const bool recursive);
void setSharedState(const Path & fromExisting, const Path & toNew);

View file

@ -241,7 +241,7 @@ public:
virtual PathSet toNonSharedPathSet(const PathSet & statePaths) = 0;
/* TODO */
virtual void revertToRevision(const Path & componentPath, const Path & derivationPath, const Path & statePath, const unsigned int revision_arg, const bool recursive) = 0;
virtual void revertToRevision(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

@ -93,14 +93,10 @@ PathSet getAllStateDerivationsRecursivelyTxn(const Transaction & txn, const Path
void revertToRevisionTxn(const Transaction & txn, const Path & componentPath, const Path & derivationPath, const Path & statePath, const int revision_arg, const bool recursive)
void revertToRevisionTxn(const Transaction & txn, const Path & statePath, const int revision_arg, const bool recursive)
{
PathSet statePaths;
if(recursive)
PathSet statePaths = getAllStateDerivationsRecursivelyTxn(txn, componentPath, revision_arg); //get dependecies (if neccecary | recusively) of all state components that need to be updated
else
statePaths.insert(derivationPath); //Insert direct state path
//Unshare the path
Path statePath_ns = toNonSharedPathTxn(txn, statePath);
//get a new timestamp for the references update
unsigned int newTimestamp = getTimeStamp();
@ -108,7 +104,7 @@ void revertToRevisionTxn(const Transaction & txn, const Path & componentPath, co
//Get the revisions recursively to also roll them back
RevisionClosure getRivisions;
RevisionClosureTS getTimestamps;
queryStateRevisionsTxn(txn, statePath, getRivisions, getTimestamps, revision_arg);
queryStateRevisionsTxn(txn, statePath_ns, getRivisions, getTimestamps, revision_arg);
//Revert each statePath in the list
for (RevisionClosure::iterator i = getRivisions.begin(); i != getRivisions.end(); ++i){

View file

@ -25,7 +25,7 @@ void scanAndUpdateAllReferencesTxn(const Transaction & txn, const Path & statePa
void scanAndUpdateAllReferencesRecusivelyTxn(const Transaction & txn, const Path & statePath);
void revertToRevisionTxn(const Transaction & txn, const Path & componentPath, const Path & derivationPath, const Path & statePath, const int revision_arg, const bool recursive);
void revertToRevisionTxn(const Transaction & txn, const Path & statePath, const int revision_arg, const bool recursive);
}

View file

@ -177,7 +177,7 @@ static void revertToRevision(Strings opFlags, Strings opArgs)
bool recursive = revert_recursively;
store->revertToRevision(componentPath, derivationPath, statePath, revision_arg, recursive);
store->revertToRevision(statePath, revision_arg, recursive);
}
@ -486,8 +486,23 @@ void run(Strings args)
RevisionClosureTS timestamps;
bool b = store->queryStateRevisions("/nix/state/aacs4qpi9jzg4vmhj09d0ichframh22x-hellohardcodedstateworld-1.0-test", revisions, timestamps, 0);
return;
*/
store = openStore();
/*
PathSet sharedWith = getSharedWithPathSetRecTxn(noTxn, "/nix/state/1kjxymaxf0i6qp5k8ggacc06bzbi4b82-hellohardcodedstateworld-1.0-test");
for (PathSet::const_iterator j = sharedWith.begin(); j != sharedWith.end(); ++j)
printMsg(lvlError, format("RootSP SW '%1%'") % *j);
printMsg(lvlError, format("------------"));
sharedWith = getSharedWithPathSetRecTxn(noTxn, "/nix/state/7c9azkk6qfk18hsvw4a5d8vk1p6qryk0-hellohardcodedstateworld-1.0-test");
for (PathSet::const_iterator j = sharedWith.begin(); j != sharedWith.end(); ++j)
printMsg(lvlError, format("RootSP SW '%1%'") % *j);
return;
*/
/* test */
for (Strings::iterator i = args.begin(); i != args.end(); ) {

View file

@ -579,13 +579,11 @@ static void performOp(Source & from, Sink & to, unsigned int op)
}
case wopRevertToRevision: {
Path componentPath = readString(from);
Path derivationPath = readString(from);
Path statePath = readString(from);
unsigned int revision_arg = readBigUnsignedInt(from);
bool recursive = readInt(from) == 1;
startWork();
store->revertToRevision(componentPath, derivationPath, statePath, revision_arg, recursive);
store->revertToRevision(statePath, revision_arg, recursive);
stopWork();
writeInt(1, to);
break;