1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/sat/Pool.cc
12 #include <sys/types.h>
18 #include <solv/pool.h>
19 #include <solv/repo.h>
20 #include <solv/solvable.h>
26 #include "zypp/base/Easy.h"
27 #include "zypp/base/Logger.h"
28 #include "zypp/base/Gettext.h"
29 #include "zypp/base/Exception.h"
31 #include "zypp/AutoDispose.h"
33 #include "zypp/sat/detail/PoolImpl.h"
34 #include "zypp/sat/Pool.h"
35 #include "zypp/sat/LookupAttr.h"
39 ///////////////////////////////////////////////////////////////////
41 { /////////////////////////////////////////////////////////////////
42 ///////////////////////////////////////////////////////////////////
44 { /////////////////////////////////////////////////////////////////
46 const std::string & Pool::systemRepoAlias()
47 { return detail::PoolImpl::systemRepoAlias(); }
49 detail::CPool * Pool::get() const
50 { return myPool().getPool(); }
52 Pool::size_type Pool::capacity() const
53 { return myPool()->nsolvables; }
55 const SerialNumber & Pool::serial() const
56 { return myPool().serial(); }
58 const SerialNumber & Pool::serialIDs() const
59 { return myPool().serialIDs(); }
61 void Pool::prepare() const
62 { return myPool().prepare(); }
64 Pathname Pool::rootDir() const
65 { return myPool().rootDir(); }
67 void Pool::rootDir( const Pathname & root_r )
68 { return myPool().rootDir( root_r ); }
70 bool Pool::reposEmpty() const
71 { return ! myPool()->urepos; }
73 Pool::size_type Pool::reposSize() const
74 { return myPool()->urepos; }
76 Pool::RepositoryIterator Pool::reposBegin() const
78 if ( myPool()->urepos )
80 for_( it, myPool()->repos+1, myPool()->repos+myPool()->nrepos )
82 return RepositoryIterator( it );
87 Pool::RepositoryIterator Pool::reposEnd() const
88 { return RepositoryIterator( myPool()->repos+myPool()->nrepos ); }
90 bool Pool::solvablesEmpty() const
92 // return myPool()->nsolvables;
93 // nsolvables is the array size including
95 for_( it, reposBegin(), reposEnd() )
97 if ( ! it->solvablesEmpty() )
103 Pool::size_type Pool::solvablesSize() const
105 // Do not return myPool()->nsolvables;
106 // nsolvables is the array size including
107 // invalid Solvables.
109 for_( it, reposBegin(), reposEnd() )
111 ret += it->solvablesSize();
116 Pool::SolvableIterator Pool::solvablesBegin() const
117 { return SolvableIterator( myPool().getFirstId() ); }
119 Pool::SolvableIterator Pool::solvablesEnd() const
120 { return SolvableIterator(); }
122 sat::Queue Pool::whatMatchesDep( const SolvAttr &attr, const Capability &cap ) const
125 pool_whatmatchesdep( get(), attr.id(), cap.id(), q, 0);
129 Queue Pool::whatMatchesSolvable( const SolvAttr &attr, const Solvable &solv ) const
132 pool_whatmatchessolvable( get(), attr.id(), static_cast<Id>( solv.id() ), q, 0 );
136 Queue Pool::whatContainsDep( const SolvAttr &attr, const Capability &cap ) const
139 pool_whatcontainsdep( get(), attr.id(), cap.id(), q, 0 );
143 Repository Pool::reposInsert( const std::string & alias_r )
145 Repository ret( reposFind( alias_r ) );
149 ret = Repository( myPool()._createRepo( alias_r ) );
150 if ( ret.isSystemRepo() )
152 // autoprovide (dummy) RepoInfo
154 info.setAlias( alias_r );
155 info.setName( alias_r );
156 info.setAutorefresh( true );
157 info.setEnabled( true );
163 Repository Pool::reposFind( const std::string & alias_r ) const
165 for_( it, reposBegin(), reposEnd() )
167 if ( alias_r == it->alias() )
173 Repository Pool::findSystemRepo() const
175 return Repository( myPool().systemRepo() );
178 Repository Pool::systemRepo()
180 if ( myPool().systemRepo() )
181 return Repository( myPool().systemRepo() );
182 return reposInsert( systemRepoAlias() );
185 Repository Pool::addRepoSolv( const Pathname & file_r, const std::string & alias_r )
187 // Using a temporay repo! (The additional parenthesis are required.)
188 AutoDispose<Repository> tmprepo( (Repository::EraseFromPool()) );
189 *tmprepo = reposInsert( alias_r );
190 tmprepo->addSolv( file_r );
192 // no exceptions so we keep it:
193 tmprepo.resetDispose();
197 Repository Pool::addRepoSolv( const Pathname & file_r )
198 { return addRepoSolv( file_r, file_r.basename() ); }
200 Repository Pool::addRepoSolv( const Pathname & file_r, const RepoInfo & info_r )
202 Repository ret( addRepoSolv( file_r, info_r.alias() ) );
203 ret.setInfo( info_r );
207 /////////////////////////////////////////////////////////////////
209 Repository Pool::addRepoHelix( const Pathname & file_r, const std::string & alias_r )
211 // Using a temporay repo! (The additional parenthesis are required.)
212 AutoDispose<Repository> tmprepo( (Repository::EraseFromPool()) );
213 *tmprepo = reposInsert( alias_r );
214 tmprepo->addHelix( file_r );
216 // no exceptions so we keep it:
217 tmprepo.resetDispose();
221 Repository Pool::addRepoHelix( const Pathname & file_r )
222 { return addRepoHelix( file_r, file_r.basename() ); }
224 Repository Pool::addRepoHelix( const Pathname & file_r, const RepoInfo & info_r )
226 Repository ret( addRepoHelix( file_r, info_r.alias() ) );
227 ret.setInfo( info_r );
231 /////////////////////////////////////////////////////////////////
233 void Pool::setTextLocale( const Locale & locale_r )
234 { myPool().setTextLocale( locale_r ); }
236 void Pool::setRequestedLocales( const LocaleSet & locales_r )
237 { myPool().setRequestedLocales( locales_r ); }
239 bool Pool::addRequestedLocale( const Locale & locale_r )
240 { return myPool().addRequestedLocale( locale_r ); }
242 bool Pool::eraseRequestedLocale( const Locale & locale_r )
243 { return myPool().eraseRequestedLocale( locale_r ); }
245 const LocaleSet & Pool::getRequestedLocales() const
246 { return myPool().getRequestedLocales(); }
248 bool Pool::isRequestedLocale( const Locale & locale_r ) const
249 { return myPool().isRequestedLocale( locale_r ); }
251 void Pool::initRequestedLocales( const LocaleSet & locales_r ) { myPool().initRequestedLocales( locales_r ); }
252 const LocaleSet & Pool::getAddedRequestedLocales() const { return myPool().getAddedRequestedLocales(); }
253 const LocaleSet & Pool::getRemovedRequestedLocales() const { return myPool().getRemovedRequestedLocales(); }
255 const LocaleSet & Pool::getAvailableLocales() const
256 { return myPool().getAvailableLocales(); }
258 bool Pool::isAvailableLocale( const Locale & locale_r ) const
259 { return myPool().isAvailableLocale( locale_r ); }
261 const Pool::MultiversionList & Pool::multiversion() const
262 { return myPool().multiversionList(); }
264 Queue Pool::autoInstalled() const { return myPool().autoInstalled(); }
265 void Pool::setAutoInstalled( const Queue & autoInstalled_r ){ myPool().setAutoInstalled( autoInstalled_r ); }
267 void Pool::setNeedrebootSpec( sat::SolvableSpec needrebootSpec_r ) { myPool().setNeedrebootSpec( std::move(needrebootSpec_r) ); }
269 /******************************************************************
271 ** FUNCTION NAME : operator<<
272 ** FUNCTION TYPE : std::ostream &
274 std::ostream & operator<<( std::ostream & str, const Pool & obj )
276 return str << "sat::pool(" << obj.serial() << ")["
277 << obj.capacity() << "]{"
278 << obj.reposSize() << "repos|"
279 << obj.solvablesSize() << "solv}";
282 /////////////////////////////////////////////////////////////////
283 #undef ZYPP_BASE_LOGGER_LOGGROUP
284 #define ZYPP_BASE_LOGGER_LOGGROUP "solvidx"
286 void updateSolvFileIndex( const Pathname & solvfile_r )
288 AutoDispose<FILE*> solv( ::fopen( solvfile_r.c_str(), "re" ), ::fclose );
292 ERR << "Can't open solv-file: " << solv << endl;
296 std::string solvidxfile( solvfile_r.extend(".idx").asString() );
297 if ( ::unlink( solvidxfile.c_str() ) == -1 && errno != ENOENT )
299 ERR << "Can't unlink solv-idx: " << Errno() << endl;
303 int fd = ::open( solvidxfile.c_str(), O_CREAT|O_EXCL|O_WRONLY|O_TRUNC, 0644 );
306 ERR << "Can't create solv-idx: " << Errno() << endl;
311 std::ofstream idx( solvidxfile.c_str() );
314 detail::CPool * _pool = ::pool_create();
315 detail::CRepo * _repo = ::repo_create( _pool, "" );
316 if ( ::repo_add_solv( _repo, solv, 0 ) == 0 )
319 detail::CSolvable * _solv = nullptr;
320 FOR_REPO_SOLVABLES( _repo, _id, _solv )
325 #define idstr(V) pool_id2str( _pool, _solv->V )
326 if ( _solv->arch == ARCH_SRC || _solv->arch == ARCH_NOSRC )
327 idx << "srcpackage:" << idstr(name) << SEP << idstr(evr) << SEP << "noarch" << endl;
329 idx << idstr(name) << SEP << idstr(evr) << SEP << idstr(arch) << endl;
335 ERR << "Can't read solv-file: " << ::pool_errstr( _pool ) << endl;
337 ::repo_free( _repo, 0 );
338 ::pool_free( _pool );
341 /////////////////////////////////////////////////////////////////
343 ///////////////////////////////////////////////////////////////////
344 /////////////////////////////////////////////////////////////////
346 ///////////////////////////////////////////////////////////////////