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