aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-02-12 23:35:55 +0000
committerAvatar Ciaran McCreesh <ciaran.mccreesh@googlemail.com> 2009-02-12 23:35:55 +0000
commit42dc8dd1f2e1f0bf33cbb0ea5dcac0ed20dfa083 (patch)
tree90099ce6371c20ef91db6f96f15e644a14ca1a2a
parentc97f6755a13ac7c8c9108d173d49399970b7dc79 (diff)
downloadpaludis-42dc8dd1f2e1f0bf33cbb0ea5dcac0ed20dfa083.tar.gz
paludis-42dc8dd1f2e1f0bf33cbb0ea5dcac0ed20dfa083.tar.xz
Add option to avoid keeping empty files
-rw-r--r--paludis/environments/paludis/output_managers/keep_stdout_as_messages.conf1
-rw-r--r--paludis/environments/paludis/output_managers/logged_only.conf2
-rw-r--r--paludis/file_output_manager.cc37
-rw-r--r--paludis/file_output_manager.hh3
4 files changed, 35 insertions, 8 deletions
diff --git a/paludis/environments/paludis/output_managers/keep_stdout_as_messages.conf b/paludis/environments/paludis/output_managers/keep_stdout_as_messages.conf
index 67a2787..9888709 100644
--- a/paludis/environments/paludis/output_managers/keep_stdout_as_messages.conf
+++ b/paludis/environments/paludis/output_managers/keep_stdout_as_messages.conf
@@ -4,4 +4,5 @@ handler = file
stdout = /var/log/paludis/%{time}-%{action}-%{id}.messages
stderr = ${stdout}
keep_on_success = true
+keep_on_empty = false
diff --git a/paludis/environments/paludis/output_managers/logged_only.conf b/paludis/environments/paludis/output_managers/logged_only.conf
index b8c8a0f..b41f5ab 100644
--- a/paludis/environments/paludis/output_managers/logged_only.conf
+++ b/paludis/environments/paludis/output_managers/logged_only.conf
@@ -5,3 +5,5 @@ handler = file
stdout = /var/log/paludis/%{time}-%{action}-%{id}.out
stderr = ${stdout}
keep_on_success = false
+keep_on_empty = true
+
diff --git a/paludis/file_output_manager.cc b/paludis/file_output_manager.cc
index 8b5aeb3..1dfe40d 100644
--- a/paludis/file_output_manager.cc
+++ b/paludis/file_output_manager.cc
@@ -25,6 +25,7 @@
#include <paludis/util/make_shared_ptr.hh>
#include <paludis/util/destringify.hh>
#include <paludis/util/fs_entry.hh>
+#include <paludis/util/stringify.hh>
using namespace paludis;
@@ -37,17 +38,19 @@ namespace paludis
FSEntry stderr_file;
std::tr1::shared_ptr<SafeOFStream> stdout_stream;
std::tr1::shared_ptr<SafeOFStream> stderr_stream;
- const bool keep_on_success;
+ const bool keep_on_success, keep_on_empty;
Implementation(
const FSEntry & o,
const FSEntry & e,
- const bool k
+ const bool k,
+ const bool l
) :
stdout_file(o),
stderr_file(e),
stdout_stream(new SafeOFStream(o)),
- keep_on_success(k)
+ keep_on_success(k),
+ keep_on_empty(l)
{
if (o == e)
stderr_stream = stdout_stream;
@@ -57,13 +60,28 @@ namespace paludis
};
}
-FileOutputManager::FileOutputManager(const FSEntry & o, const FSEntry & e, const bool k) :
- PrivateImplementationPattern<FileOutputManager>(new Implementation<FileOutputManager>(o, e, k))
+FileOutputManager::FileOutputManager(const FSEntry & o, const FSEntry & e, const bool k, const bool l) :
+ PrivateImplementationPattern<FileOutputManager>(new Implementation<FileOutputManager>(o, e, k, l))
{
}
FileOutputManager::~FileOutputManager()
{
+ if (! _imp->keep_on_empty)
+ {
+ *_imp->stdout_stream << std::flush;
+ *_imp->stderr_stream << std::flush;
+
+ FSEntry stdout_file_now(stringify(_imp->stdout_file)), stderr_file_now(stringify(_imp->stderr_file));
+ if (stdout_file_now.exists() && 0 == stdout_file_now.file_size())
+ _imp->stdout_file.unlink();
+
+ if (stdout_file_now != stderr_file_now)
+ {
+ if (stderr_file_now.exists() && 0 == stderr_file_now.file_size())
+ _imp->stderr_file.unlink();
+ }
+ }
}
std::ostream &
@@ -107,7 +125,8 @@ FileOutputManager::factory_create(
const OutputManagerFactory::CreateChildFunction &,
const OutputManagerFactory::ReplaceVarsFunc & replace_vars_func)
{
- std::string o_s(key_func("stdout")), e_s(key_func("stderr")), k_s(key_func("keep_on_success"));
+ std::string o_s(key_func("stdout")), e_s(key_func("stderr")), k_s(key_func("keep_on_success")),
+ l_s(key_func("keep_on_empty"));
if (o_s.empty())
throw ConfigurationError("Key 'stdout' not specified when creating a file output manager");
@@ -120,7 +139,11 @@ FileOutputManager::factory_create(
if (k_s.empty())
throw ConfigurationError("Key 'keep_on_success' not specified when creating a file output manager");
- return make_shared_ptr(new FileOutputManager(FSEntry(o_s), FSEntry(e_s), destringify<bool>(k_s)));
+ if (l_s.empty())
+ throw ConfigurationError("Key 'keep_on_empty' not specified when creating a file output manager");
+
+ return make_shared_ptr(new FileOutputManager(FSEntry(o_s), FSEntry(e_s), destringify<bool>(k_s),
+ destringify<bool>(l_s)));
}
template class PrivateImplementationPattern<FileOutputManager>;
diff --git a/paludis/file_output_manager.hh b/paludis/file_output_manager.hh
index e8ffa8c..fc6eea3 100644
--- a/paludis/file_output_manager.hh
+++ b/paludis/file_output_manager.hh
@@ -36,7 +36,8 @@ namespace paludis
public OutputManager
{
public:
- FileOutputManager(const FSEntry &, const FSEntry &, const bool keep_on_success);
+ FileOutputManager(const FSEntry &, const FSEntry &, const bool keep_on_success,
+ const bool keep_on_empty);
~FileOutputManager();
virtual std::ostream & stdout_stream() PALUDIS_ATTRIBUTE((warn_unused_result));