Imported Upstream version 17.25.4
[platform/upstream/libzypp.git] / zypp / Target.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/Target.h
10  *
11 */
12 #ifndef ZYPP_TARGET_H
13 #define ZYPP_TARGET_H
14
15 #include <iosfwd>
16
17 #include <zypp/base/ReferenceCounted.h>
18 #include <zypp/base/NonCopyable.h>
19 #include <zypp/base/PtrTypes.h>
20 #include <zypp/APIConfig.h>
21
22 #include <zypp/Product.h>
23 #include <zypp/Pathname.h>
24 #include <zypp/ResPool.h>
25
26 ///////////////////////////////////////////////////////////////////
27 namespace zypp
28 { /////////////////////////////////////////////////////////////////
29   class VendorAttr;
30   namespace target
31   {
32     class TargetImpl;
33     namespace rpm {
34       class RpmDb;
35     }
36   }
37   namespace zypp_detail
38   {
39     class ZYppImpl;
40   }
41
42   DEFINE_PTR_TYPE(Target);
43
44   ///////////////////////////////////////////////////////////////////
45   //
46   //    CLASS NAME : Target
47   //
48   /**
49   */
50   class Target : public base::ReferenceCounted, public base::NonCopyable
51   {
52   public:
53     typedef target::TargetImpl  Impl;
54     typedef intrusive_ptr<Impl> Impl_Ptr;
55     typedef std::list<PoolItem> PoolItemList;
56
57   public:
58
59     /**
60      * builds or refreshes the target cache
61      */
62     void buildCache();
63
64     /**
65      * cleans the target cache (.solv files)
66      */
67     void cleanCache();
68
69    /**
70      * load resolvables into the pool
71      */
72     void load();
73
74     void reload();
75     
76     /**
77      * unload target resolvables from the
78      * pool
79      */
80     void unload();
81
82     /** Refference to the RPM database */
83     target::rpm::RpmDb & rpmDb();
84
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;
88
89     /** Return name of package owning \a path_str
90      * or empty string if no installed package owns \a path_str.
91      **/
92     std::string whoOwnsFile (const std::string & path_str) const;
93
94     /** Return the root set for this target */
95     Pathname root() const;
96
97     /** Whether the targets \ref root is not \c "/". */
98     bool chrooted() const
99     { return( ! root().emptyOrRoot() ); }
100
101     /** Return the path prefixed by the target root, unless it already is prefixed. */
102     Pathname assertRootPrefix( const Pathname & path_r ) const
103     { return Pathname::assertprefix( root(), path_r ); }
104
105     /**
106      * returns the target base installed product, also known as
107      * the distribution or platform.
108      *
109      * returns 0 if there is no base installed product in the
110      * pool.
111      *
112      * \note this method requires the target to be loaded,
113      * otherwise it will return 0 as no product is found.
114      *
115      * if you require some base product attributes when the
116      * target is not loaded into the pool, see
117      * \ref targetDistribution , \ref targetDistributionRelease
118      * and \ref distributionVersion that obtain the data
119      * on demand from the installed product information.
120      */
121     Product::constPtr baseProduct() const;
122
123     /**
124      * \brief Languages to be supported by the system.
125      * E.g. language specific packages to be installed.
126      */
127     LocaleSet requestedLocales() const;
128     /** \overload Use a specific root_r, if empty the default targets root, or '/'
129      */
130     static LocaleSet requestedLocales( const Pathname & root_r );
131
132     /** Update the database of autoinstalled packages.
133      * This is done on commit, so you usually don't need to call this explicitly.
134      */
135     void updateAutoInstalled();
136
137   public:
138     /** \name Base product and registration.
139      *
140      * Static methods herein allow to retrieve the values without explicitly
141      * initializing the \ref Target. They take a targets root directory as
142      * argument. If an empty \ref Pathname is passed, an already existing
143      * Targets root is used, otherwise \c "/" is assumed.
144      */
145     //@{
146     /** This is \c register.target attribute of the installed base product.
147      * Used for registration and \ref Service refresh.
148      */
149     std::string targetDistribution() const;
150     /** \overload */
151     static std::string targetDistribution( const Pathname & root_r );
152
153     /** This is \c register.release attribute of the installed base product.
154      * Used for registration.
155      */
156     std::string targetDistributionRelease() const;
157     /** \overload */
158     static std::string targetDistributionRelease( const Pathname & root_r );
159
160     /** This is \c register.flavor attribute of the installed base product.
161      * Used for registration.
162      * \note don't mistake this for \ref distributionFlavor
163      */
164     std::string targetDistributionFlavor() const;
165     /** \overload */
166     static std::string targetDistributionFlavor( const Pathname & root_r );
167
168     struct DistributionLabel { std::string shortName; std::string summary; };
169     /** This is \c shortName and \c summary attribute of the installed base product.
170      * Used e.g. for the bootloader menu.
171      */
172     DistributionLabel distributionLabel() const;
173     /** \overload */
174     static DistributionLabel distributionLabel( const Pathname & root_r );
175
176     /** This is \c version attribute of the installed base product.
177      * For example http://download.opensue.org/update/11.0
178      * The 11.0 corresponds to the base product version.
179      */
180     std::string distributionVersion() const;
181     /** \overload */
182     static std::string distributionVersion( const Pathname & root_r );
183
184     /**
185      * This is \c flavor attribute of the installed base product
186      * but does not require the target to be loaded as it remembers
187      * the last used one. It can be empty is the target has never
188      * been loaded, as the value is not present in the system
189      * but computer from a package provides
190      * \note don't mistake this for \ref targetDistributionFlavor
191      */
192     std::string distributionFlavor() const;
193     /** \overload */
194     static std::string distributionFlavor( const Pathname & root_r );
195
196     /**
197      * anonymous unique id
198      *
199      * This id is generated once and stays in the
200      * saved in the target.
201      * It is unique and is used only for statistics.
202      *
203      */
204     std::string anonymousUniqueId() const;
205     /** \overload */
206     static std::string anonymousUniqueId( const Pathname & root_r );
207     //@}
208
209   public:
210     /** \name Definition of vendor equivalence.
211      * \see \ref VendorAttr
212      */
213     //@{
214     /** The targets current vendor equivalence settings.
215      * Initialized from the targets /etc/zypp/vendors.d.
216      */
217     const VendorAttr & vendorAttr() const;
218     /** Assign new vendor equivalence settings to the target. */
219     void vendorAttr( VendorAttr vendorAttr_r );
220     //@}
221
222   public:
223     /** Ctor. If \c doRebuild_r is \c true, an already existing
224      * database is rebuilt (rpm --rebuilddb ).
225     */
226     explicit
227     Target( const Pathname & root = "/", bool doRebuild_r = false );
228     /** Ctor */
229     explicit
230     Target( const Impl_Ptr & impl_r );
231
232   private:
233     friend std::ostream & operator<<( std::ostream & str, const Target & obj );
234     /** Stream output. */
235     std::ostream & dumpOn( std::ostream & str ) const;
236
237   private:
238     /** Direct access to Impl. */
239     friend class zypp_detail::ZYppImpl;
240
241     /** Pointer to implementation */
242     RW_pointer<Impl,rw_pointer::Intrusive<Impl> > _pimpl;
243   };
244   ///////////////////////////////////////////////////////////////////
245
246   /** \relates Target Stream output. */
247   inline std::ostream & operator<<( std::ostream & str, const Target & obj )
248   { return obj.dumpOn( str ); }
249
250   /** \relates Target::DistributionLabel Stream output.
251    * Write out the content as key/value pairs:
252    * \code
253    * summary=Beautiful Name
254    * shortName=BN
255    * \endcode
256    */
257   std::ostream & operator<<( std::ostream & str, const Target::DistributionLabel & obj );
258
259   /////////////////////////////////////////////////////////////////
260 } // namespace zypp
261 ///////////////////////////////////////////////////////////////////
262 #endif // ZYPP_TARGET_H