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

the command /nixstate/nix/bin/nix-state --run /nix/store/sig2qgvaayydrwy5hn6b2dm5r2ayhv5s-hellohardcodedstateworld-1.0 now causes state to be checked and comitted

This commit is contained in:
Wouter den Breejen 2007-05-30 17:16:25 +00:00
parent 653e557e81
commit 25117fd165
10 changed files with 378 additions and 202 deletions

View file

@ -42,7 +42,7 @@ struct DerivationStateOutput
string stateIdentifier; //the identifier
string enabled; //enable or disable state
string shared; //none, full, group
string synchronization; //none (no locks), exclusive-lock-on-own-state-dir, exclusive-lock-on-all-(sub)-states-dir
string synchronization; //none (no locks), exclusive-lock, recursive-exclusive-lock
string commitReferences; //TODO none, direct, recursive-all
string commitBinaries; //TODO list of binaries that need (or not) to be committed when these binaries are called
@ -54,6 +54,15 @@ struct DerivationStateOutput
}
DerivationStateOutput(Path statepath, string hashAlgo, string hash, string stateIdentifier, string enabled, string shared, string synchronization, string createDirsBeforeInstall, string runtimeStateParamters)
{
if(shared != "none" || shared != "full" || shared != "group")
throw Error(format("shared '%1%' is not a correct type") % shared);
if(synchronization != "none" || synchronization != "exclusive-lock" || synchronization != "recursive-exclusive-lock")
throw Error(format("synchronization '%1%' is not a correct type") % synchronization);
//TODO
//commitReferences
//commitBinaries
this->statepath = statepath;
this->hashAlgo = hashAlgo;
this->hash = hash;
@ -84,6 +93,9 @@ struct DerivationStateOutputDir
}
DerivationStateOutputDir(string path, string type, string interval)
{
if(type != "none" || type != "manual" || type != "interval" || type != "full")
throw Error(format("interval '%1%' is not a correct type") % type);
this->path = path;
this->type = type;
this->interval = interval;

View file

@ -1140,7 +1140,12 @@ vector<int> getStatePathsInterval(const PathSet & statePaths)
for (PathSet::iterator i = statePaths.begin(); i != statePaths.end(); ++i)
{
nixDB.queryString(txn, dbStateCounters, *i, data);
printMsg(lvlError, format("Data %1%") % data); //TODO
//TODO check if every key returns a value from the db
int n;
if (!string2Int(data, n)) throw Error("number expected");
intervals.push_back(n);
}
txn.commit();

View file

@ -67,56 +67,5 @@ void createStateDirs(const DerivationStateOutputDirs & stateOutputDirs, const De
store->setStatePathsInterval(intervalPaths, empty, true);
}
//executes a shell command and captures and prints the output.
void executeAndPrintShellCommand(const string & command, const string & commandName)
{
string tempoutput = "svnoutput.txt";
string newcommand = command + " > " + tempoutput;
int kidstatus, deadpid;
pid_t kidpid = fork();
switch (kidpid) {
case -1:
throw SysError("unable to fork");
case 0:
try { // child
int rv = system(newcommand.c_str());
//int rv = execlp(svnbin.c_str(), svnbin.c_str(), ">", tempoutput.c_str(), NULL); //TODO make this work ... ?
string line;
std::ifstream myfile (tempoutput.c_str());
if (myfile.is_open()){
while (! myfile.eof() )
{
getline (myfile,line);
if(trim(line) != "")
printMsg(lvlError, format("[%2%]: %1%") % line % commandName);
}
myfile.close();
}
else{
throw SysError("svn state error");
quickExit(1);
}
if (rv == -1) {
throw SysError("svn state error");
quickExit(99);
}
quickExit(0);
} catch (std::exception & e) {
std::cerr << format("state child error: %1%\n") % e.what();
quickExit(1);
}
}
deadpid = waitpid(kidpid, &kidstatus, 0);
if (deadpid == -1) {
std::cerr << format("state child waitpid error\n");
quickExit(1);
}
remove(tempoutput.c_str()); //Remove the tempoutput file
}
}