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

Fixed revert issue

This commit is contained in:
Wouter den Breejen 2007-07-26 11:39:55 +00:00
parent 0fc5accd86
commit 856251df03
3 changed files with 17 additions and 16 deletions

View file

@ -22,15 +22,13 @@ namespace nix {
void updatedStateDerivation(Path storePath)
{
//We dont remove the old .svn folders
//nothing to do since New repostorys are created by createStateDirs
printMsg(lvlTalkative, format("Resetting state drv settings like repositorys"));
//update in database?
printMsg(lvlTalkative, format("Resetting state drv settings"));
}
void createStateDirs(const DerivationStateOutputDirs & stateOutputDirs, const DerivationStateOutputs & stateOutputs)
{
Path statePath = stateOutputs.find("state")->second.statepath;
string stateDir = statePath;
@ -51,7 +49,7 @@ void createStateDirs(const DerivationStateOutputDirs & stateOutputDirs, const De
string thisdir = d.path;
//Check if it is a file
//If it is a file: continue
if(thisdir.substr(thisdir.length() -1 , thisdir.length()) != "/")
continue;
@ -127,12 +125,10 @@ Snapshots commitStatePathTxn(const Transaction & txn, const Path & statePath)
throw Error(format("Type '%1%' is not handled in nix-state") % d.type);
//We got here so we need to commit
unsigned int revision_number;
if(pathExists(fullstatedir) || FileExist(fullstatedir)){
revision_number = take_snapshot(fullstatedir);
printMsg(lvlError, format("Snapshotted '%1%' with id '%2%'") % fullstatedir % revision_number);
printMsg(lvlError, format("Snapshotted '%1%@%2%'") % fullstatedir % revision_number);
}
else
revision_number = 0; //deleted, so we assign 0 to indicate that

View file

@ -277,7 +277,8 @@ static void revertToRevision(Strings opFlags, Strings opArgs)
p_args.push_back("-c"); //we use the shell to execute the cp command becuase the shell expands the '*'
string cpcommand = "cp -R";
if(revertPathOrFile.substr(revertPathOrFile.length() -1 , revertPathOrFile.length()) == "/"){ //is dir
cpcommand += " " + (revertPathOrFile.substr(0, revertPathOrFile.length() -1) + "@" + unsignedInt2String(epoch) + "/*");
string revert_to_path = revertPathOrFile.substr(0, revertPathOrFile.length() -1) + "@" + unsignedInt2String(epoch);
cpcommand += " " + revert_to_path + "/*";
//clean all contents of the folder first (so were sure the path is clean)
if(pathExists(revertPathOrFile))
@ -288,6 +289,14 @@ static void revertToRevision(Strings opFlags, Strings opArgs)
continue;
else
ensureDirExists(revertPathOrFile);
//If the the dir has not contents then a cp ..../* will error since * cannot be expanded. So in this case were done and dont have to revert.
Strings p2_args;
p2_args.push_back("-A");
p2_args.push_back(revert_to_path + "/");
string output = runProgram("ls", true, p2_args);
if(output == "")
continue;
}
else{ //is file
cpcommand += " " + (revertPathOrFile + "@" + unsignedInt2String(epoch));
@ -300,14 +309,10 @@ static void revertToRevision(Strings opFlags, Strings opArgs)
}
}
//Revert
printMsg(lvlError, format("Reverting '%1%'") % revertPathOrFile);
cpcommand += " " + revertPathOrFile;
p_args.push_back(cpcommand);
//for (Strings::iterator h = p_args.begin(); h != p_args.end(); ++h)
// printMsg(lvlError, format("SH ARGS '%1%'") % *h);
runProgram_AndPrintOutput("sh", true, p_args, "sh-cp"); //TODO does this work on windows?
}