- add Target::baseProduct for convenence. disable flavor header for now
[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/DefaultFalseBool.h"
22 #include "zypp/base/PtrTypes.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/TargetException.h"
31 #include "zypp/target/RequestedLocalesFile.h"
32 #include "zypp/target/SoftLocksFile.h"
33 #include "zypp/target/HardLocksFile.h"
34
35 ///////////////////////////////////////////////////////////////////
36 namespace zypp
37 { /////////////////////////////////////////////////////////////////
38   ///////////////////////////////////////////////////////////////////
39   namespace target
40   { /////////////////////////////////////////////////////////////////
41
42     DEFINE_PTR_TYPE(TargetImpl);
43
44     ///////////////////////////////////////////////////////////////////
45     //
46     //  CLASS NAME : TargetImpl
47     //
48     /** Base class for concrete Target implementations.
49      *
50      * Constructed by \ref TargetFactory. Public access via \ref Target
51      * interface.
52     */
53     class TargetImpl : public base::ReferenceCounted, private base::NonCopyable
54     {
55       friend std::ostream & operator<<( std::ostream & str, const TargetImpl & obj );
56
57     public:
58       /** list of pool items  */
59       typedef std::list<PoolItem> PoolItemList;
60
61       /** set of pool items  */
62       typedef std::set<PoolItem> PoolItemSet;
63
64     public:
65       /** Ctor. */
66       TargetImpl(const Pathname & root_r = "/", bool doRebuild_r = false );
67       /** Dtor. */
68       virtual ~TargetImpl();
69
70       /** Null implementation */
71       static TargetImpl_Ptr nullimpl();
72
73       void load();
74
75       void unload();
76
77       void clearCache();
78
79       void buildCache();
80
81       std::string anonymousUniqueId() const;
82
83     public:
84
85       /** The root set for this target */
86       Pathname root() const
87       { return _root; }
88
89       /** The directory to store things. */
90       Pathname home() const
91       { return _root / "/var/lib/zypp"; }
92
93       /** Commit changes in the pool */
94       ZYppCommitResult commit( ResPool pool_r, const ZYppCommitPolicy & policy_r );
95
96       ZYPP_DEPRECATED int commit( ResPool pool_r, unsigned int medianr,
97                                   PoolItemList & errors_r,
98                                   PoolItemList & remaining_r,
99                                   PoolItemList & srcremaining_r,
100                                   bool dry_run = false )
101       {
102         ZYppCommitPolicy policy;
103         policy.restrictToMedia( medianr ).dryRun( dry_run );
104         ZYppCommitResult res = commit( pool_r, policy );
105         errors_r.swap( res._errors );
106         remaining_r.swap( res._remaining );
107         srcremaining_r.swap( res._srcremaining );
108         return res._result;
109       }
110
111       /** Commit ordered changes
112        *  @param pool_r only needed for #160792
113        *  @return uncommitted ones (due to error)
114        */
115       PoolItemList commit( const PoolItemList & items_r, const ZYppCommitPolicy & policy_r, const ResPool & pool_r );
116
117       /** Install a source package on the Target. */
118       void installSrcPackage( const SrcPackage_constPtr & srcPackage_r );
119
120       /** Overload to realize stream output. */
121       virtual std::ostream & dumpOn( std::ostream & str ) const
122       {
123         return str << "TargetImpl";
124       }
125
126       /** The RPM database */
127       rpm::RpmDb & rpm();
128
129       /** If the package is installed and provides the file
130       Needed to evaluate split provides during Resolver::Upgrade() */
131       bool providesFile (const std::string & path_str, const std::string & name_str) const;
132
133       /** Return name of package owning \a path_str
134        * or empty string if no installed package owns \a path_str. */
135       std::string whoOwnsFile (const std::string & path_str) const
136       { return _rpm.whoOwnsFile (path_str); }
137
138       /** return the last modification date of the target */
139       Date timestamp() const;
140
141       /** \copydoc Target::baseProduct() */
142       Product::constPtr baseProduct() const;
143
144       /** \copydoc Target::release() */
145       std::string release() const;
146
147       /** \copydoc Target::targetDistribution() */
148       std::string targetDistribution() const;
149
150       /** \copydoc Target::targetDistributionRelease()*/
151       std::string targetDistributionRelease() const;
152
153       /** \copydoc Target::distributionVersion()*/
154       std::string distributionVersion() const;
155
156     protected:
157       /** Path to the target */
158       Pathname _root;
159       /** RPM database */
160       rpm::RpmDb _rpm;
161       /** Requested Locales database */
162       RequestedLocalesFile _requestedLocalesFile;
163       /** Soft-locks database */
164       SoftLocksFile _softLocksFile;
165       /** Hard-Locks database */
166       HardLocksFile _hardLocksFile;
167       /** Cache distributionVersion */
168       mutable std::string _distributionVersion;
169     private:
170       /** Null implementation */
171       static TargetImpl_Ptr _nullimpl;
172     };
173     ///////////////////////////////////////////////////////////////////
174
175     /** \relates TargetImpl Stream output */
176     inline std::ostream & operator<<( std::ostream & str, const TargetImpl & obj )
177     {
178       return obj.dumpOn( str );
179     }
180
181     /////////////////////////////////////////////////////////////////
182   } // namespace target
183   ///////////////////////////////////////////////////////////////////
184   /////////////////////////////////////////////////////////////////
185 } // namespace zypp
186 ///////////////////////////////////////////////////////////////////
187 #endif // ZYPP_TARGET_TARGETIMPL_H