ref: refs/heads/ma-misc commit 15972404fc06b593790455b069eb7b0a0c7913e6 Author: Michael Andres <ma@suse.de> Date: Tue Jul 7 17:43:03 2009 +0200 Prevent HistoryLog from accessing ZConfig when initializing its static vars. --- zypp/HistoryLog.cc | 87 +++++++++++++++++++++++++++------------------------ zypp/HistoryLog.h | 21 ++---------- 2 files changed, 50 insertions(+), 58 deletions(-) diff --git a/zypp/HistoryLog.cc b/zypp/HistoryLog.cc index 1c8218f..8ff44d6 100644 --- a/zypp/HistoryLog.cc +++ b/zypp/HistoryLog.cc @@ -68,69 +68,71 @@ namespace namespace zypp { - - - /////////////////////////////////////////////////////////////////// - // - // CLASS NAME : HistoryLog - // - /////////////////////////////////////////////////////////////////// - - Pathname HistoryLog::_fname(ZConfig::instance().historyLogFile()); - std::ofstream HistoryLog::_log; - unsigned HistoryLog::_refcnt = 0; - const char HistoryLog::_sep = '|'; - - /////////////////////////////////////////////////////////////////// - - HistoryLog::HistoryLog( const Pathname & rootdir ) + namespace { - refUp(); - if (!rootdir.empty() && rootdir.absolute()) - _fname = rootdir / ZConfig::instance().historyLogFile(); - } + const char _sep = '|'; + std::ofstream _log; + unsigned _refcnt = 0; + Pathname _fname; - void HistoryLog::openLog() - { - if ( !_fname.empty() ) + inline void openLog() { + if ( _fname.empty() ) + _fname = ZConfig::instance().historyLogFile(); + _log.clear(); _log.open( _fname.asString().c_str(), std::ios::out|std::ios::app ); if( !_log ) ERR << "Could not open logfile '" << _fname << "'" << endl; } - } - void HistoryLog::closeLog() - { - _log.clear(); - _log.close(); + inline void closeLog() + { + _log.clear(); + _log.close(); + } + + inline void refUp() + { + if ( !_refcnt ) + openLog(); + ++_refcnt; + } + + inline void refDown() + { + --_refcnt; + if ( !_refcnt ) + closeLog(); + } } - void HistoryLog::refUp() + /////////////////////////////////////////////////////////////////// + // + // CLASS NAME : HistoryLog + // + /////////////////////////////////////////////////////////////////// + + HistoryLog::HistoryLog( const Pathname & rootdir ) { - if ( !_refcnt ) - openLog(); - ++_refcnt; + setRoot( rootdir ); + refUp(); } - void HistoryLog::refDown() + HistoryLog::~HistoryLog() { - --_refcnt; - if ( !_refcnt ) - closeLog(); + refDown(); } - void HistoryLog::setRoot( const Pathname & rootdir ) { - if (rootdir.empty() || !rootdir.absolute()) + if ( ! rootdir.absolute() ) return; if ( _refcnt ) closeLog(); - _fname = rootdir / "/var/log/zypp/history"; + _fname = rootdir / ZConfig::instance().historyLogFile(); filesystem::assert_dir( _fname.dirname() ); MIL << "installation log file " << _fname << endl; @@ -138,9 +140,12 @@ namespace zypp openLog(); } - const Pathname & HistoryLog::fname() - { return _fname; } + { + if ( _fname.empty() ) + _fname = ZConfig::instance().historyLogFile(); + return _fname; + } ///////////////////////////////////////////////////////////////////////// diff --git a/zypp/HistoryLog.h b/zypp/HistoryLog.h index da8e88c..e2c0152 100644 --- a/zypp/HistoryLog.h +++ b/zypp/HistoryLog.h @@ -52,26 +52,14 @@ namespace zypp * * \see http://en.opensuse.org/Libzypp/Package_History * - * \todo Static private stuff does not need to be mentioned here in the - * header (use an annon. namespace in the .cc). Appart from that the - * implementation as signleton is questionable. Use shared_ptr instead of - * handcrafted ref/unref. Manage multiple logs at different locations. + * \todo The implementation as pseudo signleton is questionable. + * Use shared_ptr instead of handcrafted ref/unref. Manage multiple + * logs at different locations. */ class HistoryLog { HistoryLog( const HistoryLog & ); HistoryLog & operator=( const HistoryLog & ); - private: - static std::ofstream _log; - static unsigned _refcnt; - static Pathname _fname; - static const char _sep; - - static void openLog(); - static void closeLog(); - static void refUp(); - static void refDown(); - public: /** * Constructor with an optional root directory. @@ -79,8 +67,7 @@ namespace zypp * \param rootdir actual target root directory */ HistoryLog( const Pathname & rootdir = Pathname() ); - ~HistoryLog() - { refDown(); } + ~HistoryLog(); /** * Set new root directory to the default history log file path. -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org