1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/target/TargetImpl.h
12 #ifndef ZYPP_TARGET_TARGETIMPL_H
13 #define ZYPP_TARGET_TARGETIMPL_H
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"
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/SoftLocksFile.h"
31 #include "zypp/target/HardLocksFile.h"
33 ///////////////////////////////////////////////////////////////////
35 { /////////////////////////////////////////////////////////////////
36 ///////////////////////////////////////////////////////////////////
38 { /////////////////////////////////////////////////////////////////
40 DEFINE_PTR_TYPE(TargetImpl);
41 class CommitPackageCache;
43 ///////////////////////////////////////////////////////////////////
45 // CLASS NAME : TargetImpl
47 /** Base class for concrete Target implementations.
49 * Constructed by \ref TargetFactory. Public access via \ref Target
52 class TargetImpl : public base::ReferenceCounted, private base::NonCopyable
54 friend std::ostream & operator<<( std::ostream & str, const TargetImpl & obj );
57 /** list of pool items */
58 typedef std::list<PoolItem> PoolItemList;
60 /** set of pool items */
61 typedef std::set<PoolItem> PoolItemSet;
65 TargetImpl(const Pathname & root_r = "/", bool doRebuild_r = false );
67 virtual ~TargetImpl();
69 /** Null implementation */
70 static TargetImpl_Ptr nullimpl();
73 * generates the unique anonymous id which is called
74 * when creating the target
76 void createAnonymousId() const;
79 * generates a cache of the last product flavor
81 void createLastDistributionFlavorCache() const;
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.
90 /** The systems default solv file location. */
91 Pathname defaultSolvfilesPath() const;
93 /** The solv file location actually in use (default or temp). */
94 Pathname solvfilesPath() const
95 { return solvfilesPathIsTemp() ? _tmpSolvfilesPath : defaultSolvfilesPath(); }
97 /** Whether we're using a temp. solvfile. */
98 bool solvfilesPathIsTemp() const
99 { return ! _tmpSolvfilesPath.empty(); }
101 Pathname _tmpSolvfilesPath;
115 /** The root set for this target */
116 Pathname root() const
119 /** The directory to store things. */
120 Pathname home() const
121 { return home( _root ); }
123 static Pathname home( const Pathname & root_r )
124 { return root_r / "/var/lib/zypp"; }
126 /** Commit changes in the pool */
127 ZYppCommitResult commit( ResPool pool_r, const ZYppCommitPolicy & policy_r );
129 /** Install a source package on the Target. */
130 void installSrcPackage( const SrcPackage_constPtr & srcPackage_r );
132 /** Overload to realize stream output. */
133 virtual std::ostream & dumpOn( std::ostream & str ) const
135 return str << "TargetImpl";
138 /** The RPM database */
141 /** If the package is installed and provides the file
142 Needed to evaluate split provides during Resolver::Upgrade() */
143 bool providesFile (const std::string & path_str, const std::string & name_str) const;
145 /** Return name of package owning \a path_str
146 * or empty string if no installed package owns \a path_str. */
147 std::string whoOwnsFile (const std::string & path_str) const
148 { return _rpm.whoOwnsFile (path_str); }
150 /** return the last modification date of the target */
151 Date timestamp() const;
153 /** \copydoc Target::baseProduct() */
154 Product::constPtr baseProduct() const;
156 /** \copydoc Target::requestedLocales() */
157 LocaleSet requestedLocales() const
158 { return _requestedLocalesFile.locales(); }
160 static LocaleSet requestedLocales( const Pathname & root_r );
162 /** \copydoc Target::targetDistribution() */
163 std::string targetDistribution() const;
165 static std::string targetDistribution( const Pathname & root_r );
167 /** \copydoc Target::targetDistributionRelease()*/
168 std::string targetDistributionRelease() const;
170 static std::string targetDistributionRelease( const Pathname & root_r );
172 /** \copydoc Target::distributionVersion()*/
173 Target::DistributionLabel distributionLabel() const;
175 static Target::DistributionLabel distributionLabel( const Pathname & root_r );
177 /** \copydoc Target::distributionVersion()*/
178 std::string distributionVersion() const;
180 static std::string distributionVersion( const Pathname & root_r );
182 /** \copydoc Target::distributionFlavor() */
183 std::string distributionFlavor() const;
185 static std::string distributionFlavor( const Pathname & root_r );
187 /** \copydoc Target::anonymousUniqueId() */
188 std::string anonymousUniqueId() const;
190 static std::string anonymousUniqueId( const Pathname & root_r );
193 /** Commit ordered changes (internal helper) */
194 void commit( const ZYppCommitPolicy & policy_r,
195 CommitPackageCache & packageCache_r,
196 ZYppCommitResult & result_r );
199 /** Path to the target */
203 /** Requested Locales database */
204 RequestedLocalesFile _requestedLocalesFile;
205 /** Soft-locks database */
206 SoftLocksFile _softLocksFile;
207 /** Hard-Locks database */
208 HardLocksFile _hardLocksFile;
209 /** Cache distributionVersion */
210 mutable std::string _distributionVersion;
213 /** Null implementation */
214 static TargetImpl_Ptr _nullimpl;
216 ///////////////////////////////////////////////////////////////////
218 /** \relates TargetImpl Stream output */
219 inline std::ostream & operator<<( std::ostream & str, const TargetImpl & obj )
221 return obj.dumpOn( str );
224 /////////////////////////////////////////////////////////////////
225 } // namespace target
226 ///////////////////////////////////////////////////////////////////
227 /////////////////////////////////////////////////////////////////
229 ///////////////////////////////////////////////////////////////////
230 #endif // ZYPP_TARGET_TARGETIMPL_H