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/base/Deprecated.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
74 * unload target resolvables from the
79 /** Null implementation */
80 static Target_Ptr nullimpl();
82 /** Refference to the RPM database */
83 target::rpm::RpmDb & rpmDb();
85 /** If the package is installed and provides the file
86 Needed to evaluate split provides during Resolver::Upgrade() */
87 bool providesFile (const std::string & name_str, const std::string & path_str) const;
89 /** Return name of package owning \a path_str
90 * or empty string if no installed package owns \a path_str.
92 std::string whoOwnsFile (const std::string & path_str) const;
94 /** Return the root set for this target */
95 Pathname root() const;
97 /** Return the path prefixed by the target root, unless it already is prefixed. */
98 Pathname assertRootPrefix( const Pathname & path_r ) const
99 { return Pathname::assertprefix( root(), path_r ); }
101 /** return the last modification date of the target */
102 Date timestamp() const;
105 * returns the target base installed product, also known as
106 * the distribution or platform.
108 * returns 0 if there is no base installed product in the
111 * \note this method requires the target to be loaded,
112 * otherwise it will return 0 as no product is found.
114 * if you require some base product attributes when the
115 * target is not loaded into the pool, see
116 * \ref targetDistribution , \ref targetDistributionRelease
117 * and \ref distributionVersion that obtain the data
118 * on demand from the installed product information.
120 Product::constPtr baseProduct() const;
123 /** \name Base product and registration.
125 * Static methods herein allow to retrieve the values without explicitly
126 * initializing the \ref Target. They take a targets root directory as
127 * argument. If an empty \ref Pathname is passed, an already existing
128 * Targets root is used, otherwise \c "\" is assumed.
131 /** This is \c register.target attribute of the installed base product.
132 * Used for registration and \ref Service refresh.
134 std::string targetDistribution() const;
136 static std::string targetDistribution( const Pathname & root_r );
138 /** This is \c register.release attribute of the installed base product.
139 * Used for registration.
141 std::string targetDistributionRelease() const;
143 static std::string targetDistributionRelease( const Pathname & root_r );
145 /** This is \c version attribute of the installed base product.
146 * For example http://download.opensue.org/update/11.0
147 * The 11.0 corresponds to the base product version.
149 std::string distributionVersion() const;
151 static std::string distributionVersion( const Pathname & root_r );
154 * This is \c flavor attribute of the installed base product
155 * but does not require the target to be loaded as it remembers
156 * the last used one. It can be empty is the target has never
157 * been loaded, as the value is not present in the system
158 * but computer from a package provides
160 std::string distributionFlavor() const;
162 static std::string distributionFlavor( const Pathname & root_r );
165 * anonymous unique id
167 * This id is generated once and stays in the
168 * saved in the target.
169 * It is unique and is used only for statistics.
172 std::string anonymousUniqueId() const;
174 static std::string anonymousUniqueId( const Pathname & root_r );
178 /** Ctor. If \c doRebuild_r is \c true, an already existing
179 * database is rebuilt (rpm --rebuilddb ).
182 Target( const Pathname & root = "/", bool doRebuild_r = false );
185 Target( const Impl_Ptr & impl_r );
188 friend std::ostream & operator<<( std::ostream & str, const Target & obj );
189 /** Stream output. */
190 std::ostream & dumpOn( std::ostream & str ) const;
193 /** Direct access to Impl. */
194 friend class zypp_detail::ZYppImpl;
196 /** Pointer to implementation */
197 RW_pointer<Impl,rw_pointer::Intrusive<Impl> > _pimpl;
199 static Target_Ptr _nullimpl;
201 ///////////////////////////////////////////////////////////////////
203 /** \relates Target Stream output. */
204 inline std::ostream & operator<<( std::ostream & str, const Target & obj )
205 { return obj.dumpOn( str ); }
208 /////////////////////////////////////////////////////////////////
210 ///////////////////////////////////////////////////////////////////
211 #endif // ZYPP_TARGET_H