libzypp 17.31.23
WhatObsoletes.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#include <iostream>
13
14#include <zypp/base/LogTools.h>
15#include <zypp/base/Hash.h>
17#include <zypp/sat/detail/PoolImpl.h>
18#include <zypp/PoolItem.h>
19
20using std::endl;
21
23namespace zypp
24{
26 namespace sat
27 {
28
29 // Obsoletes may either match against provides, or names.
30 // Configuration depends on the behaviour of rpm.
31#ifdef _RPM_5
32 bool obsoleteUsesProvides = true;
33#else
35#endif
36
38 namespace
39 {
40
41 typedef std::unordered_set<detail::IdType> set_type;
42 typedef std::vector<sat::detail::IdType> vector_type;
43
45 } // namespace
47
49 : _begin( 0 )
50 {
51 ctorAdd( item_r );
52 ctorDone();
53 }
54
56 : _begin( 0 )
57 {
58 ctorAdd( item_r );
59 ctorDone();
60 }
61
63 : _begin( 0 )
64 {
65 if ( item_r )
66 {
67 ctorAdd( item_r->satSolvable() );
68 ctorDone();
69 }
70 }
71
72 void WhatObsoletes::ctorAdd( const PoolItem & item_r )
73 { ctorAdd( item_r->satSolvable() ); }
74
75 void WhatObsoletes::ctorAdd( ResObject_constPtr item_r )
76 { if ( item_r ) ctorAdd( item_r->satSolvable() ); }
77
78
79 namespace
80 {
82 inline void addToSet( Solvable item, set_type *& pdata, shared_ptr<void>& _private )
83 {
84 if ( ! pdata )
85 {
86 _private.reset( (pdata = new set_type) );
87 }
88 pdata->insert( item.id() );
89 }
90 }
91
93 {
94 if ( item_r.multiversionInstall() )
95 return; // multiversion (rpm -i) does not evaluate any obsoletes
96
98 {
99 WhatProvides obsoleted( item_r.obsoletes() );
100 if ( obsoleted.empty() )
101 return;
102
103 // use allocated private data to collect the results
104 set_type * pdata = ( _private ? reinterpret_cast<set_type*>( _private.get() ) : 0 );
105 for_( it, obsoleted.begin(), obsoleted.end() )
106 {
107 if ( it->isSystem() )
108 addToSet( *it, pdata, _private );
109 }
110 }
111 else // Obsoletes match names
112 {
113 Capabilities obsoletes( item_r.obsoletes() );
114 if ( obsoletes.empty() )
115 return;
116
117 // use allocated private data to collect the results
118 set_type * pdata = ( _private ? reinterpret_cast<set_type*>( _private.get() ) : 0 );
119 for_( it, obsoletes.begin(), obsoletes.end() )
120 {
121 // For each obsoletes find providers, but with the same name
122 IdString ident( it->detail().name() );
123 WhatProvides obsoleted( *it );
124 for_( iit, obsoleted.begin(), obsoleted.end() )
125 {
126 if ( iit->isSystem() && iit->ident() == ident )
127 addToSet( *iit, pdata, _private );
128 }
129 }
130 }
131 }
132
134 {
135 if ( _private )
136 {
137 // copy set to vector and terminate _private
138 set_type * sdata = reinterpret_cast<set_type*>( _private.get() );
139
140 vector_type * pdata = new vector_type( sdata->begin(), sdata->end() );
141 pdata->push_back( sat::detail::noId );
142 _begin = &pdata->front();
143
144 _private.reset( pdata );
145 }
146 }
147
149 {
150 if ( ! _begin )
151 return 0;
152
154 for ( const sat::detail::IdType * end = _begin; *end; ++end )
155 {
156 ++ret;
157 }
158 return ret;
159 }
160
161 /******************************************************************
162 **
163 ** FUNCTION NAME : operator<<
164 ** FUNCTION TYPE : std::ostream &
165 */
166 std::ostream & operator<<( std::ostream & str, const WhatObsoletes & obj )
167 {
168 return dumpRange( str << "(" << obj.size() << ")", obj.begin(), obj.end() );
169 }
170
172 } // namespace sat
175} // namespace zypp
Container of Capability (currently read only).
Definition: Capabilities.h:36
const_iterator begin() const
Iterator pointing to the first Capability.
Definition: Capabilities.h:169
const_iterator end() const
Iterator pointing behind the last Capability.
Definition: Capabilities.h:172
bool empty() const
Whether the container is empty.
Definition: Capabilities.h:62
Access to the sat-pools string space.
Definition: IdString.h:43
Combining sat::Solvable and ResStatus.
Definition: PoolItem.h:51
TraitsType::constPtrType constPtr
Definition: ResObject.h:43
A Solvable object within the sat Pool.
Definition: Solvable.h:54
IdType id() const
Expert backdoor.
Definition: Solvable.h:428
bool multiversionInstall() const
Whether different versions of this package can be installed at the same time.
Definition: Solvable.cc:430
Capabilities obsoletes() const
Definition: Solvable.cc:499
Container of installed Solvable which would be obsoleted by the Solvable passed to the ctor.
Definition: WhatObsoletes.h:38
const_iterator end() const
Iterator pointing behind the last Solvable.
Definition: WhatObsoletes.h:87
void ctorAdd(const PoolItem &item_r)
WhatObsoletes()
Default ctor.
Definition: WhatObsoletes.h:45
size_type size() const
Number of solvables inside.
const sat::detail::IdType * _begin
Definition: WhatObsoletes.h:97
shared_ptr< void > _private
Definition: WhatObsoletes.h:98
const_iterator begin() const
Iterator pointing to the first Solvable.
Definition: WhatObsoletes.h:83
Container of Solvable providing a Capability (read only).
Definition: WhatProvides.h:89
const_iterator end() const
Iterator pointing behind the last Solvable.
Definition: WhatProvides.h:234
bool empty() const
Whether the container is empty.
const_iterator begin() const
Iterator pointing to the first Solvable.
String related utilities and Regular expression matching.
static const IdType noId(0)
int IdType
Generic Id type.
Definition: PoolMember.h:104
std::ostream & operator<<(std::ostream &str, const FileConflicts &obj)
bool obsoleteUsesProvides
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
std::ostream & dumpRange(std::ostream &str, TIterator begin, TIterator end, const std::string &intro="{", const std::string &pfx="\n ", const std::string &sep="\n ", const std::string &sfx="\n", const std::string &extro="}")
Print range defined by iterators (multiline style).
Definition: LogTools.h:92
Solvable satSolvable() const
Return the corresponding sat::Solvable.
Definition: SolvableType.h:57
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:28