Products that would be replaced by installing a new Product.
#include "zypp/sat/SolvableSet.h"
#include "zypp/sat/SolvIterMixin.h"
#include "zypp/sat/detail/PoolImpl.h"
+#include "zypp/sat/WhatObsoletes.h"
#include "zypp/PoolQuery.h"
#include "zypp/parser/ProductConfReader.h"
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
- testcase();
- MIL << "FOOO" << endl;
+ // Pool of Selectables
+ ResPoolProxy selectablePool( ResPool::instance().proxy() );
- ///////////////////////////////////////////////////////////////////
+ // Iterate it's Products...
+ for_( it, selectablePool.byKindBegin<Product>(), selectablePool.byKindEnd<Product>() )
+ {
+ // current Product Selectable
+ ui::Selectable::Ptr prodSel( *it );
+ MIL << dump( prodSel ) << endl;
+
+ // It's candiate as Product pointer
+ Product::constPtr prod( prodSel->candidateAsKind<Product>() );
+ if ( prod )
+ {
+ // Not NULL, so there is an available Product.
+ // Get the installed Products it would replace.
+ Product::ReplacedProducts prodReplaces( prod->replacedProducts() );
+
+ // Iterate the replaced Products...
+ for_( it, prodReplaces.begin(), prodReplaces.end() )
+ {
+ // current replaced Product
+ Product::constPtr replacedProduct( *it );
+ DBG << replacedProduct << endl;
+
+ // and this is how you would get the Selectable that contains
+ // this replacedProduct, in case you need it ..
+ ui::Selectable::Ptr replacedProductsSelectable( ui::Selectable::get( replacedProduct ) );
+ DBG << replacedProductsSelectable << endl;
+ }
+ }
+
+ }
+
+
+ ///////////////////////////////////////////////////////////////////
INT << "===[END]============================================" << endl << endl;
zypp::base::LogControl::instance().logNothing();
return 0;
-------------------------------------------------------------------
+Fri Aug 15 17:42:58 CEST 2008 - ma@suse.de
+
+- Add method Product::replacedProducts to identify installed
+ Products that would be replaced by installing a new Product.
+ (for Fate #301997)
+- revision 10876
+
+-------------------------------------------------------------------
Fri Aug 15 15:30:32 CEST 2008 - ma@suse.de
- Fixes to Selectable doing staus manipulation on non-USER level.
sat/SolvableSet.cc
sat/SolvIterMixin.cc
sat/WhatProvides.cc
+ sat/WhatObsoletes.cc
sat/LocaleSupport.cc
sat/LookupAttr.cc
sat/SolvAttr.cc
sat/SolvableSet.h
sat/SolvIterMixin.h
sat/WhatProvides.h
+ sat/WhatObsoletes.h
sat/LocaleSupport.h
sat/LookupAttr.h
sat/SolvAttr.h
#include "zypp/sat/LookupAttr.h"
#include "zypp/sat/WhatProvides.h"
+#include "zypp/sat/WhatObsoletes.h"
+#include "zypp/PoolItem.h"
using std::endl;
{}
///////////////////////////////////////////////////////////////////
- //
- // Package interface forwarded to implementation
- //
- ///////////////////////////////////////////////////////////////////
sat::Solvable Product::referencePackage() const
{
return sat::Solvable::noSolvable;
}
+ Product::ReplacedProducts Product::replacedProducts() const
+ {
+ std::vector<constPtr> ret;
+ // By now we simply collect what is obsoleted by the Product,
+ // or by the products buddy (release-package).
+
+ // Check our own dependencies. We should not have any,
+ // but just to be shure.
+ sat::WhatObsoletes obsoleting( satSolvable() );
+ for_( it, obsoleting.begin(), obsoleting.end() )
+ {
+ if ( it->isKind( ResKind::product ) )
+ ret.push_back( make<Product>( *it ) );
+ }
+
+ // If we have a buddy, we check what product buddies the
+ // buddy replaces.
+ obsoleting = sat::WhatObsoletes( poolItem().buddy() );
+ for_( it, obsoleting.poolItemBegin(), obsoleting.poolItemEnd() )
+ {
+ if ( (*it).buddy().isKind( ResKind::product ) )
+ ret.push_back( make<Product>( (*it).buddy() ) );
+ }
+
+ return ret;
+ }
+
+ ///////////////////////////////////////////////////////////////////
+
std::string Product::shortName() const
{ return lookupStrAttribute( sat::SolvAttr::productShortlabel ); }
sat::Solvable referencePackage() const;
public:
+ /***/
+ typedef std::vector<constPtr> ReplacedProducts;
+
+ /** Array of \b installed Products that would be replaced by
+ * installing this one.
+ */
+ ReplacedProducts replacedProducts() const;
+
+ public:
/** Untranslated short name like <tt>SLES 10</tt>*/
std::string shortName() const;
--- /dev/null
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/sat/WhatObsoletes.cc
+ *
+*/
+#include <iostream>
+
+#include "zypp/base/LogTools.h"
+#include "zypp/sat/WhatObsoletes.h"
+#include "zypp/sat/detail/PoolImpl.h"
+#include "zypp/PoolItem.h"
+
+using std::endl;
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ namespace sat
+ { /////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////
+ namespace
+ { /////////////////////////////////////////////////////////////////
+
+ /** WhatObsoletes ctor helper collecting obsoleted installed items. */
+ shared_ptr<void> allocatedProviders( sat::Solvable item_r, const sat::detail::IdType *& first_r )
+ {
+ WhatProvides obsoleted( item_r.obsoletes() );
+ if ( obsoleted.empty() )
+ {
+ return shared_ptr<void>();
+ }
+
+ // use allocated private data to store the result (incl. trailing NULL)
+ std::vector<sat::detail::IdType> * pdata = 0;
+ shared_ptr<void> ret;
+
+ for_( it, obsoleted.begin(), obsoleted.end() )
+ {
+ if ( it->isSystem() )
+ {
+ if ( ! pdata )
+ {
+ ret.reset( (pdata = new std::vector<sat::detail::IdType>) );
+ }
+ pdata->push_back( it->id() );
+ }
+ }
+
+ if ( pdata )
+ {
+ pdata->push_back( sat::detail::noId );
+ first_r = &pdata->front();
+ }
+ return ret;
+ }
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace
+ ///////////////////////////////////////////////////////////////////
+
+ WhatObsoletes::WhatObsoletes( Solvable item_r )
+ : _begin( 0 )
+ , _private( allocatedProviders( item_r, _begin ) )
+ {}
+
+ WhatObsoletes::WhatObsoletes( const PoolItem & item_r )
+ : _begin( 0 )
+ , _private( allocatedProviders( item_r.satSolvable(), _begin ) )
+ {}
+
+ WhatObsoletes::WhatObsoletes( const ResObject::constPtr item_r )
+ : _begin( 0 )
+ {
+ if ( item_r )
+ _private = allocatedProviders( item_r->satSolvable(), _begin );
+ }
+
+ WhatObsoletes::size_type WhatObsoletes::size() const
+ {
+ if ( ! _begin )
+ return 0;
+
+ Capabilities::size_type ret = 0;
+ for ( const sat::detail::IdType * end = _begin; *end; ++end )
+ {
+ ++ret;
+ }
+ return ret;
+ }
+
+ /******************************************************************
+ **
+ ** FUNCTION NAME : operator<<
+ ** FUNCTION TYPE : std::ostream &
+ */
+ std::ostream & operator<<( std::ostream & str, const WhatObsoletes & obj )
+ {
+ return dumpRange( str << "(" << obj.size() << ")", obj.begin(), obj.end() );
+ }
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace sat
+ ///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
--- /dev/null
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+/** \file zypp/sat/WhatObsoletes.h
+ *
+*/
+#ifndef ZYPP_SAT_WHATOBSOLETES_H
+#define ZYPP_SAT_WHATOBSOLETES_H
+
+#include <iosfwd>
+#include <vector>
+
+#include "zypp/sat/WhatProvides.h"
+
+///////////////////////////////////////////////////////////////////
+namespace zypp
+{ /////////////////////////////////////////////////////////////////
+ ///////////////////////////////////////////////////////////////////
+ namespace sat
+ { /////////////////////////////////////////////////////////////////
+
+ ///////////////////////////////////////////////////////////////////
+ //
+ // CLASS NAME : WhatObsoletes
+ //
+ /** Container of \b installed \ref Solvable which would be
+ * obsoleted by the \ref Solvable passed to the ctor.
+ *
+ * \code
+ * \endcode
+ */
+ class WhatObsoletes : public SolvIterMixin<WhatObsoletes,detail::WhatProvidesIterator>,
+ protected detail::PoolMember
+ {
+ public:
+ typedef Solvable value_type;
+ typedef unsigned size_type;
+
+ public:
+ /** Default ctor */
+ WhatObsoletes()
+ : _begin( 0 )
+ {}
+
+ /** Ctor from \ref Solvable. */
+ explicit
+ WhatObsoletes( Solvable item_r );
+
+ /** Ctor from \ref PoolItem. */
+ explicit
+ WhatObsoletes( const PoolItem & item_r );
+
+ /** Ctor from \ref ResObject::constPtr. */
+ explicit
+ WhatObsoletes( const ResObject_constPtr item_r );
+
+ public:
+ /** Whether the container is empty. */
+ bool empty() const
+ { return ! ( _begin && *_begin ); }
+
+ /** Number of solvables inside. */
+ size_type size() const;
+
+ public:
+ typedef detail::WhatProvidesIterator const_iterator;
+
+ /** Iterator pointing to the first \ref Solvable. */
+ const_iterator begin() const
+ { return const_iterator( _begin ); }
+
+ /** Iterator pointing behind the last \ref Solvable. */
+ const_iterator end() const
+ { return const_iterator( 0 ); }
+
+ private:
+ const sat::detail::IdType * _begin;
+ shared_ptr<void> _private;
+ };
+ ///////////////////////////////////////////////////////////////////
+
+ /** \relates WhatObsoletes Stream output */
+ std::ostream & operator<<( std::ostream & str, const WhatObsoletes & obj );
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace sat
+ ///////////////////////////////////////////////////////////////////
+ /////////////////////////////////////////////////////////////////
+} // namespace zypp
+///////////////////////////////////////////////////////////////////
+#endif // ZYPP_SAT_WHATOBSOLETES_H
return shared_ptr<void>();
}
- // use allocated private data to store the result
- std::vector<sat::detail::IdType> * pdata = new std::vector<sat::detail::IdType>( ids.size(), sat::detail::noId );
+ // use allocated private data to store the result (incl. trailing NULL)
+ std::vector<sat::detail::IdType> * pdata = new std::vector<sat::detail::IdType>( ids.size()+1, sat::detail::noId );
pdata->insert( pdata->begin(), ids.begin(), ids.end() );
first_r = &pdata->front();
return shared_ptr<void>( pdata );
| /_____||_| |_| |_| |
| |
\---------------------------------------------------------------------*/
-/** \file zypp/sat/.h
+/** \file zypp/sat/WhatProvides.h
*
*/
#ifndef ZYPP_SAT_WHATPROVIDES_H
// CLASS NAME : WhatProvides::const_iterator
//
/** \ref WhatProvides iterator.
+ * Iterate a NULL terminated sat::detail::IdType array.
*/
class WhatProvidesIterator : public boost::iterator_adaptor<
WhatProvidesIterator // Derived
*/
PoolItem candidateObj() const;
+ /** Return the \ref installedObj resolvable casted to a specific kind.
+ * \code
+ * Selectable mySelectable;
+ * Package::constPtr p( mySelectable.installedAsKind<Package>() );
+ * \endcode
+ */
+ template<class _Res>
+ typename ResTraits<_Res>::constPtrType installedAsKind() const
+ { return asKind<_Res>( candidateObj() ); }
+
+ /** Return the \ref candidateObj resolvable casted to a specific kind.
+ * \code
+ * Selectable mySelectable;
+ * Package::constPtr p( mySelectable.candidateAsKind<Package>() );
+ * \endcode
+ */
+ template<class _Res>
+ typename ResTraits<_Res>::constPtrType candidateAsKind() const
+ { return asKind<_Res>( candidateObj() ); }
+
/** Set a candidate (out of available objects).
* \return The new candidate, or NULL if choice was invalid
* (NULL or not among availableObjs). An invalid choice
#include "zypp/base/Iterator.h"
#include "zypp/PoolItem.h"
#include "zypp/pool/ByIdent.h"
-//#include "zypp/ResObject.h"
///////////////////////////////////////////////////////////////////
namespace zypp