Mailinglist Archive: zypp-commit (172 mails)

< Previous Next >
[zypp-commit] <libzypp> SuSE-Code-11-Branch : Compute obsoletes based on names only (not considering provides) (bnc #471023)
  • From: Michael Andres <ma@xxxxxxx>
  • Date: Tue, 17 Feb 2009 18:04:03 +0100
  • Message-id: <E1LZTMv-0004TD-8G@xxxxxxxxxxxxxxxx>
ref: refs/heads/SuSE-Code-11-Branch
commit 570c5d3102a31aeb88b28967e56707d0ade29bc3
Author: Michael Andres <ma@xxxxxxx>
Date: Tue Feb 17 18:04:03 2009 +0100

Compute obsoletes based on names only (not considering provides) (bnc
#471023)
---
tests/data/TCWhatObsoletes/solver-system.xml | 55 +++++++++++
tests/data/TCWhatObsoletes/solver-test.xml | 7 ++
tests/sat/CMakeLists.txt | 2 +-
tests/sat/WhatObsoletes_test.cc | 37 ++++++++
zypp/sat/WhatObsoletes.cc | 127 ++++++++++++++++++-------
zypp/sat/WhatObsoletes.h | 21 ++++-
6 files changed, 208 insertions(+), 41 deletions(-)

diff --git a/tests/data/TCWhatObsoletes/solver-system.xml
b/tests/data/TCWhatObsoletes/solver-system.xml
new file mode 100644
index 0000000..ce95a06
--- /dev/null
+++ b/tests/data/TCWhatObsoletes/solver-system.xml
@@ -0,0 +1,55 @@
+<channel><subchannel>
+<package>
+ <name>test1</name>
+ <history><update>
+ <arch>i586</arch>
+ <version>1</version><release>1</release>
+ </update></history>
+ <provides>
+ <dep name='test1' op='==' version='1' release='1' />
+ </provides>
+ <obsoletes>
+ <dep name='goaway' op='&lt;' version='2' release='1' />
+ </obsoletes>
+</package>
+<package>
+ <name>goaway</name>
+ <history><update>
+ <arch>i586</arch>
+ <version>1</version><release>1</release>
+ </update></history>
+ <provides>
+ <dep name='goaway' op='==' version='1' release='1' />
+ </provides>
+</package>
+<package>
+ <name>goaway</name>
+ <history><update>
+ <arch>i586</arch>
+ <version>2</version><release>1</release>
+ </update></history>
+ <provides>
+ <dep name='goaway' op='==' version='2' release='1' />
+ </provides>
+</package>
+<package>
+ <name>meetoo</name>
+ <history><update>
+ <arch>i586</arch>
+ <version>1</version><release>1</release>
+ </update></history>
+ <provides>
+ <dep name='goaway' op='==' version='1' release='1' />
+ </provides>
+</package>
+<package>
+ <name>meetoo</name>
+ <history><update>
+ <arch>i586</arch>
+ <version>2</version><release>1</release>
+ </update></history>
+ <provides>
+ <dep name='goaway' op='==' version='2' release='1' />
+ </provides>
+</package>
+</subchannel></channel>
diff --git a/tests/data/TCWhatObsoletes/solver-test.xml
b/tests/data/TCWhatObsoletes/solver-test.xml
new file mode 100644
index 0000000..9a2143d
--- /dev/null
+++ b/tests/data/TCWhatObsoletes/solver-test.xml
@@ -0,0 +1,7 @@
+<?xml version="1.0"?>
+<test>
+<setup arch="i686">
+ <system file="solver-system.xml.gz"/>
+ <locale name="en_US" />
+</setup>
+</test>
diff --git a/tests/sat/CMakeLists.txt b/tests/sat/CMakeLists.txt
index 309ebb9..60775d4 100644
--- a/tests/sat/CMakeLists.txt
+++ b/tests/sat/CMakeLists.txt
@@ -2,6 +2,6 @@
# to find the KeyRingTest receiver
INCLUDE_DIRECTORIES( ${LIBZYPP_SOURCE_DIR}/tests/zypp )

-ADD_TESTS(Solvable SolvParsing WhatProvides LookupAttr)
+ADD_TESTS(Solvable SolvParsing WhatProvides WhatObsoletes LookupAttr)


diff --git a/tests/sat/WhatObsoletes_test.cc b/tests/sat/WhatObsoletes_test.cc
new file mode 100644
index 0000000..c082d99
--- /dev/null
+++ b/tests/sat/WhatObsoletes_test.cc
@@ -0,0 +1,37 @@
+#include "TestSetup.h"
+#include <zypp/sat/WhatObsoletes.h>
+
+#define LABELED(V) #V << ":\t" << V
+
+namespace zypp
+{
+ namespace sat
+ {
+ // Obsoletes may either match against provides, or names.
+ // Configuration depends on the behaviour of rpm.
+ extern bool obsoleteUsesProvides;
+ }
+}
+
+BOOST_AUTO_TEST_CASE(WhatObsoletes)
+{
+ TestSetup test( Arch_x86_64 );
+ test.loadTestcaseRepos( TESTS_SRC_DIR"/data/TCWhatObsoletes" );
+
+ sat::Solvable test1( 2 );
+ BOOST_REQUIRE_EQUAL( test1.name(), "test1" );
+
+ {
+ sat::obsoleteUsesProvides = true;
+ sat::WhatObsoletes w( test1 );
+ BOOST_REQUIRE( w.size() == 2 );
+ // (3)goaway-1-1.i586(@System)
+ // (5)meetoo-1-1.i586(@System)
+ }
+ {
+ sat::obsoleteUsesProvides = false;
+ sat::WhatObsoletes w( test1 );
+ BOOST_REQUIRE( w.size() == 1 );
+ // (3)goaway-1-1.i586(@System)
+ }
+}
\ No newline at end of file
diff --git a/zypp/sat/WhatObsoletes.cc b/zypp/sat/WhatObsoletes.cc
index 077e73d..800b7e0 100644
--- a/zypp/sat/WhatObsoletes.cc
+++ b/zypp/sat/WhatObsoletes.cc
@@ -12,6 +12,7 @@
#include <iostream>

#include "zypp/base/LogTools.h"
+#include "zypp/base/Tr1hash.h"
#include "zypp/sat/WhatObsoletes.h"
#include "zypp/sat/detail/PoolImpl.h"
#include "zypp/PoolItem.h"
@@ -25,62 +26,116 @@ namespace zypp
namespace sat
{ /////////////////////////////////////////////////////////////////

+ // Obsoletes may either match against provides, or names.
+ // Configuration depends on the behaviour of rpm.
+ bool obsoleteUsesProvides = false;
+
///////////////////////////////////////////////////////////////////
namespace
{ /////////////////////////////////////////////////////////////////

- /** WhatObsoletes ctor helper collecting obsoleted installed items. */
- shared_ptr<void> allocatedProviders( sat::Solvable item_r, const
sat::detail::IdType *& first_r )
+ typedef std::tr1::unordered_set<detail::IdType> set_type;
+ typedef std::vector<sat::detail::IdType> vector_type;
+
+ /////////////////////////////////////////////////////////////////
+ } // namespace
+ ///////////////////////////////////////////////////////////////////
+
+ WhatObsoletes::WhatObsoletes( Solvable item_r )
+ : _begin( 0 )
+ {
+ ctorAdd( item_r );
+ ctorDone();
+ }
+
+ WhatObsoletes::WhatObsoletes( const PoolItem & item_r )
+ : _begin( 0 )
+ {
+ ctorAdd( item_r );
+ ctorDone();
+ }
+
+ WhatObsoletes::WhatObsoletes( const ResObject::constPtr item_r )
+ : _begin( 0 )
+ {
+ if ( item_r )
{
- WhatProvides obsoleted( item_r.obsoletes() );
- if ( obsoleted.empty() )
+ ctorAdd( item_r->satSolvable() );
+ ctorDone();
+ }
+ }
+
+ void WhatObsoletes::ctorAdd( const PoolItem & item_r )
+ { ctorAdd( item_r->satSolvable() ); }
+
+ void WhatObsoletes::ctorAdd( ResObject_constPtr item_r )
+ { if ( item_r ) ctorAdd( item_r->satSolvable() ); }
+
+
+ namespace
+ {
+ /** Add item to the set created on demand. */
+ inline void addToSet( Solvable item, set_type *& pdata,
shared_ptr<void>& _private )
+ {
+ if ( ! pdata )
{
- return shared_ptr<void>();
+ _private.reset( (pdata = new set_type) );
}
+ pdata->insert( item.id() );
+ }
+ }

- // use allocated private data to store the result (incl. trailing NULL)
- std::vector<sat::detail::IdType> * pdata = 0;
- shared_ptr<void> ret;
+ void WhatObsoletes::ctorAdd( Solvable item_r )
+ {
+ if ( obsoleteUsesProvides )
+ {
+ WhatProvides obsoleted( item_r.obsoletes() );
+ if ( obsoleted.empty() )
+ return;

+ // use allocated private data to collect the results
+ set_type * pdata = ( _private ? reinterpret_cast<set_type*>(
_private.get() ) : 0 );
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() );
- }
+ addToSet( *it, pdata, _private );
}
+ }
+ else // Obsoletes match names
+ {
+ Capabilities obsoletes( item_r.obsoletes() );
+ if ( obsoletes.empty() )
+ return;

- if ( pdata )
+ // use allocated private data to collect the results
+ set_type * pdata = ( _private ? reinterpret_cast<set_type*>(
_private.get() ) : 0 );
+ for_( it, obsoletes.begin(), obsoletes.end() )
{
- pdata->push_back( sat::detail::noId );
- first_r = &pdata->front();
+ // For each obsoletes find providers, but with the same name
+ IdString ident( it->detail().name() );
+ WhatProvides obsoleted( *it );
+ for_( iit, obsoleted.begin(), obsoleted.end() )
+ {
+ if ( iit->isSystem() && iit->ident() == ident )
+ addToSet( *iit, pdata, _private );
+ }
}
- return ret;
}
+ }

- /////////////////////////////////////////////////////////////////
- } // namespace
- ///////////////////////////////////////////////////////////////////
-
- WhatObsoletes::WhatObsoletes( Solvable item_r )
- : _begin( 0 )
- , _private( allocatedProviders( item_r, _begin ) )
- {}
+ void WhatObsoletes::ctorDone()
+ {
+ if ( _private )
+ {
+ // copy set to vector and terminate _private
+ set_type * sdata = reinterpret_cast<set_type*>( _private.get() );

- WhatObsoletes::WhatObsoletes( const PoolItem & item_r )
- : _begin( 0 )
- , _private( allocatedProviders( item_r.satSolvable(), _begin ) )
- {}
+ vector_type * pdata = new vector_type( sdata->begin(), sdata->end() );
+ pdata->push_back( sat::detail::noId );
+ _begin = &pdata->front();

- WhatObsoletes::WhatObsoletes( const ResObject::constPtr item_r )
- : _begin( 0 )
- {
- if ( item_r )
- _private = allocatedProviders( item_r->satSolvable(), _begin );
+ _private.reset( pdata );
+ }
}

WhatObsoletes::size_type WhatObsoletes::size() const
diff --git a/zypp/sat/WhatObsoletes.h b/zypp/sat/WhatObsoletes.h
index 7e2af1f..f34efd7 100644
--- a/zypp/sat/WhatObsoletes.h
+++ b/zypp/sat/WhatObsoletes.h
@@ -31,10 +31,7 @@ namespace zypp
/** Container of \b installed \ref Solvable which would be
* obsoleted by the \ref Solvable passed to the ctor.
*
- * \code
- * \endcode
- *
- * \todo Add flag to also add any installed version to the containter.
+ * \todo Publish obsoleteUsesProvides config option.
*/
class WhatObsoletes : public
SolvIterMixin<WhatObsoletes,detail::WhatProvidesIterator>,
protected detail::PoolMember
@@ -61,6 +58,16 @@ namespace zypp
explicit
WhatObsoletes( const ResObject_constPtr item_r );

+ /** Ctor from a range of \ref Solvable, \ref PoolItem or \ref
ResObject::constPtr. */
+ template <class _Iterator>
+ WhatObsoletes( _Iterator begin, _Iterator end )
+ : _begin( 0 )
+ {
+ for_( it, begin, end )
+ ctorAdd( *it );
+ ctorDone();
+ }
+
public:
/** Whether the container is empty. */
bool empty() const
@@ -81,6 +88,12 @@ namespace zypp
{ return const_iterator(); }

private:
+ void ctorAdd( const PoolItem & item_r );
+ void ctorAdd( ResObject_constPtr item_r );
+ void ctorAdd( Solvable item_r );
+ void ctorDone();
+
+ private:
const sat::detail::IdType * _begin;
shared_ptr<void> _private;
};
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: zypp-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages