backup
[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     class CommitPackageCache;
44
45     ///////////////////////////////////////////////////////////////////
46     //
47     //  CLASS NAME : TargetImpl
48     //
49     /** Base class for concrete Target implementations.
50      *
51      * Constructed by \ref TargetFactory. Public access via \ref Target
52      * interface.
53     */
54     class TargetImpl : public base::ReferenceCounted, private base::NonCopyable
55     {
56       friend std::ostream & operator<<( std::ostream & str, const TargetImpl & obj );
57
58     public:
59       /** list of pool items  */
60       typedef std::list<PoolItem> PoolItemList;
61
62       /** set of pool items  */
63       typedef std::set<PoolItem> PoolItemSet;
64
65     public:
66       /** Ctor. */
67       TargetImpl(const Pathname & root_r = "/", bool doRebuild_r = false );
68       /** Dtor. */
69       virtual ~TargetImpl();
70
71       /** Null implementation */
72       static TargetImpl_Ptr nullimpl();
73
74       /**
75        * generates the unique anonymous id which is called
76        * when creating the target
77        */
78       void createAnonymousId() const;
79
80       /**
81        * generates a cache of the last product flavor
82        */
83       void createLastDistributionFlavorCache() const;
84
85       /** \name Solv file handling.
86        * If target solv file is outdated, but (non-root-)user has
87        * no permission to  create it at the default location, we
88        * use a temporary one.
89        */
90       //@{
91     private:
92       /** The systems default solv file location. */
93       Pathname defaultSolvfilesPath() const;
94
95       /** The solv file location actually in use (default or temp). */
96       Pathname solvfilesPath() const
97       { return solvfilesPathIsTemp() ? _tmpSolvfilesPath : defaultSolvfilesPath(); }
98
99       /** Whether we're using a temp. solvfile. */
100       bool solvfilesPathIsTemp() const
101       { return ! _tmpSolvfilesPath.empty(); }
102
103       Pathname _tmpSolvfilesPath;
104
105     public:
106       void load();
107
108       void unload();
109
110       void clearCache();
111
112       void buildCache();
113       //@}
114
115       std::string anonymousUniqueId() const;
116
117     public:
118
119       /** The root set for this target */
120       Pathname root() const
121       { return _root; }
122
123       /** The directory to store things. */
124       Pathname home() const
125       { return _root / "/var/lib/zypp"; }
126
127       /** Commit changes in the pool */
128       ZYppCommitResult commit( ResPool pool_r, const ZYppCommitPolicy & policy_r );
129
130       ZYPP_DEPRECATED int commit( ResPool pool_r, unsigned int medianr,
131                                   PoolItemList & errors_r,
132                                   PoolItemList & remaining_r,
133                                   PoolItemList & srcremaining_r,
134                                   bool dry_run = false )
135       {
136         ZYppCommitPolicy policy;
137         policy.restrictToMedia( medianr ).dryRun( dry_run );
138         ZYppCommitResult res = commit( pool_r, policy );
139         errors_r.swap( res._errors );
140         remaining_r.swap( res._remaining );
141         srcremaining_r.swap( res._srcremaining );
142         return res._result;
143       }
144
145       /** Commit ordered changes
146        *  @param packageCache_r Access to the package provider
147        *  @return uncommitted ones (due to error)
148        */
149       PoolItemList commit( const PoolItemList & items_r, const ZYppCommitPolicy & policy_r,
150                            CommitPackageCache & packageCache_r );
151
152       /** Install a source package on the Target. */
153       void installSrcPackage( const SrcPackage_constPtr & srcPackage_r );
154
155       /** Overload to realize stream output. */
156       virtual std::ostream & dumpOn( std::ostream & str ) const
157       {
158         return str << "TargetImpl";
159       }
160
161       /** The RPM database */
162       rpm::RpmDb & rpm();
163
164       /** If the package is installed and provides the file
165       Needed to evaluate split provides during Resolver::Upgrade() */
166       bool providesFile (const std::string & path_str, const std::string & name_str) const;
167
168       /** Return name of package owning \a path_str
169        * or empty string if no installed package owns \a path_str. */
170       std::string whoOwnsFile (const std::string & path_str) const
171       { return _rpm.whoOwnsFile (path_str); }
172
173       /** return the last modification date of the target */
174       Date timestamp() const;
175
176       /** \copydoc Target::baseProduct() */
177       Product::constPtr baseProduct() const;
178
179       /** \copydoc Target::release() */
180       std::string release() const;
181
182       /** \copydoc Target::targetDistribution() */
183       std::string targetDistribution() const;
184
185       /** \copydoc Target::targetDistributionRelease()*/
186       std::string targetDistributionRelease() const;
187
188       /** \copydoc Target::distributionVersion()*/
189       std::string distributionVersion() const;
190
191       /** \copydoc Target::distributionFlavor() */
192       std::string distributionFlavor() const;
193
194     protected:
195       /** Path to the target */
196       Pathname _root;
197       /** RPM database */
198       rpm::RpmDb _rpm;
199       /** Requested Locales database */
200       RequestedLocalesFile _requestedLocalesFile;
201       /** Soft-locks database */
202       SoftLocksFile _softLocksFile;
203       /** Hard-Locks database */
204       HardLocksFile _hardLocksFile;
205       /** Cache distributionVersion */
206       mutable std::string _distributionVersion;
207     private:
208       /** Null implementation */
209       static TargetImpl_Ptr _nullimpl;
210     };
211     ///////////////////////////////////////////////////////////////////
212
213     /** \relates TargetImpl Stream output */
214     inline std::ostream & operator<<( std::ostream & str, const TargetImpl & obj )
215     {
216       return obj.dumpOn( str );
217     }
218
219     /////////////////////////////////////////////////////////////////
220   } // namespace target
221   ///////////////////////////////////////////////////////////////////
222   /////////////////////////////////////////////////////////////////
223 } // namespace zypp
224 ///////////////////////////////////////////////////////////////////
225 #endif // ZYPP_TARGET_TARGETIMPL_H