c6e86cff8577a84fd80f6ecb698bc8d1a5c8f0b4
[platform/upstream/libzypp.git] / zypp / ZYppCommitResult.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/ZYppCommitResult.h
10  *
11 */
12 #ifndef ZYPP_ZYPPCOMMITRESULT_H
13 #define ZYPP_ZYPPCOMMITRESULT_H
14
15 #include <iosfwd>
16 #include <vector>
17 #include <list>
18
19 #include "zypp/PoolItem.h"
20 #include "zypp/sat/Transaction.h"
21 #include "zypp/base/DefaultIntegral.h"
22
23 ///////////////////////////////////////////////////////////////////
24 namespace zypp
25 { /////////////////////////////////////////////////////////////////
26
27   namespace sat
28   {
29     class Transaction;
30   }
31
32   /** Pair of \ref sat::Solvable and \ref Pathname. */
33   class UpdateNotificationFile
34   {
35     public:
36       UpdateNotificationFile( sat::Solvable solvable_r, const Pathname & file_r )
37       : _solvable( solvable_r ), _file( file_r )
38       {}
39     public:
40       sat::Solvable solvable() const { return _solvable; }
41       const Pathname & file() const { return _file; }
42     private:
43       sat::Solvable _solvable;
44       Pathname      _file;
45   };
46
47   typedef std::list<UpdateNotificationFile> UpdateNotifications;
48
49   ///////////////////////////////////////////////////////////////////
50   //
51   //    CLASS NAME : ZYppCommitResult
52   //
53   /** Result returned from ZYpp::commit.
54    *
55    * \note Transaction data are provided and maintained during commit.
56    * Though the interface does not inhibit manipulation of transaction
57    * data outside commit (those methods could have been made \c private:),
58    * this is not recommended as you may easily mess up things.
59    *
60    * \see \ref ZYpp::commit
61    */
62   class ZYppCommitResult
63   {
64     public:
65       typedef std::vector<sat::Transaction::Step> TransactionStepList;
66
67     public:
68       ZYppCommitResult();
69       ZYppCommitResult( const ZYppCommitResult & lhs_r );
70       ZYppCommitResult( const Pathname & root_r );
71       ~ZYppCommitResult();
72
73     public:
74       /** Remembered root directory of the target.
75        *  \Note Pathnames within this class are relative to the
76        * targets root directory.
77       */
78       const Pathname & root() const;
79
80       /** \c True if at least one attempt to actually install/remove packages was made.
81        * While this is false there should have been no serious modifications to the system.
82        * Mainly used to detect whether commit failed while preloading the caches or within
83        * the real action.
84        */
85       bool attemptToModify() const;
86
87       /** Set \ref attemptToModify */
88       void attemptToModify( bool yesno_r );
89
90       /** The full transaction list.
91        * The complete list including transaction steps that do not require
92        * any action (like obsoletes or non-package actions). Depending on
93        * \ref ZYppCommitPolicy::restrictToMedia only a subset of this
94        * transaction might have been executed.
95        * \see \ref transactionStepList.
96        */
97       const sat::Transaction & transaction() const;
98
99       /** Manipulate \ref transaction */
100       sat::Transaction & rTransaction();
101
102       /** List of \ref sat::Transaction::Step to be executed by commit.
103        * The list of transaction step commit actually tried to execute.
104        */
105       const TransactionStepList & transactionStepList() const;
106
107       /** Manipulate \ref transactionStepList. */
108       TransactionStepList & rTransactionStepList();
109
110       /** List of update messages installed during this commit.
111        * \Note Pathnames are relative to the targets root directory.
112        * \code
113        *   ZYppCommitResult result;
114        *   ...
115        *   if ( ! result.updateMessages().empty() )
116        *   {
117        *     MIL << "Received " << result.updateMessages().size() << " update notification(s):" << endl;
118        *     for_( it, result.updateMessages().begin(), result.updateMessages().end() )
119        *     {
120        *       MIL << "- From " << it->solvable().asString() << " in file " << Pathname::showRootIf( result.root(), it->file() ) << ":" << endl;
121        *       {
122        *         // store message files content in a string:
123        *         InputStream istr( Pathname::assertprefix( result.root(), it->file() ) );
124        *         std::ostringstream strstr;
125        *         iostr::copy( istr, strstr );
126        *         std::string message( strstr.str() ); // contains the message
127        *       }
128        *       {
129        *         // or write out the message file indented:
130        *         InputStream istr( Pathname::assertprefix( result.root(), it->file() ) );
131        *         iostr::copyIndent( istr, MIL, "> " ) << endl;
132        *       }
133        *     }
134        *   }
135        * \endcode
136        */
137       const UpdateNotifications & updateMessages() const;
138
139       /** Manipulate \ref updateMessages
140        * \Note Pathnames are relative to the targets root directory.
141        */
142       UpdateNotifications & rUpdateMessages();
143
144     public:
145
146       /** \name Some statistics based on \ref Transaction
147        *
148        * Class \ref Transaction allows to count and iterate the action steps to
149        * get more detailed information about the transaction result. Here are just
150        * a few convenience methods for easy evaluation.
151        *
152        * \code
153        *    ZYppCommitResult result;
154        *    const sat::Transaction & trans( result.transaction() );
155        *    for_( it, trans.actionBegin(~sat::Transaction::STEP_DONE), trans.actionEnd() )
156        *    {
157        *       // process all steps not DONE (ERROR and TODO)
158        *       if ( it->satSolvable() )
159        *         std::cout << it->satSolvable() << endl;
160        *       else // deleted @System solvable: print post mortem data available
161        *         std::cout << it->ident() << endl;
162        *    }
163        * \endcode
164        * \see \ref Transaction, \ref transaction()
165        */
166       //@{
167         /** Whether all steps were performed successfully (none skipped or error) */
168         bool allDone() const
169         { return transaction().actionEmpty( ~sat::Transaction::STEP_DONE ); }
170
171         /** Whether an error ocurred (skipped streps are ok). */
172         bool noError() const
173         { return transaction().actionEmpty( sat::Transaction::STEP_ERROR ); }
174       //@}
175
176     public:
177       /** Implementation  */
178       class Impl;
179     private:
180       /** Pointer to data. */
181       RWCOW_pointer<Impl> _pimpl;
182   };
183   ///////////////////////////////////////////////////////////////////
184
185   /** \relates ZYppCommitResult Stream output. */
186   std::ostream & operator<<( std::ostream & str, const ZYppCommitResult & obj );
187
188   /////////////////////////////////////////////////////////////////
189 } // namespace zypp
190 ///////////////////////////////////////////////////////////////////
191 #endif // ZYPP_ZYPPCOMMITRESULT_H