libzypp  17.5.0
PoolItem.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #include <iostream>
13 #include "zypp/base/Logger.h"
15 
16 #include "zypp/PoolItem.h"
17 #include "zypp/ResPool.h"
18 #include "zypp/Package.h"
19 #include "zypp/VendorAttr.h"
20 
21 using std::endl;
22 
24 namespace zypp
25 {
26 
28  //
29  // CLASS NAME : PoolItem::Impl
30  //
38  {
39  public:
40  Impl() {}
41 
43  const ResStatus & status_r )
44  : _status( status_r )
45  , _resolvable( res_r )
46  {}
47 
48  ResStatus & status() const
49  { return _buddy > 0 ? PoolItem(buddy()).status() : _status; }
50 
52  {
53  if ( !_buddy )
55  if ( _buddy < 0 )
56  return sat::Solvable( -_buddy );
57  return sat::Solvable( _buddy );
58  }
59 
60  void setBuddy( const sat::Solvable & solv_r );
61 
63  { return _resolvable; }
64 
66  {
69  return _status;
70  }
71 
72  public:
73  bool isUndetermined() const
74  {
75  return status().isUndetermined();
76  }
77 
78  bool isRelevant() const
79  {
80  return !status().isNonRelevant();
81  }
82 
83  bool isSatisfied() const
84  {
85  return status().isSatisfied();
86  }
87 
88  bool isBroken() const
89  {
90  return status().isBroken();
91  }
92 
93  bool isNeeded() const
94  {
95  return status().isToBeInstalled() || ( isBroken() && ! status().isLocked() );
96  }
97 
98  bool isUnwanted() const
99  {
100  return isBroken() && status().isLocked();
101  }
102 
103  private:
107 
112  public:
113  void saveState() const
114  { _savedStatus = status(); }
115  void restoreState() const
116  { status() = _savedStatus; }
117  bool sameState() const
118  {
119  if ( status() == _savedStatus )
120  return true;
121  // some bits changed...
122  if ( status().getTransactValue() != _savedStatus.getTransactValue()
123  && ( ! status().isBySolver() // ignore solver state changes
124  // removing a user lock also goes to bySolver
126  return false;
128  return false;
129  return true;
130  }
131  private:
134 
135  public:
137  static shared_ptr<Impl> nullimpl()
138  {
139  static shared_ptr<Impl> _nullimpl( new Impl );
140  return _nullimpl;
141  }
142  };
144 
146  inline std::ostream & operator<<( std::ostream & str, const PoolItem::Impl & obj )
147  {
148  str << obj.status();
149  if (obj.resolvable())
150  str << *obj.resolvable();
151  else
152  str << "(NULL)";
153  return str;
154  }
155 
156  inline void PoolItem::Impl::setBuddy( const sat::Solvable & solv_r )
157  {
158  PoolItem myBuddy( solv_r );
159  if ( myBuddy )
160  {
161  if ( myBuddy._pimpl->_buddy )
162  {
163  ERR << *this << " would be buddy2 in " << myBuddy << endl;
164  return;
165  }
166  myBuddy._pimpl->_buddy = -resolvable()->satSolvable().id();
167  _buddy = myBuddy.satSolvable().id();
168  DBG << *this << " has buddy " << myBuddy << endl;
169  }
170  }
171 
173  // class PoolItem
175 
177  : _pimpl( Impl::nullimpl() )
178  {}
179 
180  PoolItem::PoolItem( const sat::Solvable & solvable_r )
181  : _pimpl( ResPool::instance().find( solvable_r )._pimpl )
182  {}
183 
184  PoolItem::PoolItem( const ResObject::constPtr & resolvable_r )
185  : _pimpl( ResPool::instance().find( resolvable_r )._pimpl )
186  {}
187 
188  PoolItem::PoolItem( Impl * implptr_r )
189  : _pimpl( implptr_r )
190  {}
191 
193  {
194  return PoolItem( new Impl( makeResObject( solvable_r ), solvable_r.isSystem() ) );
195  }
196 
198  {}
199 
201  { return ResPool::instance(); }
202 
203 
204  ResStatus & PoolItem::status() const { return _pimpl->status(); }
206  sat::Solvable PoolItem::buddy() const { return _pimpl->buddy(); }
207  void PoolItem::setBuddy( const sat::Solvable & solv_r ) { _pimpl->setBuddy( solv_r ); }
208  bool PoolItem::isUndetermined() const { return _pimpl->isUndetermined(); }
209  bool PoolItem::isRelevant() const { return _pimpl->isRelevant(); }
210  bool PoolItem::isSatisfied() const { return _pimpl->isSatisfied(); }
211  bool PoolItem::isBroken() const { return _pimpl->isBroken(); }
212  bool PoolItem::isNeeded() const { return _pimpl->isNeeded(); }
213  bool PoolItem::isUnwanted() const { return _pimpl->isUnwanted(); }
214  void PoolItem::saveState() const { _pimpl->saveState(); }
216  bool PoolItem::sameState() const { return _pimpl->sameState(); }
218 
219 
220  std::ostream & operator<<( std::ostream & str, const PoolItem & obj )
221  { return str << *obj._pimpl; }
222 
223 } // namespace zypp
bool isBroken() const
Definition: PoolItem.cc:88
A Solvable object within the sat Pool.
Definition: Solvable.h:53
PoolItem()
Default ctor for use in std::container.
Definition: PoolItem.cc:176
IdType id() const
Expert backdoor.
Definition: Solvable.h:385
DefaultIntegral< sat::detail::IdType, sat::detail::noId > _buddy
Definition: PoolItem.cc:106
bool sameState() const
Definition: PoolItem.cc:216
bool isToBeInstalled() const
Definition: ResStatus.h:244
void setBuddy(const sat::Solvable &solv_r)
Buddies are set by pool::PoolImpl.
Definition: PoolItem.cc:207
bool isNonRelevant() const
Definition: ResStatus.h:225
ResStatus & status() const
Returns the current status.
Definition: PoolItem.cc:204
String related utilities and Regular expression matching.
sat::Solvable buddy() const
Return the buddy we share our status object with.
Definition: PoolItem.cc:206
bool isBroken() const
Definition: ResStatus.h:222
TransactValue getTransactValue() const
Definition: ResStatus.h:270
std::ostream & operator<<(std::ostream &str, const PoolItem::Impl &obj)
Definition: PoolItem.cc:146
bool sameState() const
Definition: PoolItem.cc:117
void saveState() const
Definition: PoolItem.cc:113
bool resetTransact(TransactByValue causer_r)
Not the same as setTransact( false ).
Definition: ResStatus.h:476
~PoolItem()
Dtor.
Definition: PoolItem.cc:197
bool isSatisfied() const
Whether a relevant items requirements are met.
Definition: PoolItem.cc:210
TraitsType::constPtrType constPtr
Definition: ResObject.h:44
void setBuddy(const sat::Solvable &solv_r)
Definition: PoolItem.cc:156
bool isRelevant() const
Definition: PoolItem.cc:78
bool isNeeded() const
Definition: PoolItem.cc:93
ResObject::constPtr resolvable() const
Returns the ResObject::constPtr.
Definition: PoolItem.cc:217
#define ERR
Definition: Logger.h:66
static const Solvable noSolvable
Represents no Solvable.
Definition: Solvable.h:71
Impl(ResObject::constPtr res_r, const ResStatus &status_r)
Definition: PoolItem.cc:42
ResStatus _savedStatus
Definition: PoolItem.cc:132
bool isBroken() const
Whether a relevant items requirements are broken.
Definition: PoolItem.cc:211
bool isUndetermined() const
Definition: PoolItem.cc:73
ResStatus & statusReset() const
Reset status.
Definition: PoolItem.cc:205
std::ostream & operator<<(std::ostream &str, const Exception &obj)
Definition: Exception.cc:147
static shared_ptr< Impl > nullimpl()
Offer default Impl.
Definition: PoolItem.cc:137
bool isUndetermined() const
No validation is performed for packages.
Definition: PoolItem.cc:208
PoolItem implementation.
Definition: PoolItem.cc:37
void restoreState() const
Definition: PoolItem.cc:215
bool isSatisfied() const
Definition: ResStatus.h:219
static PoolItem makePoolItem(const sat::Solvable &solvable_r)
PoolItem generator for pool::PoolImpl.
Definition: PoolItem.cc:192
bool setLock(bool toLock_r, TransactByValue causer_r)
Apply a lock (prevent transaction).
Definition: ResStatus.h:379
void restoreState() const
Definition: PoolItem.cc:115
bool isSystem() const
Return whether this Solvable belongs to the system repo.
Definition: Solvable.cc:369
ResObject::constPtr _resolvable
Definition: PoolItem.cc:105
bool isRelevant() const
Returns true if the solvable is relevant which means e.g.
Definition: PoolItem.cc:209
ResStatus & statusReset() const
Definition: PoolItem.cc:65
ResStatus & status() const
Definition: PoolItem.cc:48
bool isLicenceConfirmed() const
Definition: ResStatus.h:175
ResPool pool() const
Return the ResPool the item belongs to.
Definition: PoolItem.cc:200
Global ResObject pool.
Definition: ResPool.h:60
bool isUndetermined() const
Definition: ResStatus.h:216
bool isUnwanted() const
Definition: PoolItem.cc:98
bool isSatisfied() const
Definition: PoolItem.cc:83
bool isLocked() const
Definition: ResStatus.h:255
ResObject::constPtr resolvable() const
Definition: PoolItem.cc:62
Status bitfield.
Definition: ResStatus.h:53
bool isNeeded() const
This includes unlocked broken patches, as well as those already selected to be installed (otherwise c...
Definition: PoolItem.cc:212
ResObject::Ptr makeResObject(const sat::Solvable &solvable_r)
Create ResObject from sat::Solvable.
Definition: ResObject.cc:44
Combining sat::Solvable and ResStatus.
Definition: PoolItem.h:50
sat::Solvable buddy() const
Definition: PoolItem.cc:51
bool isUnwanted() const
Broken (needed) but locked patches.
Definition: PoolItem.cc:213
RW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: PoolItem.h:151
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
Solvable satSolvable() const
Return the corresponding sat::Solvable.
Definition: SolvableType.h:57
bool isBySolver() const
Definition: ResStatus.h:281
#define DBG
Definition: Logger.h:63
void saveState() const
Definition: PoolItem.cc:214
static ResPool instance()
Singleton ctor.
Definition: ResPool.cc:33