1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/target/TargetImpl.h
12 #ifndef ZYPP_TARGET_TARGETIMPL_H
13 #define ZYPP_TARGET_TARGETIMPL_H
19 #include "zypp/base/ReferenceCounted.h"
20 #include "zypp/base/NonCopyable.h"
21 #include "zypp/base/PtrTypes.h"
22 #include "zypp/PoolItem.h"
23 #include "zypp/ZYppCommit.h"
25 #include "zypp/Pathname.h"
26 #include "zypp/media/MediaAccess.h"
27 #include "zypp/Target.h"
28 #include "zypp/target/rpm/RpmDb.h"
29 #include "zypp/target/TargetException.h"
30 #include "zypp/target/RequestedLocalesFile.h"
31 #include "zypp/target/SoftLocksFile.h"
32 #include "zypp/target/HardLocksFile.h"
34 ///////////////////////////////////////////////////////////////////
36 { /////////////////////////////////////////////////////////////////
37 ///////////////////////////////////////////////////////////////////
39 { /////////////////////////////////////////////////////////////////
41 DEFINE_PTR_TYPE(TargetImpl);
42 class CommitPackageCache;
44 ///////////////////////////////////////////////////////////////////
46 // CLASS NAME : TargetImpl
48 /** Base class for concrete Target implementations.
50 * Constructed by \ref TargetFactory. Public access via \ref Target
53 class TargetImpl : public base::ReferenceCounted, private base::NonCopyable
55 friend std::ostream & operator<<( std::ostream & str, const TargetImpl & obj );
58 /** list of pool items */
59 typedef std::list<PoolItem> PoolItemList;
61 /** set of pool items */
62 typedef std::set<PoolItem> PoolItemSet;
66 TargetImpl(const Pathname & root_r = "/", bool doRebuild_r = false );
68 virtual ~TargetImpl();
70 /** Null implementation */
71 static TargetImpl_Ptr nullimpl();
74 * generates the unique anonymous id which is called
75 * when creating the target
77 void createAnonymousId() const;
80 * generates a cache of the last product flavor
82 void createLastDistributionFlavorCache() const;
84 /** \name Solv file handling.
85 * If target solv file is outdated, but (non-root-)user has
86 * no permission to create it at the default location, we
87 * use a temporary one.
91 /** The systems default solv file location. */
92 Pathname defaultSolvfilesPath() const;
94 /** The solv file location actually in use (default or temp). */
95 Pathname solvfilesPath() const
96 { return solvfilesPathIsTemp() ? _tmpSolvfilesPath : defaultSolvfilesPath(); }
98 /** Whether we're using a temp. solvfile. */
99 bool solvfilesPathIsTemp() const
100 { return ! _tmpSolvfilesPath.empty(); }
102 Pathname _tmpSolvfilesPath;
116 /** The root set for this target */
117 Pathname root() const
120 /** The directory to store things. */
121 Pathname home() const
122 { return _root / "/var/lib/zypp"; }
124 /** Commit changes in the pool */
125 ZYppCommitResult commit( ResPool pool_r, const ZYppCommitPolicy & policy_r );
127 /** Install a source package on the Target. */
128 void installSrcPackage( const SrcPackage_constPtr & srcPackage_r );
130 /** Overload to realize stream output. */
131 virtual std::ostream & dumpOn( std::ostream & str ) const
133 return str << "TargetImpl";
136 /** The RPM database */
139 /** If the package is installed and provides the file
140 Needed to evaluate split provides during Resolver::Upgrade() */
141 bool providesFile (const std::string & path_str, const std::string & name_str) const;
143 /** Return name of package owning \a path_str
144 * or empty string if no installed package owns \a path_str. */
145 std::string whoOwnsFile (const std::string & path_str) const
146 { return _rpm.whoOwnsFile (path_str); }
148 /** return the last modification date of the target */
149 Date timestamp() const;
151 /** \copydoc Target::baseProduct() */
152 Product::constPtr baseProduct() const;
155 /** \copydoc Target::targetDistribution() */
156 std::string targetDistribution() const;
158 static std::string targetDistribution( const Pathname & root_r );
160 /** \copydoc Target::targetDistributionRelease()*/
161 std::string targetDistributionRelease() const;
163 static std::string targetDistributionRelease( const Pathname & root_r );
165 /** \copydoc Target::distributionVersion()*/
166 Target::DistributionLabel distributionLabel() const;
168 static Target::DistributionLabel distributionLabel( const Pathname & root_r );
170 /** \copydoc Target::distributionVersion()*/
171 std::string distributionVersion() const;
173 static std::string distributionVersion( const Pathname & root_r );
175 /** \copydoc Target::distributionFlavor() */
176 std::string distributionFlavor() const;
178 static std::string distributionFlavor( const Pathname & root_r );
180 /** \copydoc Target::anonymousUniqueId() */
181 std::string anonymousUniqueId() const;
183 static std::string anonymousUniqueId( const Pathname & root_r );
186 /** Commit ordered changes (internal helper) */
187 PoolItemList commit( const PoolItemList & items_r,
188 const ZYppCommitPolicy & policy_r,
189 ZYppCommitResult & result_r,
190 CommitPackageCache & packageCache_r );
193 /** Path to the target */
197 /** Requested Locales database */
198 RequestedLocalesFile _requestedLocalesFile;
199 /** Soft-locks database */
200 SoftLocksFile _softLocksFile;
201 /** Hard-Locks database */
202 HardLocksFile _hardLocksFile;
203 /** Cache distributionVersion */
204 mutable std::string _distributionVersion;
207 /** Null implementation */
208 static TargetImpl_Ptr _nullimpl;
210 ///////////////////////////////////////////////////////////////////
212 /** \relates TargetImpl Stream output */
213 inline std::ostream & operator<<( std::ostream & str, const TargetImpl & obj )
215 return obj.dumpOn( str );
218 /////////////////////////////////////////////////////////////////
219 } // namespace target
220 ///////////////////////////////////////////////////////////////////
221 /////////////////////////////////////////////////////////////////
223 ///////////////////////////////////////////////////////////////////
224 #endif // ZYPP_TARGET_TARGETIMPL_H