1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/sat/Transaction.h
11 #ifndef ZYPP_SAT_TRANSACTION_H
12 #define ZYPP_SAT_TRANSACTION_H
16 #include "zypp/base/PtrTypes.h"
17 #include "zypp/base/Flags.h"
18 #include "zypp/base/Iterator.h"
19 #include "zypp/base/DefaultIntegral.h"
21 #include "zypp/sat/SolvIterMixin.h"
22 #include "zypp/sat/Solvable.h"
23 #include "zypp/sat/Queue.h"
25 #include "zypp/PoolItem.h"
27 ///////////////////////////////////////////////////////////////////
29 { /////////////////////////////////////////////////////////////////
30 ///////////////////////////////////////////////////////////////////
32 { /////////////////////////////////////////////////////////////////
36 /** Needs to be outside \ref Transaction in order to be usable in SolvIterMixin. */
37 class Transaction_iterator;
38 /** Needs to be outside \ref Transaction in order to be usable in SolvIterMixin. */
39 class Transaction_const_iterator;
42 /** Libsolv transaction wrapper.
43 * \note Note that Transaction is derived from \ref sat::SolvIterMixin which
44 * makes PoolItem and Selectable iterators automatically available.
45 * \note Changing the \ref ResPool content (loading/unloading repositories)
46 * invalidates all outstanding transaction data. \see \ref valid.
47 * \note.The transaction may inlude steps of type \ref TRANSACTION_IGNORE which
48 * do not cause/require any specific action. To skip those informal steps
49 * when iterating, use the \ref actionBegin /\ref actionEnd methods.
51 class Transaction : public SolvIterMixin<Transaction, detail::Transaction_const_iterator>
53 friend std::ostream & operator<<( std::ostream & str, const Transaction & obj );
54 friend std::ostream & dumpOn( std::ostream & str, const Transaction & obj );
55 friend bool operator==( const Transaction & lhs, const Transaction & rhs );
58 /** Represents a single step within a \ref Transaction. */
61 /** Type of (rpm) action to perform in a \ref Step. */
64 TRANSACTION_IGNORE = 0x00, /**< [ ] Nothing (includes implicit deletes due to obsoletes and non-package actions) */
65 TRANSACTION_ERASE = 0x10, /**< [-] Delete item */
66 TRANSACTION_INSTALL = 0x20, /**< [+] Install(update) item */
67 TRANSACTION_MULTIINSTALL = 0x30 /**< [M] Install(multiversion) item (\see \ref ZConfig::multiversion) */
70 /** \ref Step action result. */
73 STEP_TODO = (1 << 0), /**< [__] unprocessed */
74 STEP_DONE = (1 << 1), /**< [OK] success */
75 STEP_ERROR = (1 << 2), /**< [**] error */
78 ZYPP_DECLARE_FLAGS(StepStages,StepStage);
81 struct LoadFromPoolType {}; ///< Ctor arg type
82 static constexpr LoadFromPoolType loadFromPool = LoadFromPoolType();
85 /** Default ctor: empty transaction. */
88 /** Ctor loading the default pools transaction. */
89 Transaction( LoadFromPoolType );
95 /** Whether transaction actually contains data and also fits the current pools content. */
98 /** Validate object in a boolean context: valid */
99 explicit operator bool() const
102 /** Order transaction steps for commit.
103 * It's cheap to call it for an aleready ordered \ref Transaction.
104 * This invalidates outstanding iterators. Returns whether
105 * \ref Transaction is \ref valid.
109 /** Whether the transaction contains any steps. */
112 /** Number of steps in transaction steps. */
115 typedef detail::Transaction_iterator iterator;
116 typedef detail::Transaction_const_iterator const_iterator;
118 /** Iterator to the first \ref TransactionStep */
119 const_iterator begin() const;
123 /** Iterator behind the last \ref TransactionStep */
124 const_iterator end() const;
128 /** Return iterator pointing to \a solv_r or \ref end. */
129 const_iterator find( const sat::Solvable & solv_r ) const;
130 iterator find( const sat::Solvable & solv_r );
132 const_iterator find( const ResObject::constPtr & resolvable_r ) const;
133 iterator find( const ResObject::constPtr & resolvable_r );
135 const_iterator find( const PoolItem & pi_r ) const;
136 iterator find( const PoolItem & pi_r );
139 /** \name Iterate action steps (omit TRANSACTION_IGNORE steps).
141 * All these methods allow to pass an optional OR'd combination of
142 * \ref StepStages as filter. Per default all steps are processed/counted.
146 * for_( it, trans.actionBegin(~sat::Transaction::STEP_DONE), trans.actionEnd() )
148 * ... // process all steps not DONE (ERROR and TODO)
154 typedef filter_iterator<FilterAction,const_iterator> action_iterator;
156 /** Whether the [filtered] transaction contains any steps . */
157 bool actionEmpty( StepStages filter_r = StepStages() ) const;
159 /** Number of steps in [filtered] transaction steps. */
160 size_t actionSize( StepStages filter_r = StepStages() ) const;
162 /** Pointer to the 1st action step in [filtered] transaction. */
163 action_iterator actionBegin( StepStages filter_r = StepStages() ) const;
165 /** Pointer behind the last action step in transaction. */
166 action_iterator actionEnd() const;
168 /** Iterate the [filtered] transaction steps. */
169 Iterable<action_iterator> action( StepStages filter_r = StepStages() ) const;
173 /** Return all packages that would be installed after the transaction is run.
174 * The new packages are put at the head of the queue, the number of new
175 * packages is returned. (wraps libsolv::transaction_installedresult) */
176 int installedResult( Queue & result_r ) const;
178 /** Return the ident strings of all packages that would be auto-installed after the transaction is run. */
179 StringQueue autoInstalled() const;
181 /** Set the ident strings of all packages that would be auto-installed after the transaction is run. */
182 void autoInstalled( const StringQueue & queue_r );
185 /** Implementation */
188 /** Pointer to implementation */
189 RW_pointer<Impl> _pimpl;
192 ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Transaction::StepStages);
194 /** \relates Transaction Stream output */
195 std::ostream & operator<<( std::ostream & str, const Transaction & obj );
197 /** \relates Transaction Verbose stream output */
198 std::ostream & dumpOn( std::ostream & str, const Transaction & obj );
200 /** \relates Transaction */
201 bool operator==( const Transaction & lhs, const Transaction & rhs );
203 /** \relates Transaction */
204 inline bool operator!=( const Transaction & lhs, const Transaction & rhs )
205 { return !( lhs == rhs ); }
208 /** A single step within a \ref Transaction.
210 * \note After commit, when the @System repo (rpm database) is reread, all
211 * @System solvables within the transaction are invalidated (they got deleted).
212 * Thats why we internally store the NVRA, so you can access \ref ident
213 * (\see \ref sat::Solvable::ident), \ref edition, \ref arch of a deleted package,
214 * even if the \ref satSolvable itself is meanwhile invalid.
216 * \see \ref Transaction.
218 class Transaction::Step
220 friend std::ostream & operator<<( std::ostream & str, const Step & obj );
224 Step( const RW_pointer<Impl> & pimpl_r, detail::IdType id_r )
230 /** Type of action to perform in this step. */
231 StepType stepType() const;
233 /** Step action result. */
234 StepStage stepStage() const;
236 /** Set step action result. */
237 void stepStage( StepStage val_r );
239 /** Return the corresponding \ref Solvable.
240 * Returns \ref Solvable::noSolvable if the item is meanwhile deleted and
241 * was removed from the pool. \see Post mortem acccess to @System solvables.
243 Solvable satSolvable() const
246 /** \name Post mortem acccess to @System solvables
248 * Transaction::Step step;
249 * if ( step.satSolvable() )
250 * std::cout << step.satSolvable() << endl;
252 * std::cout << step.ident() << endl; // deleted @System solvable
256 /** \see \ref sat::Solvable::ident. */
257 IdString ident() const;
259 /** \see \ref sat::Solvable::edition. */
260 Edition edition() const;
262 /** \see \ref sat::Solvable::arch. */
266 /** Implicit conversion to \ref Solvable */
267 operator const Solvable &() const { return _solv; }
268 /** \overload nonconst */
269 operator Solvable &() { return _solv; }
273 /** Pointer to implementation */
274 RW_pointer<Impl> _pimpl;
277 /** \relates Transaction::Step Stream output */
278 std::ostream & operator<<( std::ostream & str, const Transaction::Step & obj );
280 /** \relates Transaction::StepType Stream output */
281 std::ostream & operator<<( std::ostream & str, Transaction::StepType obj );
283 /** \relates Transaction::StepStage Stream output */
284 std::ostream & operator<<( std::ostream & str, Transaction::StepStage obj );
286 ///////////////////////////////////////////////////////////////////
288 { /////////////////////////////////////////////////////////////////
290 /** \ref Transaction iterator.
292 class Transaction_iterator : public boost::iterator_adaptor<
293 Transaction_iterator // Derived
294 , const detail::IdType * // Base
295 , Transaction::Step // Value
296 , boost::forward_traversal_tag // CategoryOrTraversal
297 , Transaction::Step // Reference
301 Transaction_iterator();
302 Transaction_iterator( const RW_pointer<Transaction::Impl> & pimpl_r, base_type id_r )
303 : Transaction_iterator::iterator_adaptor_( id_r )
308 friend class boost::iterator_core_access;
310 reference dereference() const
311 { return Transaction::Step( _pimpl, *base() ); }
314 friend class Transaction_const_iterator;
315 /** Pointer to implementation */
316 RW_pointer<Transaction::Impl> _pimpl;
319 /** \ref Transaction const_iterator.
321 class Transaction_const_iterator : public boost::iterator_adaptor<
322 Transaction_const_iterator // Derived
323 , const detail::IdType * // Base
324 , const Transaction::Step // Value
325 , boost::forward_traversal_tag // CategoryOrTraversal
326 , const Transaction::Step // Reference
330 Transaction_const_iterator();
331 Transaction_const_iterator( const Transaction_iterator & iter_r );
332 Transaction_const_iterator( const RW_pointer<Transaction::Impl> & pimpl_r, base_type id_r )
333 : Transaction_const_iterator::iterator_adaptor_( id_r )
338 friend class boost::iterator_core_access;
340 reference dereference() const
341 { return Transaction::Step( _pimpl, *base() ); }
344 /** Pointer to implementation */
345 RW_pointer<Transaction::Impl> _pimpl;
348 /////////////////////////////////////////////////////////////////
349 } // namespace detail
350 ///////////////////////////////////////////////////////////////////
352 inline Transaction::const_iterator Transaction::find( const ResObject::constPtr & resolvable_r ) const
353 { return( resolvable_r ? find( resolvable_r->satSolvable() ) : end() ); }
355 inline Transaction::iterator Transaction::find( const ResObject::constPtr & resolvable_r )
356 { return( resolvable_r ? find( resolvable_r->satSolvable() ) : end() ); }
358 inline Transaction::const_iterator Transaction::find( const PoolItem & pi_r ) const
359 { return find( pi_r.satSolvable() ); }
361 inline Transaction::iterator Transaction::find( const PoolItem & pi_r )
362 { return find( pi_r.satSolvable() ); }
365 struct Transaction::FilterAction
368 FilterAction( StepStages filter_r ) : _filter( filter_r ) {}
370 bool operator()( const Transaction::Step & step_r ) const
372 if ( step_r.stepType() == Transaction::TRANSACTION_IGNORE )
373 return false; // no action
374 return !_filter || _filter.testFlag( step_r.stepStage() );
380 inline Transaction::action_iterator Transaction::actionBegin( StepStages filter_r ) const
381 { return make_filter_begin( FilterAction( filter_r ), *this ); }
383 inline Transaction::action_iterator Transaction::actionEnd() const
384 { return make_filter_end( FilterAction(), *this ); }
386 inline bool Transaction::actionEmpty( StepStages filter_r ) const
387 { return( actionBegin( filter_r ) == actionEnd() ); }
389 inline size_t Transaction::actionSize( StepStages filter_r ) const
392 for_( it, actionBegin( filter_r ), actionEnd() )
397 inline Iterable<Transaction::action_iterator> Transaction::action( StepStages filter_r ) const
398 { return makeIterable( actionBegin( filter_r ), actionEnd() ); }
400 /////////////////////////////////////////////////////////////////
402 ///////////////////////////////////////////////////////////////////
403 /////////////////////////////////////////////////////////////////
405 ///////////////////////////////////////////////////////////////////
406 #endif // ZYPP_SAT_TRANSACTION_H