mirror of
https://github.com/NixOS/nix.git
synced 2025-11-26 04:00:59 +01:00
merged executeAndPrintShellCommand to runProgram
This commit is contained in:
parent
729933062b
commit
b9fe3f00c1
5 changed files with 47 additions and 73 deletions
|
|
@ -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.
|
//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", 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
|
//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
|
//Check if and how this dir needs to be versioned
|
||||||
if(d.type == "none"){
|
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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -62,8 +70,12 @@ 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", true); //TODO create as nixbld.nixbld chmod 700... can you still commit then ??
|
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"){
|
if(d.type == "interval"){
|
||||||
intervalPaths.insert(statePath);
|
intervalPaths.insert(statePath);
|
||||||
|
|
@ -73,8 +85,11 @@ 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;
|
Strings p_args;
|
||||||
executeAndPrintShellCommand(checkoutcommand, "svn", true); //TODO checkout as user
|
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
|
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);
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,6 @@ namespace nix {
|
||||||
/* Create a state directory. */
|
/* Create a state directory. */
|
||||||
void createStateDirs(const DerivationStateOutputDirs & stateOutputDirs, const DerivationStateOutputs & stateOutputs, const StringPairs & env);
|
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 */
|
#endif /* !__STORESTATE_H */
|
||||||
|
|
|
||||||
|
|
@ -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
|
//Add the prefix on every line
|
||||||
//TODO
|
//TODO
|
||||||
|
|
||||||
//Remove the trailing \n
|
Strings lines = tokenizeString(program_output, "\n");
|
||||||
size_t found = program_output.find_last_of("\n");
|
for (Strings::const_iterator i = lines.begin(); i != lines.end(); ++i){
|
||||||
printMsg(lvlError, format("%1%") % program_output.substr(0,found));
|
if(trim(*i) != "")
|
||||||
}
|
printMsg(lvlError, format("[%2%]- %1%") % *i % outputPrefix);
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/////////////////////
|
//Remove the trailing \n
|
||||||
|
//size_t found = program_output.find_last_of("\n");
|
||||||
string tempoutput = "/tmp/svnoutput.txt";
|
//printMsg(lvlError, format("%1%") % program_output.substr(0,found));
|
||||||
string newcommand = command;
|
}
|
||||||
|
|
||||||
if(captureOutput)
|
|
||||||
newcommand += " &> " + tempoutput; //the &> sends also stderr to stdout
|
|
||||||
|
|
||||||
|
void executeShellCommand(const string & command)
|
||||||
|
{
|
||||||
int kidstatus, deadpid;
|
int kidstatus, deadpid;
|
||||||
pid_t kidpid = fork();
|
pid_t kidpid = fork();
|
||||||
switch (kidpid) {
|
switch (kidpid) {
|
||||||
|
|
@ -1113,36 +1096,17 @@ void executeAndPrintShellCommand(const string & command, const string & commandN
|
||||||
throw SysError("unable to fork");
|
throw SysError("unable to fork");
|
||||||
case 0:
|
case 0:
|
||||||
try { // child
|
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 ... ?
|
//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) {
|
if (rv == -1) {
|
||||||
throw SysError("executeAndPrintShellCommand(..) error");
|
throw SysError("executeShellCommand(..) error");
|
||||||
quickExit(99);
|
quickExit(99);
|
||||||
}
|
}
|
||||||
quickExit(0);
|
quickExit(0);
|
||||||
|
|
||||||
} catch (std::exception & e) {
|
} 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);
|
quickExit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1152,9 +1116,6 @@ void executeAndPrintShellCommand(const string & command, const string & commandN
|
||||||
std::cerr << format("state child waitpid error\n");
|
std::cerr << format("state child waitpid error\n");
|
||||||
quickExit(1);
|
quickExit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(captureOutput)
|
|
||||||
remove(tempoutput.c_str()); //Remove the tempoutput file
|
|
||||||
}
|
}
|
||||||
|
|
||||||
string time_t2string(const time_t & t)
|
string time_t2string(const time_t & t)
|
||||||
|
|
|
||||||
|
|
@ -268,7 +268,7 @@ Strings unpackStrings(const string & s);
|
||||||
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. */
|
/* 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
|
/* Convert the exit status of a child as returned by wait() into an
|
||||||
error string. */
|
error string. */
|
||||||
|
|
@ -293,10 +293,10 @@ 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, 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
|
//Convert time_t to a string
|
||||||
string time_t2string(const time_t & t);
|
string time_t2string(const time_t & t);
|
||||||
|
|
|
||||||
|
|
@ -213,7 +213,7 @@ static void opRunComponent(Strings opFlags, Strings opArgs)
|
||||||
|
|
||||||
//******************* Run ****************************
|
//******************* 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 **********************
|
//******************* 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
|
//make the call
|
||||||
executeAndPrintShellCommand(nixLibexecDir + "/nix/nix-statecommit.sh " + svnbin +
|
Strings p_args;
|
||||||
" \"" + subversionedstatepathsarray + "\" " +
|
p_args.push_back(svnbin);
|
||||||
" \"" + subversionedpathsCommitBooleansarray + "\" " +
|
p_args.push_back(subversionedstatepathsarray);
|
||||||
" \"" + nonversionedstatepathsarray + "\" " +
|
p_args.push_back(subversionedpathsCommitBooleansarray);
|
||||||
" \"" + commandsarray + "\" ",
|
p_args.push_back(nonversionedstatepathsarray);
|
||||||
"commit-script", true);
|
p_args.push_back(commandsarray);
|
||||||
|
runProgram_AndPrintOutput(nixLibexecDir + "/nix/nix-statecommit.sh", true, p_args, "svn");
|
||||||
|
|
||||||
//TODO
|
//TODO
|
||||||
//Scan again??
|
//Scan again??
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue