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 Repository Pool::reposInsert( const std::string & alias_r )
124 Repository ret( reposFind( alias_r ) );
128 ret = Repository( myPool()._createRepo( alias_r ) );
129 if ( ret.isSystemRepo() )
131 // autoprovide (dummy) RepoInfo
133 info.setAlias( alias_r );
134 info.setName( alias_r );
135 info.setAutorefresh( true );
136 info.setEnabled( true );
142 Repository Pool::reposFind( const std::string & alias_r ) const
144 for_( it, reposBegin(), reposEnd() )
146 if ( alias_r == it->alias() )
152 Repository Pool::findSystemRepo() const
154 return Repository( myPool().systemRepo() );
157 Repository Pool::systemRepo()
159 if ( myPool().systemRepo() )
160 return Repository( myPool().systemRepo() );
161 return reposInsert( systemRepoAlias() );
164 Repository Pool::addRepoSolv( const Pathname & file_r, const std::string & alias_r )
166 // Using a temporay repo! (The additional parenthesis are required.)
167 AutoDispose<Repository> tmprepo( (Repository::EraseFromPool()) );
168 *tmprepo = reposInsert( alias_r );
169 tmprepo->addSolv( file_r );
171 // no exceptions so we keep it:
172 tmprepo.resetDispose();
176 Repository Pool::addRepoSolv( const Pathname & file_r )
177 { return addRepoSolv( file_r, file_r.basename() ); }
179 Repository Pool::addRepoSolv( const Pathname & file_r, const RepoInfo & info_r )
181 Repository ret( addRepoSolv( file_r, info_r.alias() ) );
182 ret.setInfo( info_r );
186 /////////////////////////////////////////////////////////////////
188 Repository Pool::addRepoHelix( const Pathname & file_r, const std::string & alias_r )
190 // Using a temporay repo! (The additional parenthesis are required.)
191 AutoDispose<Repository> tmprepo( (Repository::EraseFromPool()) );
192 *tmprepo = reposInsert( alias_r );
193 tmprepo->addHelix( file_r );
195 // no exceptions so we keep it:
196 tmprepo.resetDispose();
200 Repository Pool::addRepoHelix( const Pathname & file_r )
201 { return addRepoHelix( file_r, file_r.basename() ); }
203 Repository Pool::addRepoHelix( const Pathname & file_r, const RepoInfo & info_r )
205 Repository ret( addRepoHelix( file_r, info_r.alias() ) );
206 ret.setInfo( info_r );
210 /////////////////////////////////////////////////////////////////
212 void Pool::setTextLocale( const Locale & locale_r )
213 { myPool().setTextLocale( locale_r ); }
215 void Pool::setRequestedLocales( const LocaleSet & locales_r )
216 { myPool().setRequestedLocales( locales_r ); }
218 bool Pool::addRequestedLocale( const Locale & locale_r )
219 { return myPool().addRequestedLocale( locale_r ); }
221 bool Pool::eraseRequestedLocale( const Locale & locale_r )
222 { return myPool().eraseRequestedLocale( locale_r ); }
224 const LocaleSet & Pool::getRequestedLocales() const
225 { return myPool().getRequestedLocales(); }
227 bool Pool::isRequestedLocale( const Locale & locale_r ) const
228 { return myPool().isRequestedLocale( locale_r ); }
230 void Pool::initRequestedLocales( const LocaleSet & locales_r ) { myPool().initRequestedLocales( locales_r ); }
231 const LocaleSet & Pool::getAddedRequestedLocales() const { return myPool().getAddedRequestedLocales(); }
232 const LocaleSet & Pool::getRemovedRequestedLocales() const { return myPool().getRemovedRequestedLocales(); }
234 const LocaleSet & Pool::getAvailableLocales() const
235 { return myPool().getAvailableLocales(); }
237 bool Pool::isAvailableLocale( const Locale & locale_r ) const
238 { return myPool().isAvailableLocale( locale_r ); }
240 const Pool::MultiversionList & Pool::multiversion() const
241 { return myPool().multiversionList(); }
243 Queue Pool::autoInstalled() const { return myPool().autoInstalled(); }
244 void Pool::setAutoInstalled( const Queue & autoInstalled_r ){ myPool().setAutoInstalled( autoInstalled_r ); }
246 void Pool::setNeedrebootSpec( sat::SolvableSpec needrebootSpec_r ) { myPool().setNeedrebootSpec( std::move(needrebootSpec_r) ); }
248 /******************************************************************
250 ** FUNCTION NAME : operator<<
251 ** FUNCTION TYPE : std::ostream &
253 std::ostream & operator<<( std::ostream & str, const Pool & obj )
255 return str << "sat::pool(" << obj.serial() << ")["
256 << obj.capacity() << "]{"
257 << obj.reposSize() << "repos|"
258 << obj.solvablesSize() << "solv}";
261 /////////////////////////////////////////////////////////////////
262 #undef ZYPP_BASE_LOGGER_LOGGROUP
263 #define ZYPP_BASE_LOGGER_LOGGROUP "solvidx"
265 void updateSolvFileIndex( const Pathname & solvfile_r )
267 AutoDispose<FILE*> solv( ::fopen( solvfile_r.c_str(), "re" ), ::fclose );
271 ERR << "Can't open solv-file: " << solv << endl;
275 std::string solvidxfile( solvfile_r.extend(".idx").asString() );
276 if ( ::unlink( solvidxfile.c_str() ) == -1 && errno != ENOENT )
278 ERR << "Can't unlink solv-idx: " << Errno() << endl;
282 int fd = ::open( solvidxfile.c_str(), O_CREAT|O_EXCL|O_WRONLY|O_TRUNC, 0644 );
285 ERR << "Can't create solv-idx: " << Errno() << endl;
290 std::ofstream idx( solvidxfile.c_str() );
293 detail::CPool * _pool = ::pool_create();
294 detail::CRepo * _repo = ::repo_create( _pool, "" );
295 if ( ::repo_add_solv( _repo, solv, 0 ) == 0 )
298 detail::CSolvable * _solv = nullptr;
299 FOR_REPO_SOLVABLES( _repo, _id, _solv )
304 #define idstr(V) pool_id2str( _pool, _solv->V )
305 if ( _solv->arch == ARCH_SRC || _solv->arch == ARCH_NOSRC )
306 idx << "srcpackage:" << idstr(name) << SEP << idstr(evr) << SEP << "noarch" << endl;
308 idx << idstr(name) << SEP << idstr(evr) << SEP << idstr(arch) << endl;
314 ERR << "Can't read solv-file: " << ::pool_errstr( _pool ) << endl;
316 ::repo_free( _repo, 0 );
317 ::pool_free( _pool );
320 /////////////////////////////////////////////////////////////////
322 ///////////////////////////////////////////////////////////////////
323 /////////////////////////////////////////////////////////////////
325 ///////////////////////////////////////////////////////////////////