merge make-it-cool
[platform/upstream/libzypp.git] / zypp / target / TargetImpl.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/target/TargetImpl.h
10  *
11 */
12 #ifndef ZYPP_TARGET_TARGETIMPL_H
13 #define ZYPP_TARGET_TARGETIMPL_H
14
15 #include <iosfwd>
16 #include <list>
17 #include <set>
18
19 #include "zypp/base/ReferenceCounted.h"
20 #include "zypp/base/NonCopyable.h"
21 #include "zypp/base/PtrTypes.h"
22 #include "zypp/ResStore.h"
23 #include "zypp/PoolItem.h"
24 #include "zypp/ZYppCommit.h"
25
26 #include "zypp/Pathname.h"
27 #include "zypp/media/MediaAccess.h"
28 #include "zypp/Target.h"
29 #include "zypp/target/rpm/RpmDb.h"
30 #include "zypp/target/store/PersistentStorage.h"
31 #include "zypp/target/TargetException.h"
32
33 ///////////////////////////////////////////////////////////////////
34 namespace zypp
35 { /////////////////////////////////////////////////////////////////
36   ///////////////////////////////////////////////////////////////////
37   namespace target
38   { /////////////////////////////////////////////////////////////////
39
40     DEFINE_PTR_TYPE(TargetImpl);
41
42     ///////////////////////////////////////////////////////////////////
43     //
44     //  CLASS NAME : TargetImpl
45     //
46     /** Base class for concrete Target implementations.
47      *
48      * Constructed by \ref TargetFactory. Public access via \ref Target
49      * interface.
50     */
51     class TargetImpl : public base::ReferenceCounted, private base::NonCopyable
52     {
53       friend std::ostream & operator<<( std::ostream & str, const TargetImpl & obj );
54
55     public:
56       /** list of pool items  */
57       typedef std::list<PoolItem_Ref> PoolItemList;
58
59       /** set of pool items  */
60       typedef std::set<PoolItem_Ref> PoolItemSet;
61
62     public:
63       /** JUST FOR TESTSUITE */
64       /** Sort according to prereqs and media numbers */
65       void getResolvablesToInsDel ( const ResPool pool_r,
66                                     PoolItemList & dellist_r,
67                                     PoolItemList & instlist_r,
68                                     PoolItemList & srclist_r ) const;
69
70
71     public:
72       /** Ctor. */
73       TargetImpl(const Pathname & root_r = "/");
74       /** Dtor. */
75       virtual ~TargetImpl();
76
77       /** Null implementation */
78       static TargetImpl_Ptr nullimpl();
79
80     public:
81
82       /** All resolvables in the target. */
83       const ResStore & resolvables();
84
85       /** The root set for this target */
86       Pathname root() const;
87
88       /** Commit changes in the pool */
89       ZYppCommitResult commit( ResPool pool_r, const ZYppCommitPolicy & policy_r );
90
91       ZYPP_DEPRECATED int commit( ResPool pool_r, unsigned int medianr,
92                                   PoolItemList & errors_r,
93                                   PoolItemList & remaining_r,
94                                   PoolItemList & srcremaining_r,
95                                   bool dry_run = false )
96       {
97         ZYppCommitPolicy policy;
98         policy.restrictToMedia( medianr ).dryRun( dry_run );
99         ZYppCommitResult res = commit( pool_r, policy );
100         errors_r.swap( res._errors );
101         remaining_r.swap( res._remaining );
102         srcremaining_r.swap( res._srcremaining );
103         return res._result;
104       }
105
106       /** enables the storage target */
107       bool isStorageEnabled() const;
108       void enableStorage(const Pathname &root_r);
109
110       /** Commit ordered changes
111        *  @param pool_r only needed for #160792
112        *  @return uncommitted ones (due to error)
113        */
114       PoolItemList commit( const PoolItemList & items_r, const ZYppCommitPolicy & policy_r, const ResPool & pool_r );
115
116       /** Overload to realize stream output. */
117       virtual std::ostream & dumpOn( std::ostream & str ) const
118       { return str << "TargetImpl"; }
119
120       /** The RPM database */
121       rpm::RpmDb & rpm();
122
123       /** If the package is installed and provides the file
124           Needed to evaluate split provides during Resolver::Upgrade() */
125       bool providesFile (const std::string & path_str, const std::string & name_str) const;
126
127       /** Return the resolvable which provides path_str (rpm -qf)
128           return NULL if no resolvable provides this file  */
129       ResObject::constPtr whoOwnsFile (const std::string & path_str) const;
130
131       /** Set the log file for target */
132       bool setInstallationLogfile(const Pathname & path_r);
133
134       /** return the last modification date of the target */
135       Date timestamp() const;
136       
137     protected:
138       /** All resolvables provided by the target. */
139       ResStore _store;
140       /** Path to the target */
141       Pathname _root;
142       /** RPM database */
143       rpm::RpmDb _rpm;
144 #ifndef STORAGE_DISABLED
145       zypp::storage::PersistentStorage _storage;
146       bool _storage_enabled;
147 #endif
148     private:
149       /** Null implementation */
150       static TargetImpl_Ptr _nullimpl;
151     };
152     ///////////////////////////////////////////////////////////////////
153
154     /** \relates TargetImpl Stream output */
155     inline std::ostream & operator<<( std::ostream & str, const TargetImpl & obj )
156     { return obj.dumpOn( str ); }
157
158     /////////////////////////////////////////////////////////////////
159   } // namespace target
160   ///////////////////////////////////////////////////////////////////
161   /////////////////////////////////////////////////////////////////
162 } // namespace zypp
163 ///////////////////////////////////////////////////////////////////
164 #endif // ZYPP_TARGET_TARGETIMPL_H