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

before merging executeAndPrintShellCommand to runProgram

This commit is contained in:
Wouter den Breejen 2007-06-28 11:05:11 +00:00
parent 3d22bd50b3
commit 1c0b052243
6 changed files with 111 additions and 50 deletions

View file

@ -145,7 +145,7 @@ do
let "i_checkout+=1" let "i_checkout+=1"
done done
if ! test -d "${path}.svn/"; then #if the dir exists but is not yet an svn dir: checkout repos, if it doenst exits (is removed or something) than we dont do anything if ! test -d "${path}.svn/"; then #if the dir exists but is not yet an svn dir: checkout repos, if it doenst exits (is removed or something) than we dont do anything
if [ "$deletesvn" != "1" ]; then if [ "$deletesvn" != "1" ]; then
$debug $checkoutcommand; $debug $checkoutcommand;
fi fi

View file

@ -507,18 +507,16 @@ void LocalStore::queryStateReferrers(const Path & storePath, PathSet & stateRefe
void setDeriver(const Transaction & txn, const Path & storePath, const Path & deriver) void setDeriver(const Transaction & txn, const Path & storePath, const Path & deriver)
{ {
printMsg(lvlError, format("xxxxxxxxxxxxxxxxxxxxxxx"));
assertStorePath(storePath); assertStorePath(storePath);
printMsg(lvlError, format("Ttttttttttttttttttttttttt"));
if (deriver == "") return; if (deriver == "") return;
printMsg(lvlError, format("uuuuuuuuuuuuuuuuuuuuuuuuuuuuu"));
assertStorePath(deriver); assertStorePath(deriver);
printMsg(lvlError, format("yyyyyyyyyyyyyyyyyyyyyyyyy")); printMsg(lvlError, format("yyyyyyyyyyyyyyyyyyyyyyyyy")); //hanged !!!!!!!!
if (!isRealisablePath(txn, storePath)) if (!isRealisablePath(txn, storePath))
throw Error(format("path `%1%' is not valid") % storePath); throw Error(format("path `%1%' is not valid") % storePath);
printMsg(lvlError, format("Ttttttttttttttttttttttttt %1%") % deriver);
if (isStateDrvPathTxn(txn, deriver)){ //Redirect if its a state component if (isStateDrvPathTxn(txn, deriver)){ //Redirect if its a state component
printMsg(lvlError, format("bbbbbbbbbbbbbbb")); printMsg(lvlError, format("bbbbbbbbbbbbbbb"));
addStateDeriver(txn, storePath, deriver); addStateDeriver(txn, storePath, deriver);
@ -538,19 +536,13 @@ void addStateDeriver(const Transaction & txn, const Path & storePath, const Path
if (!isRealisablePath(txn, storePath)) if (!isRealisablePath(txn, storePath))
throw Error(format("path `%1%' is not valid") % storePath); throw Error(format("path `%1%' is not valid") % storePath);
printMsg(lvlError, format("dddddddddddddd"));
Derivation drv = derivationFromPath(deriver); Derivation drv = derivationFromPath(deriver);
string identifier = drv.stateOutputs.find("state")->second.stateIdentifier; string identifier = drv.stateOutputs.find("state")->second.stateIdentifier;
string user = drv.stateOutputs.find("state")->second.username; string user = drv.stateOutputs.find("state")->second.username;
printMsg(lvlError, format("eeeeeeeeeeeeeeeeee"));
PathSet currentDerivers = queryDerivers(txn, storePath, identifier, user); PathSet currentDerivers = queryDerivers(txn, storePath, identifier, user);
PathSet updatedDerivers = mergeNewDerivationIntoList(storePath, deriver, currentDerivers, true); PathSet updatedDerivers = mergeNewDerivationIntoList(storePath, deriver, currentDerivers, true);
printMsg(lvlError, format("ffffffffffffffffffff"));
Strings data; Strings data;
for (PathSet::iterator i = updatedDerivers.begin(); i != updatedDerivers.end(); ++i) //Convert Paths to Strings for (PathSet::iterator i = updatedDerivers.begin(); i != updatedDerivers.end(); ++i) //Convert Paths to Strings
data.push_back(*i); data.push_back(*i);

View file

@ -19,13 +19,10 @@ namespace nix {
void updatedStateDerivation(Path storePath) void updatedStateDerivation(Path storePath)
{ {
//We dont remove the old .svn folders //We dont remove the old .svn folders
//New repostorys are created by createStateDirs //nothing to do since New repostorys are created by createStateDirs
printMsg(lvlTalkative, format("Resetting state drv settings like repositorys")); printMsg(lvlTalkative, format("Resetting state drv settings like repositorys"));
//Create a repository for this state location
//
} }
void createStateDirs(const DerivationStateOutputDirs & stateOutputDirs, const DerivationStateOutputs & stateOutputs, const StringPairs & env) void createStateDirs(const DerivationStateOutputDirs & stateOutputDirs, const DerivationStateOutputs & stateOutputs, const StringPairs & env)
@ -42,7 +39,7 @@ void createStateDirs(const DerivationStateOutputDirs & stateOutputDirs, const De
//Make sure the 'root' path which holds the repositorys exists, so svn doenst complain. //Make sure the 'root' path which holds the repositorys exists, so svn doenst complain.
string repos_root_path = getStateReposRootPath("stateOutput:staterepospath", stateDir, drvName, stateIdentifier); string repos_root_path = getStateReposRootPath("stateOutput:staterepospath", stateDir, drvName, stateIdentifier);
executeAndPrintShellCommand("mkdir -p " + repos_root_path, "mkdir"); executeAndPrintShellCommand("mkdir -p " + repos_root_path, "mkdir", true);
//TODO check if we can create state and staterepos dirs //TODO check if we can create state and staterepos dirs
@ -55,7 +52,7 @@ void createStateDirs(const DerivationStateOutputDirs & stateOutputDirs, const De
//Check if and how this dir needs to be versioned //Check if and how this dir needs to be versioned
if(d.type == "none"){ if(d.type == "none"){
executeAndPrintShellCommand("mkdir -p " + fullstatedir, "mkdir"); executeAndPrintShellCommand("mkdir -p " + fullstatedir, "mkdir", true);
continue; continue;
} }
@ -66,7 +63,7 @@ void createStateDirs(const DerivationStateOutputDirs & stateOutputDirs, const De
if(IsDirectory(repos)) if(IsDirectory(repos))
printMsg(lvlTalkative, format("Repos %1% already exists, so we use that repository") % repos); printMsg(lvlTalkative, format("Repos %1% already exists, so we use that repository") % repos);
else else
executeAndPrintShellCommand(svnadminbin + " create " + repos, "svnadmin"); //TODO create as nixbld.nixbld chmod 700... can you still commit then ?? executeAndPrintShellCommand(svnadminbin + " create " + repos, "svnadmin", true); //TODO create as nixbld.nixbld chmod 700... can you still commit then ??
if(d.type == "interval"){ if(d.type == "interval"){
intervalPaths.insert(statePath); intervalPaths.insert(statePath);
@ -77,7 +74,7 @@ void createStateDirs(const DerivationStateOutputDirs & stateOutputDirs, const De
string fullstatedir_svn = fullstatedir + "/.svn/"; string fullstatedir_svn = fullstatedir + "/.svn/";
if( ! IsDirectory(fullstatedir_svn) ){ if( ! IsDirectory(fullstatedir_svn) ){
string checkoutcommand = svnbin + " checkout file://" + repos + " " + fullstatedir; string checkoutcommand = svnbin + " checkout file://" + repos + " " + fullstatedir;
executeAndPrintShellCommand(checkoutcommand, "svn"); //TODO checkout as user executeAndPrintShellCommand(checkoutcommand, "svn", true); //TODO checkout as user
} }
else else
printMsg(lvlTalkative, format("Statedir %1% already exists, so dont check out its repository again") % fullstatedir_svn); printMsg(lvlTalkative, format("Statedir %1% already exists, so dont check out its repository again") % fullstatedir_svn);

View file

@ -934,6 +934,47 @@ Strings tokenizeString(const string & s, const string & separators)
return result; return result;
} }
//Splits on a space
//Uses quotes: "...." to group multiple spaced arguments into one
//Removes the grouping quotes at the call
//TODO bug a call with args: a b "c" d will fail
//TODO bug a call with args: a bc"d " e will fail
Strings tokenizeStringWithQuotes(const string & s)
{
string separator = " ";
Strings result;
string::size_type pos = s.find_first_not_of(separator, 0);
string quote = "\"";
string inquotes = "";
while (pos != string::npos) {
string::size_type end = s.find_first_of(separator, pos + 1);
if (end == string::npos) end = s.size();
string token(s, pos, end - pos);
pos = s.find_first_not_of(separator, end);
//if first or last item is a quote, we switch inquotes
if(token.substr(0,1) == quote || token.substr(token.size()-1,token.size()) == quote){
if(inquotes == ""){ //begin
inquotes = token;
continue;
}
else{ //end
token = inquotes + token;
token = token.substr(1,token.size()-2); //remove the grouping quotes
inquotes = "";
}
}
if(inquotes != "") //middle
inquotes += separator + token;
else
result.push_back(token); //normal
}
return result;
}
string statusToString(int status) string statusToString(int status)
{ {
@ -1028,10 +1069,30 @@ string trim(const string & s) {
*/ */
void executeAndPrintShellCommand(const string & command, const string & commandName) void executeAndPrintShellCommand(const string & command, const string & commandName, const bool & captureOutput)
{ {
///////////////////////
if(captureOutput){
Strings progam_args = tokenizeStringWithQuotes(command);
string program_command = progam_args.front();
progam_args.pop_front();
string program_output = runProgram(program_command, true, progam_args);
//Remove the trailing \n
size_t found = program_output.find_last_of("\n");
printMsg(lvlError, format("%1%") % program_output.substr(0,found));
return;
}
/////////////////////
string tempoutput = "/tmp/svnoutput.txt"; string tempoutput = "/tmp/svnoutput.txt";
string newcommand = command + " &> " + tempoutput; //the &> sends also stderr to stdout string newcommand = command;
if(captureOutput)
newcommand += " &> " + tempoutput; //the &> sends also stderr to stdout
int kidstatus, deadpid; int kidstatus, deadpid;
pid_t kidpid = fork(); pid_t kidpid = fork();
@ -1045,38 +1106,43 @@ void executeAndPrintShellCommand(const string & command, const string & commandN
string line; string line;
std::ifstream myfile (tempoutput.c_str()); std::ifstream myfile (tempoutput.c_str());
if (myfile.is_open()){
while (! myfile.eof() ) if(captureOutput){
{ if (myfile.is_open()){
getline (myfile,line); while (! myfile.eof() )
if(trim(line) != "") {
printMsg(lvlError, format("[%2%]: %1%") % line % commandName); getline (myfile,line);
} if(trim(line) != "")
myfile.close(); printMsg(lvlError, format("[%2%]: %1%") % line % commandName);
} }
else{ myfile.close();
throw SysError("svn state error"); }
quickExit(1); else{
throw SysError("executeAndPrintShellCommand(..) error");
quickExit(1);
}
} }
if (rv == -1) { if (rv == -1) {
throw SysError("svn state error"); throw SysError("executeAndPrintShellCommand(..) error");
quickExit(99); quickExit(99);
} }
quickExit(0); quickExit(0);
} catch (std::exception & e) { } catch (std::exception & e) {
std::cerr << format("state child error: %1%\n") % e.what(); std::cerr << format("executeAndPrintShellCommand(..) child error: %1%\n") % e.what();
quickExit(1); quickExit(1);
} }
} }
deadpid = waitpid(kidpid, &kidstatus, 0); deadpid = waitpid(kidpid, &kidstatus, 0);
if (deadpid == -1) { if (deadpid == -1) {
std::cerr << format("state child waitpid error\n"); std::cerr << format("state child waitpid error\n");
quickExit(1); quickExit(1);
} }
remove(tempoutput.c_str()); //Remove the tempoutput file if(captureOutput)
remove(tempoutput.c_str()); //Remove the tempoutput file
} }
string time_t2string(const time_t & t) string time_t2string(const time_t & t)
@ -1121,7 +1187,7 @@ string getCallingUserName()
Strings empty; Strings empty;
string username = runProgram("whoami", true, empty); //the username of the user that is trying to build the component string username = runProgram("whoami", true, empty); //the username of the user that is trying to build the component
//TODO Can be faked, so this is clearly unsafe ... :( //TODO Can be faked, so this is clearly unsafe ... :(
//Remove the \n //Remove the trailing \n
int pos = username.find("\n",0); int pos = username.find("\n",0);
username.erase(pos,1); username.erase(pos,1);

View file

@ -267,6 +267,8 @@ Strings unpackStrings(const string & s);
/* String tokenizer. */ /* String tokenizer. */
Strings tokenizeString(const string & s, const string & separators = " \t\n\r"); Strings tokenizeString(const string & s, const string & separators = " \t\n\r");
/* String tokenizer for commandline agruments. */
Strings tokenizeStringWithQuotes(const string & s);
/* Convert the exit status of a child as returned by wait() into an /* Convert the exit status of a child as returned by wait() into an
error string. */ error string. */
@ -291,7 +293,7 @@ string trimr(const string & s);
string trim(const string & s); string trim(const string & s);
//excecute a shell command //excecute a shell command
void executeAndPrintShellCommand(const string & command, const string & commandName); void executeAndPrintShellCommand(const string & command, const string & commandName, const bool & captureOutput);
//Convert time_t to a string //Convert time_t to a string
string time_t2string(const time_t & t); string time_t2string(const time_t & t);

View file

@ -67,9 +67,7 @@ Derivation getDerivation_andCheckArgs_(Strings opFlags, Strings opArgs, Path & c
if(opArgs.size() > 1){ if(opArgs.size() > 1){
opArgs.pop_front(); opArgs.pop_front();
allargs = opArgs.front(); allargs = opArgs.front();
Strings progam_args = tokenizeString(allargs, " ");
Strings progam_args;
//TODO !!!!!!!!!!!!!!!!!!!!!!
} }
printMsg(lvlError, format("'%1%' - '%2%' - '%3%' - '%4%' - '%5%'") % componentPath % stateIdentifier % binary % username % allargs); printMsg(lvlError, format("'%1%' - '%2%' - '%3%' - '%4%' - '%5%'") % componentPath % stateIdentifier % binary % username % allargs);
@ -213,6 +211,10 @@ static void opRunComponent(Strings opFlags, Strings opArgs)
//createStoreTransaction(txn); //createStoreTransaction(txn);
//txn.commit(); //txn.commit();
//******************* Run ****************************
executeAndPrintShellCommand(componentPath + binary, "", false); //more efficient way needed ???
//******************* With everything in place, we call the commit script on all statePaths ********************** //******************* With everything in place, we call the commit script on all statePaths **********************
for (PathSet::iterator d = drvs.begin(); d != drvs.end(); ++d) for (PathSet::iterator d = drvs.begin(); d != drvs.end(); ++d)
@ -320,7 +322,10 @@ static void opRunComponent(Strings opFlags, Strings opArgs)
" \"" + subversionedpathsCommitBooleansarray + "\" " + " \"" + subversionedpathsCommitBooleansarray + "\" " +
" \"" + nonversionedstatepathsarray + "\" " + " \"" + nonversionedstatepathsarray + "\" " +
" \"" + commandsarray + "\" ", " \"" + commandsarray + "\" ",
"commit-script"); "commit-script", true);
//TODO
//Scan again??
} }
} }
@ -376,7 +381,7 @@ void run(Strings args)
Operation oldOp = op; Operation oldOp = op;
if (arg == "--commit" || arg == "-c") if (arg == "--run" || arg == "-r")
op = opRunComponent; op = opRunComponent;
else if (arg == "--showstatepath") else if (arg == "--showstatepath")
op = opShowStatePath; op = opShowStatePath;
@ -386,6 +391,7 @@ void run(Strings args)
op = opShowDerivations; op = opShowDerivations;
/* /*
--commit --commit
--run-without-commit --run-without-commit
@ -418,8 +424,6 @@ void run(Strings args)
if(username == "") if(username == "")
username = getCallingUserName(); username = getCallingUserName();
printMsg(lvlError, format("%1% - %2%") % stateIdentifier % username);
if (!op) throw UsageError("no operation specified"); if (!op) throw UsageError("no operation specified");
/* !!! hack */ /* !!! hack */