Imported Upstream version 17.16.0
[platform/upstream/libzypp.git] / zypp / sat / Pool.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/sat/Pool.h
10  *
11 */
12 #ifndef ZYPP_SAT_POOL_H
13 #define ZYPP_SAT_POOL_H
14
15 #include <iosfwd>
16
17 #include "zypp/Pathname.h"
18
19 #include "zypp/sat/detail/PoolMember.h"
20 #include "zypp/Repository.h"
21 #include "zypp/sat/WhatProvides.h"
22 #include "zypp/sat/SolvableSet.h"
23 #include "zypp/sat/Queue.h"
24
25 ///////////////////////////////////////////////////////////////////
26 namespace zypp
27 { /////////////////////////////////////////////////////////////////
28
29   class SerialNumber;
30   class RepoInfo;
31
32   ///////////////////////////////////////////////////////////////////
33   namespace sat
34   { /////////////////////////////////////////////////////////////////
35
36     class SolvableSpec;
37
38     ///////////////////////////////////////////////////////////////////
39     //
40     //  CLASS NAME : Pool
41     //
42     /** Global sat-pool.
43      *
44      * Explicitly shared singleton \ref Pool::instance.
45      */
46     class Pool : protected detail::PoolMember
47     {
48       public:
49         typedef detail::SolvableIterator SolvableIterator;
50         typedef zypp::detail::RepositoryIterator     RepositoryIterator;
51         typedef detail::size_type        size_type;
52
53       public:
54         /** Singleton ctor. */
55         static Pool instance()
56         { return Pool(); }
57
58         /** Ctor from \ref PoolMember. */
59         Pool( const detail::PoolMember & )
60         {}
61
62       public:
63         /** Internal array size for stats only. */
64         size_type capacity() const;
65
66         /** Housekeeping data serial number. */
67         const SerialNumber & serial() const;
68
69         /** Serial number changing whenever resusePoolIDs==true was used. ResPool must also invalidate it's PoolItems! */
70         const SerialNumber & serialIDs() const;
71
72         /** Update housekeeping data if necessary (e.g. whatprovides). */
73         void prepare() const;
74
75         /** Get rootdir (for file conflicts check) */
76         Pathname rootDir() const;
77
78         /** Set rootdir (for file conflicts check) */
79         void rootDir( const Pathname & root_r );
80
81       public:
82         /** Whether \ref Pool contains repos. */
83         bool reposEmpty() const;
84
85         /** Number of repos in \ref Pool. */
86         size_type reposSize() const;
87
88         /** Iterator to the first \ref Repository. */
89         RepositoryIterator reposBegin() const;
90
91         /** Iterator behind the last \ref Repository. */
92         RepositoryIterator reposEnd() const;
93
94         /** Iterate the repositories. */
95         Iterable<RepositoryIterator> repos() const
96         { return makeIterable( reposBegin(), reposEnd() ); }
97
98         /** Return a \ref Repository named \c alias_r.
99          * It a such a \ref Repository does not already exist
100          * a new empty \ref Repository is created.
101          */
102         Repository reposInsert( const std::string & alias_r );
103
104         /** Find a \ref Repository named \c alias_r.
105          * Returns \ref noRepository if there is no such \ref Repository.
106          */
107         Repository reposFind( const std::string & alias_r ) const;
108
109         /** Remove a \ref Repository named \c alias_r.
110          * \see \ref Repository::eraseFromPool
111          */
112         void reposErase( const std::string & alias_r )
113         { reposFind( alias_r ).eraseFromPool(); }
114
115         /** Remove all repos from the pool.
116          * This also shrinks a pool which may have become large
117          * after having added and removed repos lots of times.
118          */
119         void reposEraseAll()
120         { while ( ! reposEmpty() ) reposErase( reposBegin()->alias() ); }
121
122       public:
123         /** Reserved system repository alias \c @System. */
124         static const std::string & systemRepoAlias();
125
126         /** Return the system repository if it is on the pool. */
127         Repository findSystemRepo() const;
128
129         /** Return the system repository, create it if missing. */
130         Repository systemRepo();
131
132       public:
133         /** Load \ref Solvables from a solv-file into a \ref Repository named \c name_r.
134          * In case of an exception the \ref Repository is removed from the \ref Pool.
135          * \throws Exception if loading the solv-file fails.
136          * \see \ref Repository::EraseFromPool
137         */
138         Repository addRepoSolv( const Pathname & file_r, const std::string & name_r );
139         /** \overload Using the files basename as \ref Repository name. */
140         Repository addRepoSolv( const Pathname & file_r );
141         /** \overload Using the \ref RepoInfo::alias \ref Repo name.
142          * Additionally stores the \ref RepoInfo. \See \ref Prool::setInfo.
143         */
144         Repository addRepoSolv( const Pathname & file_r, const RepoInfo & info_r );
145
146       public:
147         /** Load \ref Solvables from a helix-file into a \ref Repository named \c name_r.
148          * Supports loading of gzip compressed files (.gz). In case of an exception
149          * the \ref Repository is removed from the \ref Pool.
150          * \throws Exception if loading the helix-file fails.
151          * \see \ref Repository::EraseFromPool
152         */
153         Repository addRepoHelix( const Pathname & file_r, const std::string & name_r );
154         /** \overload Using the files basename as \ref Repository name. */
155         Repository addRepoHelix( const Pathname & file_r );
156         /** \overload Using the \ref RepoInfo::alias \ref Repo name.
157          * Additionally stores the \ref RepoInfo. \See \ref Prool::setInfo.
158         */
159         Repository addRepoHelix( const Pathname & file_r, const RepoInfo & info_r );
160
161       public:
162         /** Whether \ref Pool contains solvables. */
163         bool solvablesEmpty() const;
164
165         /** Number of solvables in \ref Pool. */
166         size_type solvablesSize() const;
167
168         /** Iterator to the first \ref Solvable. */
169         SolvableIterator solvablesBegin() const;
170
171         /** Iterator behind the last \ref Solvable. */
172         SolvableIterator solvablesEnd() const;
173
174         /** Iterate the solvables. */
175         Iterable<SolvableIterator> solvables() const
176         { return makeIterable( solvablesBegin(), solvablesEnd() ); }
177
178       public:
179         /** \name Iterate all Solvables matching a \c TFilter. */
180         //@{
181         template<class TFilter>
182         filter_iterator<TFilter,SolvableIterator> filterBegin( const TFilter & filter_r ) const
183         { return make_filter_iterator( filter_r, solvablesBegin(), solvablesEnd() ); }
184
185         template<class TFilter>
186         filter_iterator<TFilter,SolvableIterator> filterEnd( const TFilter & filter_r ) const
187         { return make_filter_iterator( filter_r, solvablesEnd(), solvablesEnd() ); }
188         //@}
189
190      public:
191         /** Conainer of all \ref Solvable providing \c cap_r.  */
192         WhatProvides whatProvides( Capability cap_r ) const
193         { return WhatProvides( cap_r ); }
194
195         Queue whatMatchesDep( const SolvAttr &attr, const Capability &cap ) const;
196         Queue whatMatchesSolvable ( const SolvAttr &attr, const Solvable &solv ) const;
197         Queue whatContainsDep ( const SolvAttr &attr, const Capability &cap ) const;
198
199       public:
200         /** \name Requested locales. */
201         //@{
202         /** Set the default language for retrieving translated texts.
203          * Updated when calling \ref ZConfig::setTextLocale.
204          */
205         void setTextLocale( const Locale & locale_r );
206
207         /** Set the requested locales.
208          * Languages to be supported by the system, e.g. language specific
209          * packages to be installed.
210          */
211         void setRequestedLocales( const LocaleSet & locales_r );
212
213         /** Add one \ref Locale to the set of requested locales.
214          * Return \c true if \c locale_r was newly added to the set.
215         */
216         bool addRequestedLocale( const Locale & locale_r );
217
218         /** Erase one \ref Locale from the set of requested locales.
219         * Return \c false if \c locale_r was not found in the set.
220          */
221         bool eraseRequestedLocale( const Locale & locale_r );
222
223         /** Return the requested locales.
224          * \see \ref setRequestedLocales
225         */
226         const LocaleSet & getRequestedLocales() const;
227
228         /** Whether this \ref Locale is in the set of requested locales. */
229         bool isRequestedLocale( const Locale & locale_r ) const;
230
231
232         /** Start tracking changes based on this \a locales_r. */
233         void initRequestedLocales( const LocaleSet & locales_r );
234
235         /** Added since last initRequestedLocales. */
236         const LocaleSet & getAddedRequestedLocales() const;
237
238         /** Removed since last initRequestedLocales.*/
239         const LocaleSet & getRemovedRequestedLocales() const;
240
241
242         /** Get the set of available locales.
243          * This is computed from the package data so it actually
244          * represents all locales packages claim to support.
245          */
246         const LocaleSet & getAvailableLocales() const;
247
248         /** Whether this \ref Locale is in the set of available locales. */
249         bool isAvailableLocale( const Locale & locale_r ) const;
250         //@}
251
252       public:
253         /** \name Multiversion install.
254          * Whether the pool contains packages which are multiversion installable.
255          * \see \ref Solvable::multiversionInstall
256          * \see \ref ZConfig::multiversionSpec
257          */
258         //@{
259         typedef SolvableSet MultiversionList;
260         const MultiversionList & multiversion() const;
261         /** \deprecated Legacy, use multiversion().empty() instead. */
262         ZYPP_DEPRECATED bool multiversionEmpty() const { return multiversion().empty(); }
263         //@}
264
265       public:
266         /** \name Autoinstalled */
267         //@{
268         /** Get ident list of all autoinstalled solvables. */
269         Queue autoInstalled() const;
270         /** Set ident list of all autoinstalled solvables. */
271         void setAutoInstalled( const Queue & autoInstalled_r );
272         //@}
273
274       public:
275         /** \name Needreboot */
276         //@{
277         /** Solvables which should trigger the reboot-needed hint if installed/updated. */
278         void setNeedrebootSpec( sat::SolvableSpec needrebootSpec_r );
279         //@}
280
281       public:
282         /** Expert backdoor. */
283         detail::CPool * get() const;
284       private:
285         /** Default ctor */
286         Pool() {}
287     };
288     ///////////////////////////////////////////////////////////////////
289
290     /** \relates Pool Stream output */
291     std::ostream & operator<<( std::ostream & str, const Pool & obj );
292
293     /** \relates Pool */
294     inline bool operator==( const Pool & lhs, const Pool & rhs )
295     { return lhs.get() == rhs.get(); }
296
297     /** \relates Pool */
298     inline bool operator!=( const Pool & lhs, const Pool & rhs )
299     { return lhs.get() != rhs.get(); }
300
301     /** Create solv file content digest for zypper bash completion */
302     void updateSolvFileIndex( const Pathname & solvfile_r );
303
304     /////////////////////////////////////////////////////////////////
305   } // namespace sat
306   ///////////////////////////////////////////////////////////////////
307   /////////////////////////////////////////////////////////////////
308 } // namespace zypp
309 ///////////////////////////////////////////////////////////////////
310 #endif // ZYPP_SAT_POOL_H