backup, trying to get flavor cache working
[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       /** 
74        * generates the unique anonymous id which is called
75        * when creating the target
76        */
77       void createAnonymousId() const;
78
79       /**
80        * generates a cache of the last product flavor
81        */
82       void createLastBaseProductFlavorCache() const;
83
84       void load();
85
86       void unload();
87
88       void clearCache();
89
90       void buildCache();
91
92       std::string anonymousUniqueId() const;
93
94     public:
95
96       /** The root set for this target */
97       Pathname root() const
98       { return _root; }
99
100       /** The directory to store things. */
101       Pathname home() const
102       { return _root / "/var/lib/zypp"; }
103
104       /** Commit changes in the pool */
105       ZYppCommitResult commit( ResPool pool_r, const ZYppCommitPolicy & policy_r );
106
107       ZYPP_DEPRECATED int commit( ResPool pool_r, unsigned int medianr,
108                                   PoolItemList & errors_r,
109                                   PoolItemList & remaining_r,
110                                   PoolItemList & srcremaining_r,
111                                   bool dry_run = false )
112       {
113         ZYppCommitPolicy policy;
114         policy.restrictToMedia( medianr ).dryRun( dry_run );
115         ZYppCommitResult res = commit( pool_r, policy );
116         errors_r.swap( res._errors );
117         remaining_r.swap( res._remaining );
118         srcremaining_r.swap( res._srcremaining );
119         return res._result;
120       }
121
122       /** Commit ordered changes
123        *  @param pool_r only needed for #160792
124        *  @return uncommitted ones (due to error)
125        */
126       PoolItemList commit( const PoolItemList & items_r, const ZYppCommitPolicy & policy_r, const ResPool & pool_r );
127
128       /** Install a source package on the Target. */
129       void installSrcPackage( const SrcPackage_constPtr & srcPackage_r );
130
131       /** Overload to realize stream output. */
132       virtual std::ostream & dumpOn( std::ostream & str ) const
133       {
134         return str << "TargetImpl";
135       }
136
137       /** The RPM database */
138       rpm::RpmDb & rpm();
139
140       /** If the package is installed and provides the file
141       Needed to evaluate split provides during Resolver::Upgrade() */
142       bool providesFile (const std::string & path_str, const std::string & name_str) const;
143
144       /** Return name of package owning \a path_str
145        * or empty string if no installed package owns \a path_str. */
146       std::string whoOwnsFile (const std::string & path_str) const
147       { return _rpm.whoOwnsFile (path_str); }
148
149       /** return the last modification date of the target */
150       Date timestamp() const;
151
152       /** \copydoc Target::baseProduct() */
153       Product::constPtr baseProduct() const;
154
155       /** \copydoc Target::release() */
156       std::string release() const;
157
158       /** \copydoc Target::targetDistribution() */
159       std::string targetDistribution() const;
160
161       /** \copydoc Target::targetDistributionRelease()*/
162       std::string targetDistributionRelease() const;
163
164       /** \copydoc Target::distributionVersion()*/
165       std::string distributionVersion() const;
166
167     protected:
168       /** Path to the target */
169       Pathname _root;
170       /** RPM database */
171       rpm::RpmDb _rpm;
172       /** Requested Locales database */
173       RequestedLocalesFile _requestedLocalesFile;
174       /** Soft-locks database */
175       SoftLocksFile _softLocksFile;
176       /** Hard-Locks database */
177       HardLocksFile _hardLocksFile;
178       /** Cache distributionVersion */
179       mutable std::string _distributionVersion;
180     private:
181       /** Null implementation */
182       static TargetImpl_Ptr _nullimpl;
183     };
184     ///////////////////////////////////////////////////////////////////
185
186     /** \relates TargetImpl Stream output */
187     inline std::ostream & operator<<( std::ostream & str, const TargetImpl & obj )
188     {
189       return obj.dumpOn( str );
190     }
191
192     /////////////////////////////////////////////////////////////////
193   } // namespace target
194   ///////////////////////////////////////////////////////////////////
195   /////////////////////////////////////////////////////////////////
196 } // namespace zypp
197 ///////////////////////////////////////////////////////////////////
198 #endif // ZYPP_TARGET_TARGETIMPL_H