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

@ -1397,7 +1397,7 @@ void DerivationGoal::startBuilder()
/* 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())
createStateDirs(drv.stateOutputDirs, drv.stateOutputs); createStateDirs(drv.stateOutputDirs, drv.stateOutputs);
} }

View file

@ -22,15 +22,13 @@ namespace nix {
void updatedStateDerivation(Path storePath) void updatedStateDerivation(Path storePath)
{ {
//We dont remove the old .svn folders //We dont remove the old .svn folders
//nothing to do since New repostorys are created by createStateDirs //update in database?
printMsg(lvlTalkative, format("Resetting state drv settings like repositorys")); printMsg(lvlTalkative, format("Resetting state drv settings"));
} }
void createStateDirs(const DerivationStateOutputDirs & stateOutputDirs, const DerivationStateOutputs & stateOutputs) void createStateDirs(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;
@ -51,7 +49,7 @@ void createStateDirs(const DerivationStateOutputDirs & stateOutputDirs, const De
string thisdir = d.path; string thisdir = d.path;
//Check if it is a file //If it is a file: continue
if(thisdir.substr(thisdir.length() -1 , thisdir.length()) != "/") if(thisdir.substr(thisdir.length() -1 , thisdir.length()) != "/")
continue; 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); throw Error(format("Type '%1%' is not handled in nix-state") % d.type);
//We got here so we need to commit //We got here so we need to commit
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);
printMsg(lvlError, format("Snapshotted '%1%' with id '%2%'") % fullstatedir % revision_number); printMsg(lvlError, format("Snapshotted '%1%@%2%'") % fullstatedir % revision_number);
} }
else else
revision_number = 0; //deleted, so we assign 0 to indicate that 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 '*' p_args.push_back("-c"); //we use the shell to execute the cp command becuase the shell expands the '*'
string cpcommand = "cp -R"; string cpcommand = "cp -R";
if(revertPathOrFile.substr(revertPathOrFile.length() -1 , revertPathOrFile.length()) == "/"){ //is dir 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) //clean all contents of the folder first (so were sure the path is clean)
if(pathExists(revertPathOrFile)) if(pathExists(revertPathOrFile))
@ -288,6 +289,14 @@ static void revertToRevision(Strings opFlags, Strings opArgs)
continue; continue;
else else
ensureDirExists(revertPathOrFile); 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 else{ //is file
cpcommand += " " + (revertPathOrFile + "@" + unsignedInt2String(epoch)); cpcommand += " " + (revertPathOrFile + "@" + unsignedInt2String(epoch));
@ -299,15 +308,11 @@ static void revertToRevision(Strings opFlags, Strings opArgs)
continue; continue;
} }
} }
printMsg(lvlError, format("Reverting '%1%'") % revertPathOrFile);
//Revert
printMsg(lvlError, format("Reverting '%1%'") % revertPathOrFile);
cpcommand += " " + revertPathOrFile; cpcommand += " " + revertPathOrFile;
p_args.push_back(cpcommand); 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? runProgram_AndPrintOutput("sh", true, p_args, "sh-cp"); //TODO does this work on windows?
} }