libzypp  13.10.6
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/Tr1hash.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::tr1::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
int IdType
Generic Id type.
Definition: PoolMember.h:82
A Solvable object within the sat Pool.
Definition: Solvable.h:55
Container of Solvable providing a Capability (read only).
Definition: WhatProvides.h:87
Container of Capability (currently read only).
Definition: Capabilities.h:35
std::ostream & operator<<(std::ostream &str, const LocaleSupport &obj)
WhatObsoletes()
Default ctor.
Definition: WhatObsoletes.h:45
Access to the sat-pools string space.
Definition: IdString.h:39
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
Definition: Easy.h:27
TraitsType::constPtrType constPtr
Definition: ResObject.h:50
const sat::detail::IdType * _begin
Definition: WhatObsoletes.h:97
std::ostream & dumpRange(std::ostream &str, _Iterator begin, _Iterator 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
void ctorAdd(const PoolItem &item_r)
const_iterator begin() const
Iterator pointing to the first Solvable.
Definition: WhatObsoletes.h:83
Container of installed Solvable which would be obsoleted by the Solvable passed to the ctor...
Definition: WhatObsoletes.h:36
bool multiversionInstall() const
Whether different versions of this package can be installed at the same time.
Definition: Solvable.cc:392
static const IdType noId(0)
sat::Solvable satSolvable() const
Return the corresponding sat::Solvable.
Definition: PoolItem.h:114
size_type size() const
Number of solvables inside.
Reference to a PoolItem connecting ResObject and ResStatus.
Definition: PoolItem.h:50
IdType id() const
Expert backdoor.
Definition: Solvable.h:296
bool obsoleteUsesProvides
const_iterator end() const
Iterator pointing behind the last Solvable.
Definition: WhatObsoletes.h:87
Capabilities obsoletes() const
Definition: Solvable.cc:439