1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/Target.h
17 #include "zypp/base/ReferenceCounted.h"
18 #include "zypp/base/NonCopyable.h"
19 #include "zypp/base/PtrTypes.h"
20 #include "zypp/APIConfig.h"
22 #include "zypp/Product.h"
23 #include "zypp/Pathname.h"
24 #include "zypp/ResPool.h"
26 ///////////////////////////////////////////////////////////////////
28 { /////////////////////////////////////////////////////////////////
41 DEFINE_PTR_TYPE(Target);
43 ///////////////////////////////////////////////////////////////////
45 // CLASS NAME : Target
49 class Target : public base::ReferenceCounted, public base::NonCopyable
52 typedef target::TargetImpl Impl;
53 typedef intrusive_ptr<Impl> Impl_Ptr;
54 typedef std::list<PoolItem> PoolItemList;
59 * builds or refreshes the target cache
64 * cleans the target cache (.solv files)
69 * load resolvables into the pool
76 * unload target resolvables from the
81 /** Refference to the RPM database */
82 target::rpm::RpmDb & rpmDb();
84 /** If the package is installed and provides the file
85 Needed to evaluate split provides during Resolver::Upgrade() */
86 bool providesFile (const std::string & name_str, const std::string & path_str) const;
88 /** Return name of package owning \a path_str
89 * or empty string if no installed package owns \a path_str.
91 std::string whoOwnsFile (const std::string & path_str) const;
93 /** Return the root set for this target */
94 Pathname root() const;
96 /** Whether the targets \ref root is not \c "/". */
98 { return( ! root().emptyOrRoot() ); }
100 /** Return the path prefixed by the target root, unless it already is prefixed. */
101 Pathname assertRootPrefix( const Pathname & path_r ) const
102 { return Pathname::assertprefix( root(), path_r ); }
104 /** return the last modification date of the target */
105 Date timestamp() const;
108 * returns the target base installed product, also known as
109 * the distribution or platform.
111 * returns 0 if there is no base installed product in the
114 * \note this method requires the target to be loaded,
115 * otherwise it will return 0 as no product is found.
117 * if you require some base product attributes when the
118 * target is not loaded into the pool, see
119 * \ref targetDistribution , \ref targetDistributionRelease
120 * and \ref distributionVersion that obtain the data
121 * on demand from the installed product information.
123 Product::constPtr baseProduct() const;
126 * \brief Languages to be supported by the system.
127 * E.g. language specific packages to be installed.
129 LocaleSet requestedLocales() const;
130 /** \overload Use a specific root_r, if empty the default targets root, or '/'
132 static LocaleSet requestedLocales( const Pathname & root_r );
134 /** Update the database of autoinstalled packages.
135 * This is done on commit, so you usually don't need to call this explicitly.
137 void updateAutoInstalled();
140 /** \name Base product and registration.
142 * Static methods herein allow to retrieve the values without explicitly
143 * initializing the \ref Target. They take a targets root directory as
144 * argument. If an empty \ref Pathname is passed, an already existing
145 * Targets root is used, otherwise \c "/" is assumed.
148 /** This is \c register.target attribute of the installed base product.
149 * Used for registration and \ref Service refresh.
151 std::string targetDistribution() const;
153 static std::string targetDistribution( const Pathname & root_r );
155 /** This is \c register.release attribute of the installed base product.
156 * Used for registration.
158 std::string targetDistributionRelease() const;
160 static std::string targetDistributionRelease( const Pathname & root_r );
162 /** This is \c register.flavor attribute of the installed base product.
163 * Used for registration.
164 * \note don't mistake this for \ref distributionFlavor
166 std::string targetDistributionFlavor() const;
168 static std::string targetDistributionFlavor( const Pathname & root_r );
170 struct DistributionLabel { std::string shortName; std::string summary; };
171 /** This is \c shortName and \c summary attribute of the installed base product.
172 * Used e.g. for the bootloader menu.
174 DistributionLabel distributionLabel() const;
176 static DistributionLabel distributionLabel( const Pathname & root_r );
178 /** This is \c version attribute of the installed base product.
179 * For example http://download.opensue.org/update/11.0
180 * The 11.0 corresponds to the base product version.
182 std::string distributionVersion() const;
184 static std::string distributionVersion( const Pathname & root_r );
187 * This is \c flavor attribute of the installed base product
188 * but does not require the target to be loaded as it remembers
189 * the last used one. It can be empty is the target has never
190 * been loaded, as the value is not present in the system
191 * but computer from a package provides
192 * \note don't mistake this for \ref targetDistributionFlavor
194 std::string distributionFlavor() const;
196 static std::string distributionFlavor( const Pathname & root_r );
199 * anonymous unique id
201 * This id is generated once and stays in the
202 * saved in the target.
203 * It is unique and is used only for statistics.
206 std::string anonymousUniqueId() const;
208 static std::string anonymousUniqueId( const Pathname & root_r );
212 /** Ctor. If \c doRebuild_r is \c true, an already existing
213 * database is rebuilt (rpm --rebuilddb ).
216 Target( const Pathname & root = "/", bool doRebuild_r = false );
219 Target( const Impl_Ptr & impl_r );
222 friend std::ostream & operator<<( std::ostream & str, const Target & obj );
223 /** Stream output. */
224 std::ostream & dumpOn( std::ostream & str ) const;
227 /** Direct access to Impl. */
228 friend class zypp_detail::ZYppImpl;
230 /** Pointer to implementation */
231 RW_pointer<Impl,rw_pointer::Intrusive<Impl> > _pimpl;
233 ///////////////////////////////////////////////////////////////////
235 /** \relates Target Stream output. */
236 inline std::ostream & operator<<( std::ostream & str, const Target & obj )
237 { return obj.dumpOn( str ); }
239 /** \relates Target::DistributionLabel Stream output.
240 * Write out the content as key/value pairs:
242 * summary=Beautiful Name
246 std::ostream & operator<<( std::ostream & str, const Target::DistributionLabel & obj );
248 /////////////////////////////////////////////////////////////////
250 ///////////////////////////////////////////////////////////////////
251 #endif // ZYPP_TARGET_H