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 /** Serial number changing whenever resusePoolIDs==true was used. ResPool must also invalidate it's PoolItems! */
70 const SerialNumber & serialIDs() const
71 { return _serialIDs; }
73 /** Update housekeeping data (e.g. whatprovides).
74 * \todo actually requires a watcher.
79 /** Invalidate housekeeping data (e.g. whatprovides) if the
80 * pools content changed.
82 void setDirty( const char * a1 = 0, const char * a2 = 0, const char * a3 = 0 );
84 /** Invalidate locale related housekeeping data.
86 void localeSetDirty( const char * a1 = 0, const char * a2 = 0, const char * a3 = 0 );
88 /** Invalidate housekeeping data (e.g. whatprovides) if dependencies changed.
90 void depSetDirty( const char * a1 = 0, const char * a2 = 0, const char * a3 = 0 );
92 /** Callback to resolve namespace dependencies (language, modalias, filesystem, etc.). */
93 static detail::IdType nsCallback( CPool *, void * data, detail::IdType lhs, detail::IdType rhs );
96 /** Reserved system repository alias \c @System. */
97 static const std::string & systemRepoAlias();
99 bool isSystemRepo( CRepo * repo_r ) const
100 { return repo_r && _pool->installed == repo_r; }
102 CRepo * systemRepo() const
103 { return _pool->installed; }
105 /** Get rootdir (for file conflicts check) */
106 Pathname rootDir() const
108 const char * rd = ::pool_get_rootdir( _pool );
109 return( rd ? rd : "/" );
112 /** Set rootdir (for file conflicts check) */
113 void rootDir( const Pathname & root_r )
115 if ( root_r.empty() || root_r == "/" )
116 ::pool_set_rootdir( _pool, nullptr );
118 ::pool_set_rootdir( _pool, root_r.c_str() );
122 /** \name Actions invalidating housekeeping data.
124 * All methods expect valid arguments being passed.
127 /** Creating a new repo named \a name_r. */
128 CRepo * _createRepo( const std::string & name_r );
130 /** Delete repo \a repo_r from pool. */
131 void _deleteRepo( CRepo * repo_r );
133 /** Adding solv file to a repo.
134 * Except for \c isSystemRepo_r, solvables of incompatible architecture
137 int _addSolv( CRepo * repo_r, FILE * file_r );
139 /** Adding helix file to a repo.
140 * Except for \c isSystemRepo_r, solvables of incompatible architecture
143 int _addHelix( CRepo * repo_r, FILE * file_r );
145 /** Adding Solvables to a repo. */
146 detail::SolvableIdType _addSolvables( CRepo * repo_r, unsigned count_r );
149 /** Helper postprocessing the repo after adding solv or helix files. */
150 void _postRepoAdd( CRepo * repo_r );
153 /** a \c valid \ref Solvable has a non NULL repo pointer. */
154 bool validSolvable( const CSolvable & slv_r ) const
155 { return slv_r.repo; }
156 /** \overload Check also for id_r being in range of _pool->solvables. */
157 bool validSolvable( SolvableIdType id_r ) const
158 { return id_r < unsigned(_pool->nsolvables) && validSolvable( _pool->solvables[id_r] ); }
159 /** \overload Check also for slv_r being in range of _pool->solvables. */
160 bool validSolvable( const CSolvable * slv_r ) const
161 { return _pool->solvables <= slv_r && slv_r <= _pool->solvables+_pool->nsolvables && validSolvable( *slv_r ); }
164 CPool * getPool() const
167 /** \todo a quick check whether the repo was meanwhile deleted. */
168 CRepo * getRepo( RepoIdType id_r ) const
171 /** Return pointer to the sat-solvable or NULL if it is not valid.
172 * \see \ref validSolvable.
174 CSolvable * getSolvable( SolvableIdType id_r ) const
176 if ( validSolvable( id_r ) )
177 return &_pool->solvables[id_r];
182 /** Get id of the first valid \ref Solvable.
183 * This is the next valid after the system solvable.
185 SolvableIdType getFirstId() const
186 { return getNextId( 1 ); }
188 /** Get id of the next valid \ref Solvable.
189 * This goes round robbin. At the end it returns \ref noSolvableId.
190 * Passing \ref noSolvableId it returns the 1st valid \ref Solvable.
191 * \see \ref validSolvable.
193 SolvableIdType getNextId( SolvableIdType id_r ) const
195 for( ++id_r; id_r < unsigned(_pool->nsolvables); ++id_r )
197 if ( validSolvable( _pool->solvables[id_r] ) )
205 const RepoInfo & repoInfo( RepoIdType id_r )
206 { return _repoinfos[id_r]; }
207 /** Also adjust repo priority and subpriority accordingly. */
208 void setRepoInfo( RepoIdType id_r, const RepoInfo & info_r );
210 void eraseRepoInfo( RepoIdType id_r )
211 { _repoinfos.erase( id_r ); }
214 /** Returns the id stored at \c offset_r in the internal
215 * whatprovidesdata array.
217 const sat::detail::IdType whatProvidesData( unsigned offset_r )
218 { return _pool->whatprovidesdata[offset_r]; }
220 /** Returns offset into the internal whatprovidesdata array.
221 * Use \ref whatProvidesData to get the stored Id.
223 unsigned whatProvides( Capability cap_r )
224 { prepare(); return ::pool_whatprovides( _pool, cap_r.id() ); }
227 /// \name Requested locales.
228 /// The requested LocaleSets managed in _requestedLocalesTracker
229 /// are unexpanded; i.e. they contain just the pure user selection.
230 /// The resolver however uses expanded sets ('de_DE' will also
231 /// include its fallback locales 'de', (en); here in the namespace:
232 /// callback and in the Resolver itself).
235 void setTextLocale( const Locale & locale_r );
238 /** Start tracking changes based on this \a locales_r.
239 * Usually called on TargetInit.
241 void initRequestedLocales( const LocaleSet & locales_r );
243 /** Added since last initRequestedLocales. */
244 const LocaleSet & getAddedRequestedLocales() const
245 { return _requestedLocalesTracker.added(); }
247 /** Removed since last initRequestedLocales. */
248 const LocaleSet & getRemovedRequestedLocales() const
249 { return _requestedLocalesTracker.removed(); }
251 /** Current set of requested Locales. */
252 const LocaleSet & getRequestedLocales() const
253 { return _requestedLocalesTracker.current(); }
255 bool isRequestedLocale( const Locale & locale_r ) const
256 { return _requestedLocalesTracker.contains( locale_r ); }
258 /** User change (tracked). */
259 void setRequestedLocales( const LocaleSet & locales_r );
260 /** User change (tracked). */
261 bool addRequestedLocale( const Locale & locale_r );
262 /** User change (tracked). */
263 bool eraseRequestedLocale( const Locale & locale_r );
265 /** All Locales occurring in any repo. */
266 const LocaleSet & getAvailableLocales() const;
268 bool isAvailableLocale( const Locale & locale_r ) const
270 const LocaleSet & avl( getAvailableLocales() );
271 LocaleSet::const_iterator it( avl.find( locale_r ) );
272 return it != avl.end();
275 typedef base::SetTracker<IdStringSet> TrackedLocaleIds;
277 /** Expanded _requestedLocalesTracker for solver.*/
278 const TrackedLocaleIds & trackedLocaleIds() const;
282 /** \name Multiversion install. */
284 typedef SolvableSet MultiversionList;
286 const MultiversionList & multiversionList() const;
288 bool isMultiversion( const Solvable & solv_r ) const;
290 void multiversionSpecChanged();
294 /** \name Installed on behalf of a user request hint. */
296 /** Get ident list of all autoinstalled solvables. */
297 StringQueue autoInstalled() const
298 { return _autoinstalled; }
300 /** Set ident list of all autoinstalled solvables. */
301 void setAutoInstalled( const StringQueue & autoInstalled_r )
302 { _autoinstalled = autoInstalled_r; }
304 bool isOnSystemByUser( IdString ident_r ) const
305 { return !_autoinstalled.contains( ident_r.id() ); }
307 bool isOnSystemByAuto( IdString ident_r ) const
308 { return _autoinstalled.contains( ident_r.id() ); }
310 /** Get ident list of all solvables that trigger the "reboot needed" flag. */
311 StringQueue rebootNeededIdents() const
312 { return _rebootNeeded; }
314 /** Set ident list of all solvables that trigger the "reboot needed" flag. */
315 void setRebootNeededIdents( const StringQueue & rebootNeeded_r )
316 { _rebootNeeded = rebootNeeded_r; }
318 bool triggersRebootNeededHint( IdString ident_r ) const
319 { return _rebootNeeded.contains( ident_r.id() ); }
324 /** accessor for etc/sysconfig/storage reading file on demand */
325 const std::set<std::string> & requiredFilesystems() const;
330 /** Serial number - changes with each Pool content change. */
331 SerialNumber _serial;
332 /** Serial number of IDs - changes whenever resusePoolIDs==true - ResPool must also invalidate it's PoolItems! */
333 SerialNumber _serialIDs;
334 /** Watch serial number. */
335 SerialNumberWatcher _watcher;
336 /** Additional \ref RepoInfo. */
337 std::map<RepoIdType,RepoInfo> _repoinfos;
340 base::SetTracker<LocaleSet> _requestedLocalesTracker;
341 mutable scoped_ptr<TrackedLocaleIds> _trackedLocaleIdsPtr;
343 mutable scoped_ptr<LocaleSet> _availableLocalesPtr;
346 void multiversionListInit() const;
347 mutable scoped_ptr<MultiversionList> _multiversionListPtr;
350 sat::StringQueue _autoinstalled;
352 /** database of all identifiers that will trigger the "reboot needed" flag */
353 sat::StringQueue _rebootNeeded;
355 /** filesystems mentioned in /etc/sysconfig/storage */
356 mutable scoped_ptr<std::set<std::string> > _requiredFilesystemsPtr;
358 ///////////////////////////////////////////////////////////////////
360 /////////////////////////////////////////////////////////////////
361 } // namespace detail
362 ///////////////////////////////////////////////////////////////////
363 /////////////////////////////////////////////////////////////////
365 ///////////////////////////////////////////////////////////////////
366 /////////////////////////////////////////////////////////////////
368 ///////////////////////////////////////////////////////////////////
369 #define POOL_SETDIRTY
370 #endif // ZYPP_SAT_DETAIL_POOLIMPL_H