1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/sat/Pool.h
12 #ifndef ZYPP_SAT_POOL_H
13 #define ZYPP_SAT_POOL_H
17 #include "zypp/Pathname.h"
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"
25 ///////////////////////////////////////////////////////////////////
27 { /////////////////////////////////////////////////////////////////
32 ///////////////////////////////////////////////////////////////////
34 { /////////////////////////////////////////////////////////////////
38 ///////////////////////////////////////////////////////////////////
44 * Explicitly shared singleton \ref Pool::instance.
46 class Pool : protected detail::PoolMember
49 typedef detail::SolvableIterator SolvableIterator;
50 typedef zypp::detail::RepositoryIterator RepositoryIterator;
51 typedef detail::size_type size_type;
54 /** Singleton ctor. */
55 static Pool instance()
58 /** Ctor from \ref PoolMember. */
59 Pool( const detail::PoolMember & )
63 /** Internal array size for stats only. */
64 size_type capacity() const;
66 /** Housekeeping data serial number. */
67 const SerialNumber & serial() const;
69 /** Serial number changing whenever resusePoolIDs==true was used. ResPool must also invalidate it's PoolItems! */
70 const SerialNumber & serialIDs() const;
72 /** Update housekeeping data if necessary (e.g. whatprovides). */
75 /** Get rootdir (for file conflicts check) */
76 Pathname rootDir() const;
78 /** Set rootdir (for file conflicts check) */
79 void rootDir( const Pathname & root_r );
82 /** Whether \ref Pool contains repos. */
83 bool reposEmpty() const;
85 /** Number of repos in \ref Pool. */
86 size_type reposSize() const;
88 /** Iterator to the first \ref Repository. */
89 RepositoryIterator reposBegin() const;
91 /** Iterator behind the last \ref Repository. */
92 RepositoryIterator reposEnd() const;
94 /** Iterate the repositories. */
95 Iterable<RepositoryIterator> repos() const
96 { return makeIterable( reposBegin(), reposEnd() ); }
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.
102 Repository reposInsert( const std::string & alias_r );
104 /** Find a \ref Repository named \c alias_r.
105 * Returns \ref noRepository if there is no such \ref Repository.
107 Repository reposFind( const std::string & alias_r ) const;
109 /** Remove a \ref Repository named \c alias_r.
110 * \see \ref Repository::eraseFromPool
112 void reposErase( const std::string & alias_r )
113 { reposFind( alias_r ).eraseFromPool(); }
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.
120 { while ( ! reposEmpty() ) reposErase( reposBegin()->alias() ); }
123 /** Reserved system repository alias \c @System. */
124 static const std::string & systemRepoAlias();
126 /** Return the system repository if it is on the pool. */
127 Repository findSystemRepo() const;
129 /** Return the system repository, create it if missing. */
130 Repository systemRepo();
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
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.
144 Repository addRepoSolv( const Pathname & file_r, const RepoInfo & info_r );
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
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.
159 Repository addRepoHelix( const Pathname & file_r, const RepoInfo & info_r );
162 /** Whether \ref Pool contains solvables. */
163 bool solvablesEmpty() const;
165 /** Number of solvables in \ref Pool. */
166 size_type solvablesSize() const;
168 /** Iterator to the first \ref Solvable. */
169 SolvableIterator solvablesBegin() const;
171 /** Iterator behind the last \ref Solvable. */
172 SolvableIterator solvablesEnd() const;
174 /** Iterate the solvables. */
175 Iterable<SolvableIterator> solvables() const
176 { return makeIterable( solvablesBegin(), solvablesEnd() ); }
179 /** \name Iterate all Solvables matching a \c TFilter. */
181 template<class TFilter>
182 filter_iterator<TFilter,SolvableIterator> filterBegin( const TFilter & filter_r ) const
183 { return make_filter_iterator( filter_r, solvablesBegin(), solvablesEnd() ); }
185 template<class TFilter>
186 filter_iterator<TFilter,SolvableIterator> filterEnd( const TFilter & filter_r ) const
187 { return make_filter_iterator( filter_r, solvablesEnd(), solvablesEnd() ); }
191 /** Conainer of all \ref Solvable providing \c cap_r. */
192 WhatProvides whatProvides( Capability cap_r ) const
193 { return WhatProvides( cap_r ); }
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;
200 /** \name Requested locales. */
202 /** Set the default language for retrieving translated texts.
203 * Updated when calling \ref ZConfig::setTextLocale.
205 void setTextLocale( const Locale & locale_r );
207 /** Set the requested locales.
208 * Languages to be supported by the system, e.g. language specific
209 * packages to be installed.
211 void setRequestedLocales( const LocaleSet & locales_r );
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.
216 bool addRequestedLocale( const Locale & locale_r );
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.
221 bool eraseRequestedLocale( const Locale & locale_r );
223 /** Return the requested locales.
224 * \see \ref setRequestedLocales
226 const LocaleSet & getRequestedLocales() const;
228 /** Whether this \ref Locale is in the set of requested locales. */
229 bool isRequestedLocale( const Locale & locale_r ) const;
232 /** Start tracking changes based on this \a locales_r. */
233 void initRequestedLocales( const LocaleSet & locales_r );
235 /** Added since last initRequestedLocales. */
236 const LocaleSet & getAddedRequestedLocales() const;
238 /** Removed since last initRequestedLocales.*/
239 const LocaleSet & getRemovedRequestedLocales() const;
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.
246 const LocaleSet & getAvailableLocales() const;
248 /** Whether this \ref Locale is in the set of available locales. */
249 bool isAvailableLocale( const Locale & locale_r ) const;
253 /** \name Multiversion install.
254 * Whether the pool contains packages which are multiversion installable.
255 * \see \ref Solvable::multiversionInstall
256 * \see \ref ZConfig::multiversionSpec
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(); }
266 /** \name Autoinstalled */
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 );
275 /** \name Needreboot */
277 /** Solvables which should trigger the reboot-needed hint if installed/updated. */
278 void setNeedrebootSpec( sat::SolvableSpec needrebootSpec_r );
282 /** Expert backdoor. */
283 detail::CPool * get() const;
288 ///////////////////////////////////////////////////////////////////
290 /** \relates Pool Stream output */
291 std::ostream & operator<<( std::ostream & str, const Pool & obj );
294 inline bool operator==( const Pool & lhs, const Pool & rhs )
295 { return lhs.get() == rhs.get(); }
298 inline bool operator!=( const Pool & lhs, const Pool & rhs )
299 { return lhs.get() != rhs.get(); }
301 /** Create solv file content digest for zypper bash completion */
302 void updateSolvFileIndex( const Pathname & solvfile_r );
304 /////////////////////////////////////////////////////////////////
306 ///////////////////////////////////////////////////////////////////
307 /////////////////////////////////////////////////////////////////
309 ///////////////////////////////////////////////////////////////////
310 #endif // ZYPP_SAT_POOL_H