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/DefaultFalseBool.h"
22 #include "zypp/base/PtrTypes.h"
23 #include "zypp/PoolItem.h"
24 #include "zypp/ZYppCommit.h"
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"
35 ///////////////////////////////////////////////////////////////////
37 { /////////////////////////////////////////////////////////////////
38 ///////////////////////////////////////////////////////////////////
40 { /////////////////////////////////////////////////////////////////
42 DEFINE_PTR_TYPE(TargetImpl);
43 class CommitPackageCache;
45 ///////////////////////////////////////////////////////////////////
47 // CLASS NAME : TargetImpl
49 /** Base class for concrete Target implementations.
51 * Constructed by \ref TargetFactory. Public access via \ref Target
54 class TargetImpl : public base::ReferenceCounted, private base::NonCopyable
56 friend std::ostream & operator<<( std::ostream & str, const TargetImpl & obj );
59 /** list of pool items */
60 typedef std::list<PoolItem> PoolItemList;
62 /** set of pool items */
63 typedef std::set<PoolItem> PoolItemSet;
67 TargetImpl(const Pathname & root_r = "/", bool doRebuild_r = false );
69 virtual ~TargetImpl();
71 /** Null implementation */
72 static TargetImpl_Ptr nullimpl();
75 * generates the unique anonymous id which is called
76 * when creating the target
78 void createAnonymousId() const;
81 * generates a cache of the last product flavor
83 void createLastDistributionFlavorCache() const;
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.
92 /** The systems default solv file location. */
93 Pathname defaultSolvfilesPath() const;
95 /** The solv file location actually in use (default or temp). */
96 Pathname solvfilesPath() const
97 { return solvfilesPathIsTemp() ? _tmpSolvfilesPath : defaultSolvfilesPath(); }
99 /** Whether we're using a temp. solvfile. */
100 bool solvfilesPathIsTemp() const
101 { return ! _tmpSolvfilesPath.empty(); }
103 Pathname _tmpSolvfilesPath;
115 std::string anonymousUniqueId() const;
119 /** The root set for this target */
120 Pathname root() const
123 /** The directory to store things. */
124 Pathname home() const
125 { return _root / "/var/lib/zypp"; }
127 /** Commit changes in the pool */
128 ZYppCommitResult commit( ResPool pool_r, const ZYppCommitPolicy & policy_r );
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 )
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 );
145 /** Commit ordered changes
146 * @param packageCache_r Access to the package provider
147 * @return uncommitted ones (due to error)
149 PoolItemList commit( const PoolItemList & items_r, const ZYppCommitPolicy & policy_r,
150 CommitPackageCache & packageCache_r );
152 /** Install a source package on the Target. */
153 void installSrcPackage( const SrcPackage_constPtr & srcPackage_r );
155 /** Overload to realize stream output. */
156 virtual std::ostream & dumpOn( std::ostream & str ) const
158 return str << "TargetImpl";
161 /** The RPM database */
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;
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); }
173 /** return the last modification date of the target */
174 Date timestamp() const;
176 /** \copydoc Target::baseProduct() */
177 Product::constPtr baseProduct() const;
179 /** \copydoc Target::release() */
180 std::string release() const;
182 /** \copydoc Target::targetDistribution() */
183 std::string targetDistribution() const;
185 /** \copydoc Target::targetDistributionRelease()*/
186 std::string targetDistributionRelease() const;
188 /** \copydoc Target::distributionVersion()*/
189 std::string distributionVersion() const;
191 /** \copydoc Target::distributionFlavor() */
192 std::string distributionFlavor() const;
195 /** Path to the target */
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;
208 /** Null implementation */
209 static TargetImpl_Ptr _nullimpl;
211 ///////////////////////////////////////////////////////////////////
213 /** \relates TargetImpl Stream output */
214 inline std::ostream & operator<<( std::ostream & str, const TargetImpl & obj )
216 return obj.dumpOn( str );
219 /////////////////////////////////////////////////////////////////
220 } // namespace target
221 ///////////////////////////////////////////////////////////////////
222 /////////////////////////////////////////////////////////////////
224 ///////////////////////////////////////////////////////////////////
225 #endif // ZYPP_TARGET_TARGETIMPL_H