diff --git a/src/libstore/store-state.cc b/src/libstore/store-state.cc index 778367693..0e29a29de 100644 --- a/src/libstore/store-state.cc +++ b/src/libstore/store-state.cc @@ -39,7 +39,12 @@ void createStateDirs(const DerivationStateOutputDirs & stateOutputDirs, const De //Make sure the 'root' path which holds the repositorys exists, so svn doenst complain. string repos_root_path = getStateReposRootPath("stateOutput:staterepospath", stateDir, drvName, stateIdentifier); - executeAndPrintShellCommand("mkdir -p " + repos_root_path, "mkdir", true); + + Strings p_args; + p_args.push_back("-p"); + p_args.push_back(repos_root_path); + runProgram_AndPrintOutput("mkdir", true, p_args, "mkdir"); + //TODO check if we can create state and staterepos dirs @@ -52,7 +57,10 @@ void createStateDirs(const DerivationStateOutputDirs & stateOutputDirs, const De //Check if and how this dir needs to be versioned if(d.type == "none"){ - executeAndPrintShellCommand("mkdir -p " + fullstatedir, "mkdir", true); + Strings p_args; + p_args.push_back("-p"); + p_args.push_back(fullstatedir); + runProgram_AndPrintOutput("mkdir", true, p_args, "mkdir"); continue; } @@ -62,8 +70,12 @@ void createStateDirs(const DerivationStateOutputDirs & stateOutputDirs, const De if(IsDirectory(repos)) printMsg(lvlTalkative, format("Repos %1% already exists, so we use that repository") % repos); - else - executeAndPrintShellCommand(svnadminbin + " create " + repos, "svnadmin", true); //TODO create as nixbld.nixbld chmod 700... can you still commit then ?? + else{ + Strings p_args; + p_args.push_back("create"); + p_args.push_back(repos); + runProgram_AndPrintOutput(svnadminbin, true, p_args, "svnadmin"); //TODO create as nixbld.nixbld chmod 700... can you still commit then ?? + } if(d.type == "interval"){ intervalPaths.insert(statePath); @@ -73,8 +85,11 @@ void createStateDirs(const DerivationStateOutputDirs & stateOutputDirs, const De string fullstatedir_svn = fullstatedir + "/.svn/"; if( ! IsDirectory(fullstatedir_svn) ){ - string checkoutcommand = svnbin + " checkout file://" + repos + " " + fullstatedir; - executeAndPrintShellCommand(checkoutcommand, "svn", true); //TODO checkout as user + Strings p_args; + p_args.push_back("checkout"); + p_args.push_back("file://" + repos); + p_args.push_back(fullstatedir); + runProgram_AndPrintOutput(svnbin, true, p_args, "svn"); //TODO checkout as user } else printMsg(lvlTalkative, format("Statedir %1% already exists, so dont check out its repository again") % fullstatedir_svn); diff --git a/src/libstore/store-state.hh b/src/libstore/store-state.hh index a2d7b6810..98c47798b 100644 --- a/src/libstore/store-state.hh +++ b/src/libstore/store-state.hh @@ -8,9 +8,6 @@ namespace nix { /* Create a state directory. */ void createStateDirs(const DerivationStateOutputDirs & stateOutputDirs, const DerivationStateOutputs & stateOutputs, const StringPairs & env); -/* Create and prints the output prefixed with '[commandName]:' via print(lvlError,... of a shell command. */ -void executeAndPrintShellCommand(const string & command, const string & commandName); - } #endif /* !__STORESTATE_H */ diff --git a/src/libutil/util.cc b/src/libutil/util.cc index 39476c90a..5e5b79b7c 100644 --- a/src/libutil/util.cc +++ b/src/libutil/util.cc @@ -1069,43 +1069,26 @@ string trim(const string & s) { */ -string runProgram_AndPrintOutput(Path program, bool searchPath, const Strings & args, const string outputPrefix) +void runProgram_AndPrintOutput(Path program, bool searchPath, const Strings & args, const string outputPrefix) { - string program_output = runProgram(program, true, args); + string program_output = runProgram(program, searchPath, args); //Add the prefix on every line //TODO - + + Strings lines = tokenizeString(program_output, "\n"); + for (Strings::const_iterator i = lines.begin(); i != lines.end(); ++i){ + if(trim(*i) != "") + printMsg(lvlError, format("[%2%]- %1%") % *i % outputPrefix); + } + //Remove the trailing \n - size_t found = program_output.find_last_of("\n"); - printMsg(lvlError, format("%1%") % program_output.substr(0,found)); + //size_t found = program_output.find_last_of("\n"); + //printMsg(lvlError, format("%1%") % program_output.substr(0,found)); } -void executeAndPrintShellCommand(const string & command, const string & commandName, const bool & captureOutput) +void executeShellCommand(const string & command) { - /////////////////////// - - 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 newcommand = command; - - if(captureOutput) - newcommand += " &> " + tempoutput; //the &> sends also stderr to stdout - int kidstatus, deadpid; pid_t kidpid = fork(); switch (kidpid) { @@ -1113,36 +1096,17 @@ void executeAndPrintShellCommand(const string & command, const string & commandN throw SysError("unable to fork"); case 0: try { // child - int rv = system(newcommand.c_str()); + int rv = system(command.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(captureOutput){ - 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("executeAndPrintShellCommand(..) error"); - quickExit(1); - } - } - if (rv == -1) { - throw SysError("executeAndPrintShellCommand(..) error"); + throw SysError("executeShellCommand(..) error"); quickExit(99); } quickExit(0); } catch (std::exception & e) { - std::cerr << format("executeAndPrintShellCommand(..) child error: %1%\n") % e.what(); + std::cerr << format("executeShellCommand(..) child error: %1%\n") % e.what(); quickExit(1); } } @@ -1152,9 +1116,6 @@ void executeAndPrintShellCommand(const string & command, const string & commandN std::cerr << format("state child waitpid error\n"); quickExit(1); } - - if(captureOutput) - remove(tempoutput.c_str()); //Remove the tempoutput file } string time_t2string(const time_t & t) diff --git a/src/libutil/util.hh b/src/libutil/util.hh index 1aa627942..b1beee356 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -268,7 +268,7 @@ Strings unpackStrings(const string & s); Strings tokenizeString(const string & s, const string & separators = " \t\n\r"); /* String tokenizer for commandline agruments. */ -Strings tokenizeStringWithQuotes(const string & s); +//Strings tokenizeStringWithQuotes(const string & s); //TODO maybe remove the function /* Convert the exit status of a child as returned by wait() into an error string. */ @@ -293,10 +293,10 @@ string trimr(const string & s); string trim(const string & s); //excecute a shell command -void executeAndPrintShellCommand(const string & command, const string & commandName, const bool & captureOutput); +void executeShellCommand(const string & command); // -string runProgram_AndPrintOutput(Path program, bool searchPath, const Strings & args, const string outputPrefix); +void runProgram_AndPrintOutput(Path program, bool searchPath, const Strings & args, const string outputPrefix); //Convert time_t to a string string time_t2string(const time_t & t); diff --git a/src/nix-state/nix-state.cc b/src/nix-state/nix-state.cc index d87f15011..e9a1ecf0e 100644 --- a/src/nix-state/nix-state.cc +++ b/src/nix-state/nix-state.cc @@ -213,7 +213,7 @@ static void opRunComponent(Strings opFlags, Strings opArgs) //******************* Run **************************** - executeAndPrintShellCommand(componentPath + binary, "", false); //more efficient way needed ??? + executeShellCommand(componentPath + binary); //more efficient way needed ??? //******************* With everything in place, we call the commit script on all statePaths ********************** @@ -317,12 +317,13 @@ static void opRunComponent(Strings opFlags, Strings opArgs) } //make the call - executeAndPrintShellCommand(nixLibexecDir + "/nix/nix-statecommit.sh " + svnbin + - " \"" + subversionedstatepathsarray + "\" " + - " \"" + subversionedpathsCommitBooleansarray + "\" " + - " \"" + nonversionedstatepathsarray + "\" " + - " \"" + commandsarray + "\" ", - "commit-script", true); + Strings p_args; + p_args.push_back(svnbin); + p_args.push_back(subversionedstatepathsarray); + p_args.push_back(subversionedpathsCommitBooleansarray); + p_args.push_back(nonversionedstatepathsarray); + p_args.push_back(commandsarray); + runProgram_AndPrintOutput(nixLibexecDir + "/nix/nix-statecommit.sh", true, p_args, "svn"); //TODO //Scan again??