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/SolvableSpec.h>
30 #include <zypp/sat/Queue.h>
31 #include <zypp/RepoInfo.h>
32 #include <zypp/Locale.h>
33 #include <zypp/Capability.h>
34 #include <zypp/IdString.h>
36 ///////////////////////////////////////////////////////////////////
38 { /////////////////////////////////////////////////////////////////
39 ///////////////////////////////////////////////////////////////////
41 { /////////////////////////////////////////////////////////////////
43 ///////////////////////////////////////////////////////////////////
45 { /////////////////////////////////////////////////////////////////
47 ///////////////////////////////////////////////////////////////////
49 // CLASS NAME : PoolImpl
52 class PoolImpl : private base::NonCopyable
61 /** Pointer style access forwarded to sat-pool. */
66 /** Serial number changing whenever the content changes. */
67 const SerialNumber & serial() const
70 /** Serial number changing whenever resusePoolIDs==true was used. ResPool must also invalidate it's PoolItems! */
71 const SerialNumber & serialIDs() const
72 { return _serialIDs; }
74 /** Update housekeeping data (e.g. whatprovides).
75 * \todo actually requires a watcher.
80 /** Invalidate housekeeping data (e.g. whatprovides) if the
81 * pools content changed.
83 void setDirty( const char * a1 = 0, const char * a2 = 0, const char * a3 = 0 );
85 /** Invalidate locale related housekeeping data.
87 void localeSetDirty( const char * a1 = 0, const char * a2 = 0, const char * a3 = 0 );
89 /** Invalidate housekeeping data (e.g. whatprovides) if dependencies changed.
91 void depSetDirty( const char * a1 = 0, const char * a2 = 0, const char * a3 = 0 );
93 /** Callback to resolve namespace dependencies (language, modalias, filesystem, etc.). */
94 static detail::IdType nsCallback( CPool *, void * data, detail::IdType lhs, detail::IdType rhs );
97 /** Reserved system repository alias \c @System. */
98 static const std::string & systemRepoAlias();
100 bool isSystemRepo( CRepo * repo_r ) const
101 { return repo_r && _pool->installed == repo_r; }
103 CRepo * systemRepo() const
104 { return _pool->installed; }
106 /** Get rootdir (for file conflicts check) */
107 Pathname rootDir() const
109 const char * rd = ::pool_get_rootdir( _pool );
110 return( rd ? rd : "/" );
113 /** Set rootdir (for file conflicts check) */
114 void rootDir( const Pathname & root_r )
116 if ( root_r.empty() || root_r == "/" )
117 ::pool_set_rootdir( _pool, nullptr );
119 ::pool_set_rootdir( _pool, root_r.c_str() );
123 /** \name Actions invalidating housekeeping data.
125 * All methods expect valid arguments being passed.
128 /** Creating a new repo named \a name_r. */
129 CRepo * _createRepo( const std::string & name_r );
131 /** Delete repo \a repo_r from pool. */
132 void _deleteRepo( CRepo * repo_r );
134 /** Adding solv file to a repo.
135 * Except for \c isSystemRepo_r, solvables of incompatible architecture
138 int _addSolv( CRepo * repo_r, FILE * file_r );
140 /** Adding helix file to a repo.
141 * Except for \c isSystemRepo_r, solvables of incompatible architecture
144 int _addHelix( CRepo * repo_r, FILE * file_r );
146 /** Adding Solvables to a repo. */
147 detail::SolvableIdType _addSolvables( CRepo * repo_r, unsigned count_r );
150 /** Helper postprocessing the repo after adding solv or helix files. */
151 void _postRepoAdd( CRepo * repo_r );
154 /** a \c valid \ref Solvable has a non NULL repo pointer. */
155 bool validSolvable( const CSolvable & slv_r ) const
156 { return slv_r.repo; }
157 /** \overload Check also for id_r being in range of _pool->solvables. */
158 bool validSolvable( SolvableIdType id_r ) const
159 { return id_r < unsigned(_pool->nsolvables) && validSolvable( _pool->solvables[id_r] ); }
160 /** \overload Check also for slv_r being in range of _pool->solvables. */
161 bool validSolvable( const CSolvable * slv_r ) const
162 { return _pool->solvables <= slv_r && slv_r <= _pool->solvables+_pool->nsolvables && validSolvable( *slv_r ); }
165 CPool * getPool() const
168 /** \todo a quick check whether the repo was meanwhile deleted. */
169 CRepo * getRepo( RepoIdType id_r ) const
172 /** Return pointer to the sat-solvable or NULL if it is not valid.
173 * \see \ref validSolvable.
175 CSolvable * getSolvable( SolvableIdType id_r ) const
177 if ( validSolvable( id_r ) )
178 return &_pool->solvables[id_r];
183 /** Get id of the first valid \ref Solvable.
184 * This is the next valid after the system solvable.
186 SolvableIdType getFirstId() const
187 { return getNextId( 1 ); }
189 /** Get id of the next valid \ref Solvable.
190 * This goes round robbin. At the end it returns \ref noSolvableId.
191 * Passing \ref noSolvableId it returns the 1st valid \ref Solvable.
192 * \see \ref validSolvable.
194 SolvableIdType getNextId( SolvableIdType id_r ) const
196 for( ++id_r; id_r < unsigned(_pool->nsolvables); ++id_r )
198 if ( validSolvable( _pool->solvables[id_r] ) )
206 const RepoInfo & repoInfo( RepoIdType id_r )
207 { return _repoinfos[id_r]; }
208 /** Also adjust repo priority and subpriority accordingly. */
209 void setRepoInfo( RepoIdType id_r, const RepoInfo & info_r );
211 void eraseRepoInfo( RepoIdType id_r )
212 { _repoinfos.erase( id_r ); }
215 /** Returns the id stored at \c offset_r in the internal
216 * whatprovidesdata array.
218 const sat::detail::IdType whatProvidesData( unsigned offset_r )
219 { return _pool->whatprovidesdata[offset_r]; }
221 /** Returns offset into the internal whatprovidesdata array.
222 * Use \ref whatProvidesData to get the stored Id.
224 unsigned whatProvides( Capability cap_r )
225 { prepare(); return ::pool_whatprovides( _pool, cap_r.id() ); }
228 /// \name Requested locales.
229 /// The requested LocaleSets managed in _requestedLocalesTracker
230 /// are unexpanded; i.e. they contain just the pure user selection.
231 /// The resolver however uses expanded sets ('de_DE' will also
232 /// include its fallback locales 'de', (en); here in the namespace:
233 /// callback and in the Resolver itself).
236 void setTextLocale( const Locale & locale_r );
239 /** Start tracking changes based on this \a locales_r.
240 * Usually called on TargetInit.
242 void initRequestedLocales( const LocaleSet & locales_r );
244 /** Added since last initRequestedLocales. */
245 const LocaleSet & getAddedRequestedLocales() const
246 { return _requestedLocalesTracker.added(); }
248 /** Removed since last initRequestedLocales. */
249 const LocaleSet & getRemovedRequestedLocales() const
250 { return _requestedLocalesTracker.removed(); }
252 /** Current set of requested Locales. */
253 const LocaleSet & getRequestedLocales() const
254 { return _requestedLocalesTracker.current(); }
256 bool isRequestedLocale( const Locale & locale_r ) const
257 { return _requestedLocalesTracker.contains( locale_r ); }
259 /** User change (tracked). */
260 void setRequestedLocales( const LocaleSet & locales_r );
261 /** User change (tracked). */
262 bool addRequestedLocale( const Locale & locale_r );
263 /** User change (tracked). */
264 bool eraseRequestedLocale( const Locale & locale_r );
266 /** All Locales occurring in any repo. */
267 const LocaleSet & getAvailableLocales() const;
269 bool isAvailableLocale( const Locale & locale_r ) const
271 const LocaleSet & avl( getAvailableLocales() );
272 LocaleSet::const_iterator it( avl.find( locale_r ) );
273 return it != avl.end();
276 typedef base::SetTracker<IdStringSet> TrackedLocaleIds;
278 /** Expanded _requestedLocalesTracker for solver.*/
279 const TrackedLocaleIds & trackedLocaleIds() const;
283 /** \name Multiversion install. */
285 typedef SolvableSet MultiversionList;
287 const MultiversionList & multiversionList() const;
289 bool isMultiversion( const Solvable & solv_r ) const;
291 void multiversionSpecChanged();
295 /** \name Installed on behalf of a user request hint. */
297 /** Get ident list of all autoinstalled solvables. */
298 StringQueue autoInstalled() const
299 { return _autoinstalled; }
301 /** Set ident list of all autoinstalled solvables. */
302 void setAutoInstalled( const StringQueue & autoInstalled_r )
303 { _autoinstalled = autoInstalled_r; }
305 bool isOnSystemByUser( IdString ident_r ) const
306 { return !_autoinstalled.contains( ident_r.id() ); }
308 bool isOnSystemByAuto( IdString ident_r ) const
309 { return _autoinstalled.contains( ident_r.id() ); }
313 /** \name Solvables which should trigger the reboot-needed hint if installed/updated. */
315 /** Set new Solvable specs.*/
316 void setNeedrebootSpec( sat::SolvableSpec needrebootSpec_r )
318 _needrebootSpec = std::move(needrebootSpec_r);
319 _needrebootSpec.setDirty();
322 /** Whether \a solv_r matches the spec.*/
323 bool isNeedreboot( const Solvable & solv_r ) const
324 { return _needrebootSpec.contains( solv_r ); }
328 /** accessor for etc/sysconfig/storage reading file on demand */
329 const std::set<std::string> & requiredFilesystems() const;
334 /** Serial number - changes with each Pool content change. */
335 SerialNumber _serial;
336 /** Serial number of IDs - changes whenever resusePoolIDs==true - ResPool must also invalidate it's PoolItems! */
337 SerialNumber _serialIDs;
338 /** Watch serial number. */
339 SerialNumberWatcher _watcher;
340 /** Additional \ref RepoInfo. */
341 std::map<RepoIdType,RepoInfo> _repoinfos;
344 base::SetTracker<LocaleSet> _requestedLocalesTracker;
345 mutable scoped_ptr<TrackedLocaleIds> _trackedLocaleIdsPtr;
347 mutable scoped_ptr<LocaleSet> _availableLocalesPtr;
350 void multiversionListInit() const;
351 mutable scoped_ptr<MultiversionList> _multiversionListPtr;
354 sat::StringQueue _autoinstalled;
356 /** Solvables which should trigger the reboot-needed hint if installed/updated. */
357 sat::SolvableSpec _needrebootSpec;
359 /** filesystems mentioned in /etc/sysconfig/storage */
360 mutable scoped_ptr<std::set<std::string> > _requiredFilesystemsPtr;
362 ///////////////////////////////////////////////////////////////////
364 /////////////////////////////////////////////////////////////////
365 } // namespace detail
366 ///////////////////////////////////////////////////////////////////
367 /////////////////////////////////////////////////////////////////
369 ///////////////////////////////////////////////////////////////////
370 /////////////////////////////////////////////////////////////////
372 ///////////////////////////////////////////////////////////////////
373 #define POOL_SETDIRTY
374 #endif // ZYPP_SAT_DETAIL_POOLIMPL_H