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/Tr1hash.h"
25 #include "zypp/base/NonCopyable.h"
26 #include "zypp/base/SerialNumber.h"
27 #include "zypp/sat/detail/PoolMember.h"
28 #include "zypp/sat/Queue.h"
29 #include "zypp/RepoInfo.h"
30 #include "zypp/Locale.h"
31 #include "zypp/Capability.h"
32 #include "zypp/IdString.h"
34 ///////////////////////////////////////////////////////////////////
36 { /////////////////////////////////////////////////////////////////
37 ///////////////////////////////////////////////////////////////////
39 { /////////////////////////////////////////////////////////////////
40 ///////////////////////////////////////////////////////////////////
42 { /////////////////////////////////////////////////////////////////
44 ///////////////////////////////////////////////////////////////////
46 // CLASS NAME : PoolImpl
49 class PoolImpl : private base::NonCopyable
58 /** Pointer style access forwarded to sat-pool. */
63 /** Serial number changing whenever the content changes. */
64 const SerialNumber & serial() const
67 /** Update housekeeping data (e.g. whatprovides).
68 * \todo actually requires a watcher.
71 /** \ref prepare plus some expensive checks done before solving only. */
72 void prepareForSolving() const;
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 housekeeping data (e.g. whatprovides) if dependencies changed.
82 void depSetDirty( const char * a1 = 0, const char * a2 = 0, const char * a3 = 0 );
84 /** Callback to resolve namespace dependencies (language, modalias, filesystem, etc.). */
85 static detail::IdType nsCallback( CPool *, void * data, detail::IdType lhs, detail::IdType rhs );
88 /** Reserved system repository alias \c @System. */
89 static const std::string & systemRepoAlias();
91 bool isSystemRepo( CRepo * repo_r ) const
92 { return repo_r && _pool->installed == repo_r; }
94 CRepo * systemRepo() const
95 { return _pool->installed; }
97 /** Get rootdir (for file conflicts check) */
98 Pathname rootDir() const
100 const char * rd = ::pool_get_rootdir( _pool );
101 return( rd ? rd : "/" );
104 /** Set rootdir (for file conflicts check) */
105 void rootDir( const Pathname & root_r )
107 if ( root_r.empty() || root_r == "/" )
108 ::pool_set_rootdir( _pool, nullptr );
110 ::pool_set_rootdir( _pool, root_r.c_str() );
114 /** \name Actions invalidating housekeeping data.
116 * All methods expect valid arguments being passed.
119 /** Creating a new repo named \a name_r. */
120 CRepo * _createRepo( const std::string & name_r );
122 /** Creating a new repo named \a name_r. */
123 void _deleteRepo( CRepo * repo_r );
125 /** Adding solv file to a repo.
126 * Except for \c isSystemRepo_r, solvables of incompatible architecture
129 int _addSolv( CRepo * repo_r, FILE * file_r );
131 /** Adding helix file to a repo.
132 * Except for \c isSystemRepo_r, solvables of incompatible architecture
135 int _addHelix( CRepo * repo_r, FILE * file_r );
137 /** Adding Solvables to a repo. */
138 detail::SolvableIdType _addSolvables( CRepo * repo_r, unsigned count_r );
141 /** Helper postprocessing the repo after adding solv or helix files. */
142 void _postRepoAdd( CRepo * repo_r );
145 /** a \c valid \ref Solvable has a non NULL repo pointer. */
146 bool validSolvable( const CSolvable & slv_r ) const
147 { return slv_r.repo; }
148 /** \overload Check also for id_r being in range of _pool->solvables. */
149 bool validSolvable( SolvableIdType id_r ) const
150 { return id_r < unsigned(_pool->nsolvables) && validSolvable( _pool->solvables[id_r] ); }
151 /** \overload Check also for slv_r being in range of _pool->solvables. */
152 bool validSolvable( const CSolvable * slv_r ) const
153 { return _pool->solvables <= slv_r && slv_r <= _pool->solvables+_pool->nsolvables && validSolvable( *slv_r ); }
156 CPool * getPool() const
159 /** \todo a quick check whether the repo was meanwhile deleted. */
160 CRepo * getRepo( RepoIdType id_r ) const
163 /** Return pointer to the sat-solvable or NULL if it is not valid.
164 * \see \ref validSolvable.
166 CSolvable * getSolvable( SolvableIdType id_r ) const
168 if ( validSolvable( id_r ) )
169 return &_pool->solvables[id_r];
174 /** Get id of the first valid \ref Solvable.
175 * This is the next valid after the system solvable.
177 SolvableIdType getFirstId() const
178 { return getNextId( 1 ); }
180 /** Get id of the next valid \ref Solvable.
181 * This goes round robbin. At the end it returns \ref noSolvableId.
182 * Passing \ref noSolvableId it returns the 1st valid \ref Solvable.
183 * \see \ref validSolvable.
185 SolvableIdType getNextId( SolvableIdType id_r ) const
187 for( ++id_r; id_r < unsigned(_pool->nsolvables); ++id_r )
189 if ( validSolvable( _pool->solvables[id_r] ) )
197 const RepoInfo & repoInfo( RepoIdType id_r )
198 { return _repoinfos[id_r]; }
199 /** Also adjust repo priority and subpriority accordingly. */
200 void setRepoInfo( RepoIdType id_r, const RepoInfo & info_r );
202 void eraseRepoInfo( RepoIdType id_r )
203 { _repoinfos.erase( id_r ); }
206 /** Returns the id stored at \c offset_r in the internal
207 * whatprovidesdata array.
209 const sat::detail::IdType whatProvidesData( unsigned offset_r )
210 { return _pool->whatprovidesdata[offset_r]; }
212 /** Returns offset into the internal whatprovidesdata array.
213 * Use \ref whatProvidesData to get the stored Id.
215 unsigned whatProvides( Capability cap_r )
216 { prepare(); return ::pool_whatprovides( _pool, cap_r.id() ); }
219 /** \name Requested locales. */
221 void setTextLocale( const Locale & locale_r );
222 void setRequestedLocales( const LocaleSet & locales_r );
223 bool addRequestedLocale( const Locale & locale_r );
224 bool eraseRequestedLocale( const Locale & locale_r );
226 const LocaleSet & getRequestedLocales() const
227 { return _requestedLocales; }
229 bool isRequestedLocale( const Locale & locale_r ) const
231 LocaleSet::const_iterator it( _requestedLocales.find( locale_r ) );
232 return it != _requestedLocales.end();
235 const LocaleSet & getAvailableLocales() const;
237 bool isAvailableLocale( const Locale & locale_r ) const
239 const LocaleSet & avl( getAvailableLocales() );
240 LocaleSet::const_iterator it( avl.find( locale_r ) );
241 return it != avl.end();
246 /** \name Multiversion install. */
248 typedef IdStringSet MultiversionList;
250 const MultiversionList & multiversionList() const
252 if ( ! _multiversionListPtr )
253 multiversionListInit();
254 return *_multiversionListPtr;
257 bool isMultiversion( IdString ident_r ) const
259 const MultiversionList & l( multiversionList() );
260 return l.find( ident_r ) != l.end();
265 /** \name Installed on behalf of a user request hint. */
267 /** Get ident list of all autoinstalled solvables. */
268 StringQueue autoInstalled() const
269 { return _autoinstalled; }
271 /** Set ident list of all autoinstalled solvables. */
272 void setAutoInstalled( const StringQueue & autoInstalled_r )
273 { _autoinstalled = autoInstalled_r; }
275 bool isOnSystemByUser( IdString ident_r ) const
276 { return !_autoinstalled.contains( ident_r.id() ); }
280 /** accessor for etc/sysconfig/storage reading file on demand */
281 const std::set<std::string> & requiredFilesystems() const;
286 /** Serial number. */
287 SerialNumber _serial;
288 /** Watch serial number. */
289 SerialNumberWatcher _watcher;
290 /** Additional \ref RepoInfo. */
291 std::map<RepoIdType,RepoInfo> _repoinfos;
294 LocaleSet _requestedLocales;
295 mutable scoped_ptr<LocaleSet> _availableLocalesPtr;
296 mutable std::tr1::unordered_set<IdString> _locale2Solver;
299 void multiversionListInit() const;
300 mutable scoped_ptr<MultiversionList> _multiversionListPtr;
303 sat::StringQueue _autoinstalled;
305 /** filesystems mentioned in /etc/sysconfig/storage */
306 mutable scoped_ptr<std::set<std::string> > _requiredFilesystemsPtr;
308 ///////////////////////////////////////////////////////////////////
310 /////////////////////////////////////////////////////////////////
311 } // namespace detail
312 ///////////////////////////////////////////////////////////////////
313 /////////////////////////////////////////////////////////////////
315 ///////////////////////////////////////////////////////////////////
316 /////////////////////////////////////////////////////////////////
318 ///////////////////////////////////////////////////////////////////
319 #define POOL_SETDIRTY
320 #endif // ZYPP_SAT_DETAIL_POOLIMPL_H