ref: refs/heads/master
commit 657b024e3e82248fa43d94e0989fcdb7230b9b85
Author: Michael Andres
Date: Fri Oct 9 14:16:08 2009 +0200
Add example code printing updateMessages.
---
zypp/ZYppCommitResult.cc | 10 +++++++++-
zypp/ZYppCommitResult.h | 31 +++++++++++++++++++++++++++++++
zypp/target/TargetImpl.cc | 13 +++++++------
3 files changed, 47 insertions(+), 7 deletions(-)
diff --git a/zypp/ZYppCommitResult.cc b/zypp/ZYppCommitResult.cc
index ed9b62e..8431424 100644
--- a/zypp/ZYppCommitResult.cc
+++ b/zypp/ZYppCommitResult.cc
@@ -31,7 +31,8 @@ namespace zypp
{}
public:
- UpdateNotifications _updateMessages;
+ Pathname _root;
+ UpdateNotifications _updateMessages;
private:
friend Impl * rwcowClone<Impl>( const Impl * rhs );
@@ -49,6 +50,13 @@ namespace zypp
: _result(0), _pimpl( new Impl )
{}
+ ZYppCommitResult::ZYppCommitResult( const Pathname & root_r )
+ : _result(0), _pimpl( new Impl )
+ { _pimpl->_root = root_r; }
+
+ const Pathname & ZYppCommitResult::root() const
+ { return _pimpl->_root; }
+
const UpdateNotifications & ZYppCommitResult::updateMessages() const
{ return _pimpl->_updateMessages; }
diff --git a/zypp/ZYppCommitResult.h b/zypp/ZYppCommitResult.h
index ae65611..81f6559 100644
--- a/zypp/ZYppCommitResult.h
+++ b/zypp/ZYppCommitResult.h
@@ -51,10 +51,41 @@ namespace zypp
{
public:
ZYppCommitResult();
+ ZYppCommitResult( const Pathname & root_r );
public:
+ /** Remembered root directory of the target.
+ * \Note Pathnames within this class are relative to the
+ * targets root directory.
+ */
+ const Pathname & root() const;
+
/** List of update messages installed during this commit.
* \Note Pathnames are relative to the targets root directory.
+ * \code
+ * ZYppCommitResult result;
+ * ...
+ * if ( ! result.updateMessages().empty() )
+ * {
+ * MIL << "Received " << result.updateMessages().size() << " update notification(s):" << endl;
+ * for_( it, result.updateMessages().begin(), result.updateMessages().end() )
+ * {
+ * MIL << "- From " << it->solvable().asString() << " in file " << Pathname::showRootIf( result.root(), it->file() ) << ":" << endl;
+ * {
+ * // store message files content in a string:
+ * InputStream istr( Pathname::assertprefix( result.root(), it->file() ) );
+ * std::ostringstream strstr;
+ * iostr::copy( istr, strstr );
+ * std::string message( strstr.str() ); // contains the message
+ * }
+ * {
+ * // or write out the message file indented:
+ * InputStream istr( Pathname::assertprefix( result.root(), it->file() ) );
+ * iostr::copyIndent( istr, MIL, "> " ) << endl;
+ * }
+ * }
+ * }
+ * \endcode
*/
const UpdateNotifications & updateMessages() const;
diff --git a/zypp/target/TargetImpl.cc b/zypp/target/TargetImpl.cc
index 115128b..87c1bbe 100644
--- a/zypp/target/TargetImpl.cc
+++ b/zypp/target/TargetImpl.cc
@@ -428,7 +428,7 @@ namespace zypp
continue;
PathInfo message( messagesDir / *sit );
- if ( ! message.isFile() )
+ if ( ! message.isFile() || message.size() == 0 )
continue;
MIL << "Found update message " << *sit << endl;
@@ -958,7 +958,7 @@ namespace zypp
// Compute transaction:
///////////////////////////////////////////////////////////////////
- ZYppCommitResult result;
+ ZYppCommitResult result( root() );
TargetImpl::PoolItemList to_uninstall;
TargetImpl::PoolItemList to_install;
TargetImpl::PoolItemList to_srcinstall;
@@ -1371,16 +1371,17 @@ namespace zypp
// at least log omitted scripts.
if ( ! successfullyInstalledPackages.empty() )
{
- RunUpdateMessages( _root, ZConfig::instance().update_messagesPath(),
- successfullyInstalledPackages,
- result_r );
-
if ( ! RunUpdateScripts( _root, ZConfig::instance().update_scriptsPath(),
successfullyInstalledPackages, abort ) )
{
WAR << "Commit aborted by the user" << endl;
abort = true;
}
+ // send messages after scripts in case some script generates output,
+ // that should be kept in t %ghost message file.
+ RunUpdateMessages( _root, ZConfig::instance().update_messagesPath(),
+ successfullyInstalledPackages,
+ result_r );
}
if ( abort )
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org