libzypp  17.25.3
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>
16 #include <zypp/sat/WhatObsoletes.h>
18 #include <zypp/PoolItem.h>
19 
20 using std::endl;
21 
23 namespace zypp
24 {
25  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
34  bool obsoleteUsesProvides = false;
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 
153  Capabilities::size_type ret = 0;
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
zypp::PoolItem
Combining sat::Solvable and ResStatus.
Definition: PoolItem.h:51
zypp::sat::WhatObsoletes::size_type
unsigned size_type
Definition: WhatObsoletes.h:41
zypp::sat::Solvable
A Solvable object within the sat Pool.
Definition: Solvable.h:54
zypp::sat::WhatProvides
Container of Solvable providing a Capability (read only).
Definition: WhatProvides.h:89
zypp::sat::WhatObsoletes::WhatObsoletes
WhatObsoletes()
Default ctor.
Definition: WhatObsoletes.h:45
zypp::sat::Solvable::id
IdType id() const
Expert backdoor.
Definition: Solvable.h:399
zypp::sat::SolvableType::satSolvable
Solvable satSolvable() const
Return the corresponding sat::Solvable.
Definition: SolvableType.h:57
zypp::sat::WhatProvides::empty
bool empty() const
Whether the container is empty.
Definition: WhatProvides.cc:129
zypp::sat::detail::noId
static const IdType noId(0)
zypp::dumpRange
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:91
zypp::Capabilities::begin
const_iterator begin() const
Iterator pointing to the first Capability.
Definition: Capabilities.h:169
zypp::sat::WhatObsoletes::_begin
const sat::detail::IdType * _begin
Definition: WhatObsoletes.h:97
zypp::sat::obsoleteUsesProvides
bool obsoleteUsesProvides
Definition: WhatObsoletes.cc:34
zypp::sat::WhatProvides::end
const_iterator end() const
Iterator pointing behind the last Solvable.
Definition: WhatProvides.h:226
zypp::sat::WhatObsoletes::_private
shared_ptr< void > _private
Definition: WhatObsoletes.h:98
zypp::ResObject::constPtr
TraitsType::constPtrType constPtr
Definition: ResObject.h:43
zypp::sat::WhatProvides::begin
const_iterator begin() const
Iterator pointing to the first Solvable.
Definition: WhatProvides.cc:145
zypp::IdString
Access to the sat-pools string space.
Definition: IdString.h:43
LogTools.h
PoolImpl.h
zypp::sat::WhatObsoletes::ctorDone
void ctorDone()
Definition: WhatObsoletes.cc:133
zypp::Capabilities::end
const_iterator end() const
Iterator pointing behind the last Capability.
Definition: Capabilities.h:172
zypp::sat::Solvable::multiversionInstall
bool multiversionInstall() const
Whether different versions of this package can be installed at the same time.
Definition: Solvable.cc:415
zypp::sat::detail::IdType
int IdType
Generic Id type.
Definition: PoolMember.h:104
zypp::sat::operator<<
std::ostream & operator<<(std::ostream &str, const FileConflicts &obj)
Definition: FileConflicts.cc:109
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
zypp::sat::WhatObsoletes
Container of installed Solvable which would be obsoleted by the Solvable passed to the ctor.
Definition: WhatObsoletes.h:38
zypp::sat::WhatObsoletes::end
const_iterator end() const
Iterator pointing behind the last Solvable.
Definition: WhatObsoletes.h:87
zypp::Capabilities::size_type
unsigned size_type
Definition: Capabilities.h:39
for_
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:28
zypp::sat::Solvable::obsoletes
Capabilities obsoletes() const
Definition: Solvable.cc:484
PoolItem.h
zypp::sat::WhatObsoletes::ctorAdd
void ctorAdd(const PoolItem &item_r)
Definition: WhatObsoletes.cc:72
str
String related utilities and Regular expression matching.
Hash.h
WhatObsoletes.h
zypp::Capabilities::empty
bool empty() const
Whether the container is empty.
Definition: Capabilities.h:62
zypp::Capabilities
Container of Capability (currently read only).
Definition: Capabilities.h:36
zypp::sat::WhatObsoletes::begin
const_iterator begin() const
Iterator pointing to the first Solvable.
Definition: WhatObsoletes.h:83
zypp::sat::WhatObsoletes::size
size_type size() const
Number of solvables inside.
Definition: WhatObsoletes.cc:148