diff options
author | 2011-09-04 00:09:15 +0100 | |
---|---|---|
committer | 2011-09-04 00:09:15 +0100 | |
commit | 8fe5ce1d7211b98fbec2de757301195c61c4daf8 (patch) | |
tree | 0c6b2dae36d480ea6a053f54aa417614df4bde62 | |
parent | 989e826f9820e73fa2a7c3e6254eb38bbcbe9dac (diff) | |
download | paludis-8fe5ce1d7211b98fbec2de757301195c61c4daf8.tar.gz paludis-8fe5ce1d7211b98fbec2de757301195c61c4daf8.tar.xz |
Process::extra_newlines_if_any_output_exists
-rw-r--r-- | paludis/util/process.cc | 36 | ||||
-rw-r--r-- | paludis/util/process.hh | 1 |
2 files changed, 37 insertions, 0 deletions
diff --git a/paludis/util/process.cc b/paludis/util/process.cc index 4e8e7fc06..bf256fe57 100644 --- a/paludis/util/process.cc +++ b/paludis/util/process.cc @@ -178,6 +178,8 @@ namespace paludis std::unique_ptr<Channel> capture_stderr_pipe; std::string prefix_stderr_buffer; + bool extra_newlines_if_any_output_exists; + std::ostream * capture_output_to_fd; std::unique_ptr<Pipe> capture_output_to_fd_pipe; @@ -214,6 +216,7 @@ void RunningProcessThread::thread_func() { bool prefix_stdout_buffer_has_newline(false), prefix_stderr_buffer_has_newline(false), want_to_finish(true); + bool done_extra_newlines_stdout(false), done_extra_newlines_stderr(false); std::string input_stream_pending; if (as_main_process && send_input_to_fd) @@ -398,6 +401,13 @@ RunningProcessThread::thread_func() if (std::string::npos == p) break; + if (extra_newlines_if_any_output_exists) + { + if (! done_extra_newlines_stdout) + capture_stdout->write("\n", 1); + done_extra_newlines_stdout = true; + } + capture_stdout->write(prefix_stdout.data(), prefix_stdout.length()); capture_stdout->write(prefix_stdout_buffer.data(), p + 1); prefix_stdout_buffer.erase(0, p + 1); @@ -414,6 +424,13 @@ RunningProcessThread::thread_func() if (std::string::npos == p) break; + if (extra_newlines_if_any_output_exists) + { + if (! done_extra_newlines_stderr) + capture_stderr->write("\n", 1); + done_extra_newlines_stderr = true; + } + capture_stderr->write(prefix_stderr.data(), prefix_stderr.length()); capture_stderr->write(prefix_stderr_buffer.data(), p + 1); prefix_stderr_buffer.erase(0, p + 1); @@ -451,6 +468,14 @@ RunningProcessThread::thread_func() done = true; } } + + if (extra_newlines_if_any_output_exists) + { + if (done_extra_newlines_stdout) + capture_stdout->write("\n", 1); + if (done_extra_newlines_stderr) + capture_stderr->write("\n", 1); + } } void @@ -489,6 +514,7 @@ namespace paludis std::string prefix_stdout; std::string prefix_stderr; + bool extra_newlines_if_any_output_exists; bool as_main_process; @@ -507,6 +533,7 @@ namespace paludis setuid(getuid()), setgid(getgid()), echo_command_to(0), + extra_newlines_if_any_output_exists(false), as_main_process(false) { } @@ -554,6 +581,8 @@ Process::run() } } + thread->extra_newlines_if_any_output_exists = _imp->extra_newlines_if_any_output_exists; + if (_imp->capture_stdout) { thread->capture_stdout = _imp->capture_stdout; @@ -893,6 +922,13 @@ Process::prefix_stderr(const std::string & s) } Process & +Process::extra_newlines_if_any_output_exists() +{ + _imp->extra_newlines_if_any_output_exists = true; + return *this; +} + +Process & Process::as_main_process() { _imp->as_main_process = true; diff --git a/paludis/util/process.hh b/paludis/util/process.hh index 564c0d5aa..40f1fb0f9 100644 --- a/paludis/util/process.hh +++ b/paludis/util/process.hh @@ -107,6 +107,7 @@ namespace paludis Process & prefix_stdout(const std::string &); Process & prefix_stderr(const std::string &); + Process & extra_newlines_if_any_output_exists(); Process & sandbox(); Process & sydbox(); |