1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/sat/detail/PoolImpl.h
12 #ifndef ZYPP_SAT_DETAIL_POOLIMPL_H
13 #define ZYPP_SAT_DETAIL_POOLIMPL_H
16 #include <solv/pool.h>
17 #include <solv/repo.h>
18 #include <solv/solvable.h>
19 #include <solv/poolarch.h>
20 #include <solv/repo_solv.h>
24 #include "zypp/base/Hash.h"
25 #include "zypp/base/NonCopyable.h"
26 #include "zypp/base/SerialNumber.h"
27 #include "zypp/base/SetTracker.h"
28 #include "zypp/sat/detail/PoolMember.h"
29 #include "zypp/sat/Queue.h"
30 #include "zypp/RepoInfo.h"
31 #include "zypp/Locale.h"
32 #include "zypp/Capability.h"
33 #include "zypp/IdString.h"
35 ///////////////////////////////////////////////////////////////////
37 { /////////////////////////////////////////////////////////////////
38 ///////////////////////////////////////////////////////////////////
40 { /////////////////////////////////////////////////////////////////
42 ///////////////////////////////////////////////////////////////////
44 { /////////////////////////////////////////////////////////////////
46 ///////////////////////////////////////////////////////////////////
48 // CLASS NAME : PoolImpl
51 class PoolImpl : private base::NonCopyable
60 /** Pointer style access forwarded to sat-pool. */
65 /** Serial number changing whenever the content changes. */
66 const SerialNumber & serial() const
69 /** Update housekeeping data (e.g. whatprovides).
70 * \todo actually requires a watcher.
75 /** Invalidate housekeeping data (e.g. whatprovides) if the
76 * pools content changed.
78 void setDirty( const char * a1 = 0, const char * a2 = 0, const char * a3 = 0 );
80 /** Invalidate locale related housekeeping data.
82 void localeSetDirty( const char * a1 = 0, const char * a2 = 0, const char * a3 = 0 );
84 /** Invalidate housekeeping data (e.g. whatprovides) if dependencies changed.
86 void depSetDirty( const char * a1 = 0, const char * a2 = 0, const char * a3 = 0 );
88 /** Callback to resolve namespace dependencies (language, modalias, filesystem, etc.). */
89 static detail::IdType nsCallback( CPool *, void * data, detail::IdType lhs, detail::IdType rhs );
92 /** Reserved system repository alias \c @System. */
93 static const std::string & systemRepoAlias();
95 bool isSystemRepo( CRepo * repo_r ) const
96 { return repo_r && _pool->installed == repo_r; }
98 CRepo * systemRepo() const
99 { return _pool->installed; }
101 /** Get rootdir (for file conflicts check) */
102 Pathname rootDir() const
104 const char * rd = ::pool_get_rootdir( _pool );
105 return( rd ? rd : "/" );
108 /** Set rootdir (for file conflicts check) */
109 void rootDir( const Pathname & root_r )
111 if ( root_r.empty() || root_r == "/" )
112 ::pool_set_rootdir( _pool, nullptr );
114 ::pool_set_rootdir( _pool, root_r.c_str() );
118 /** \name Actions invalidating housekeeping data.
120 * All methods expect valid arguments being passed.
123 /** Creating a new repo named \a name_r. */
124 CRepo * _createRepo( const std::string & name_r );
126 /** Delete repo \a repo_r from pool. */
127 void _deleteRepo( CRepo * repo_r );
129 /** Adding solv file to a repo.
130 * Except for \c isSystemRepo_r, solvables of incompatible architecture
133 int _addSolv( CRepo * repo_r, FILE * file_r );
135 /** Adding helix file to a repo.
136 * Except for \c isSystemRepo_r, solvables of incompatible architecture
139 int _addHelix( CRepo * repo_r, FILE * file_r );
141 /** Adding Solvables to a repo. */
142 detail::SolvableIdType _addSolvables( CRepo * repo_r, unsigned count_r );
145 /** Helper postprocessing the repo after adding solv or helix files. */
146 void _postRepoAdd( CRepo * repo_r );
149 /** a \c valid \ref Solvable has a non NULL repo pointer. */
150 bool validSolvable( const CSolvable & slv_r ) const
151 { return slv_r.repo; }
152 /** \overload Check also for id_r being in range of _pool->solvables. */
153 bool validSolvable( SolvableIdType id_r ) const
154 { return id_r < unsigned(_pool->nsolvables) && validSolvable( _pool->solvables[id_r] ); }
155 /** \overload Check also for slv_r being in range of _pool->solvables. */
156 bool validSolvable( const CSolvable * slv_r ) const
157 { return _pool->solvables <= slv_r && slv_r <= _pool->solvables+_pool->nsolvables && validSolvable( *slv_r ); }
160 CPool * getPool() const
163 /** \todo a quick check whether the repo was meanwhile deleted. */
164 CRepo * getRepo( RepoIdType id_r ) const
167 /** Return pointer to the sat-solvable or NULL if it is not valid.
168 * \see \ref validSolvable.
170 CSolvable * getSolvable( SolvableIdType id_r ) const
172 if ( validSolvable( id_r ) )
173 return &_pool->solvables[id_r];
178 /** Get id of the first valid \ref Solvable.
179 * This is the next valid after the system solvable.
181 SolvableIdType getFirstId() const
182 { return getNextId( 1 ); }
184 /** Get id of the next valid \ref Solvable.
185 * This goes round robbin. At the end it returns \ref noSolvableId.
186 * Passing \ref noSolvableId it returns the 1st valid \ref Solvable.
187 * \see \ref validSolvable.
189 SolvableIdType getNextId( SolvableIdType id_r ) const
191 for( ++id_r; id_r < unsigned(_pool->nsolvables); ++id_r )
193 if ( validSolvable( _pool->solvables[id_r] ) )
201 const RepoInfo & repoInfo( RepoIdType id_r )
202 { return _repoinfos[id_r]; }
203 /** Also adjust repo priority and subpriority accordingly. */
204 void setRepoInfo( RepoIdType id_r, const RepoInfo & info_r );
206 void eraseRepoInfo( RepoIdType id_r )
207 { _repoinfos.erase( id_r ); }
210 /** Returns the id stored at \c offset_r in the internal
211 * whatprovidesdata array.
213 const sat::detail::IdType whatProvidesData( unsigned offset_r )
214 { return _pool->whatprovidesdata[offset_r]; }
216 /** Returns offset into the internal whatprovidesdata array.
217 * Use \ref whatProvidesData to get the stored Id.
219 unsigned whatProvides( Capability cap_r )
220 { prepare(); return ::pool_whatprovides( _pool, cap_r.id() ); }
223 /// \name Requested locales.
224 /// The requested LocaleSets managed in _requestedLocalesTracker
225 /// are unexpanded; i.e. they contain just the pure user selection.
226 /// The resolver however uses expanded sets ('de_DE' will also
227 /// include its fallback locales 'de', (en); here in the namespace:
228 /// callback and in the Resolver itself).
231 void setTextLocale( const Locale & locale_r );
234 /** Start tracking changes based on this \a locales_r.
235 * Usually called on TargetInit.
237 void initRequestedLocales( const LocaleSet & locales_r );
239 /** Added since last initRequestedLocales. */
240 const LocaleSet & getAddedRequestedLocales() const
241 { return _requestedLocalesTracker.added(); }
243 /** Removed since last initRequestedLocales. */
244 const LocaleSet & getRemovedRequestedLocales() const
245 { return _requestedLocalesTracker.removed(); }
247 /** Current set of requested Locales. */
248 const LocaleSet & getRequestedLocales() const
249 { return _requestedLocalesTracker.current(); }
251 bool isRequestedLocale( const Locale & locale_r ) const
252 { return _requestedLocalesTracker.contains( locale_r ); }
254 /** User change (tracked). */
255 void setRequestedLocales( const LocaleSet & locales_r );
256 /** User change (tracked). */
257 bool addRequestedLocale( const Locale & locale_r );
258 /** User change (tracked). */
259 bool eraseRequestedLocale( const Locale & locale_r );
261 /** All Locales occurring in any repo. */
262 const LocaleSet & getAvailableLocales() const;
264 bool isAvailableLocale( const Locale & locale_r ) const
266 const LocaleSet & avl( getAvailableLocales() );
267 LocaleSet::const_iterator it( avl.find( locale_r ) );
268 return it != avl.end();
271 typedef base::SetTracker<IdStringSet> TrackedLocaleIds;
273 /** Expanded _requestedLocalesTracker for solver.*/
274 const TrackedLocaleIds & trackedLocaleIds() const;
278 /** \name Multiversion install. */
280 typedef SolvableSet MultiversionList;
282 const MultiversionList & multiversionList() const;
284 bool isMultiversion( const Solvable & solv_r ) const;
286 void multiversionSpecChanged();
290 /** \name Installed on behalf of a user request hint. */
292 /** Get ident list of all autoinstalled solvables. */
293 StringQueue autoInstalled() const
294 { return _autoinstalled; }
296 /** Set ident list of all autoinstalled solvables. */
297 void setAutoInstalled( const StringQueue & autoInstalled_r )
298 { _autoinstalled = autoInstalled_r; }
300 bool isOnSystemByUser( IdString ident_r ) const
301 { return !_autoinstalled.contains( ident_r.id() ); }
303 bool isOnSystemByAuto( IdString ident_r ) const
304 { return _autoinstalled.contains( ident_r.id() ); }
308 /** accessor for etc/sysconfig/storage reading file on demand */
309 const std::set<std::string> & requiredFilesystems() const;
314 /** Serial number. */
315 SerialNumber _serial;
316 /** Watch serial number. */
317 SerialNumberWatcher _watcher;
318 /** Additional \ref RepoInfo. */
319 std::map<RepoIdType,RepoInfo> _repoinfos;
322 base::SetTracker<LocaleSet> _requestedLocalesTracker;
323 mutable scoped_ptr<TrackedLocaleIds> _trackedLocaleIdsPtr;
325 mutable scoped_ptr<LocaleSet> _availableLocalesPtr;
328 void multiversionListInit() const;
329 mutable scoped_ptr<MultiversionList> _multiversionListPtr;
332 sat::StringQueue _autoinstalled;
334 /** filesystems mentioned in /etc/sysconfig/storage */
335 mutable scoped_ptr<std::set<std::string> > _requiredFilesystemsPtr;
337 ///////////////////////////////////////////////////////////////////
339 /////////////////////////////////////////////////////////////////
340 } // namespace detail
341 ///////////////////////////////////////////////////////////////////
342 /////////////////////////////////////////////////////////////////
344 ///////////////////////////////////////////////////////////////////
345 /////////////////////////////////////////////////////////////////
347 ///////////////////////////////////////////////////////////////////
348 #define POOL_SETDIRTY
349 #endif // ZYPP_SAT_DETAIL_POOLIMPL_H