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 void Pool::prepare() const
59 { return myPool().prepare(); }
61 Pathname Pool::rootDir() const
62 { return myPool().rootDir(); }
64 void Pool::rootDir( const Pathname & root_r )
65 { return myPool().rootDir( root_r ); }
67 bool Pool::reposEmpty() const
68 { return ! myPool()->urepos; }
70 Pool::size_type Pool::reposSize() const
71 { return myPool()->urepos; }
73 Pool::RepositoryIterator Pool::reposBegin() const
75 if ( myPool()->urepos )
77 for_( it, myPool()->repos+1, myPool()->repos+myPool()->nrepos )
79 return RepositoryIterator( it );
84 Pool::RepositoryIterator Pool::reposEnd() const
85 { return RepositoryIterator( myPool()->repos+myPool()->nrepos ); }
87 bool Pool::solvablesEmpty() const
89 // return myPool()->nsolvables;
90 // nsolvables is the array size including
92 for_( it, reposBegin(), reposEnd() )
94 if ( ! it->solvablesEmpty() )
100 Pool::size_type Pool::solvablesSize() const
102 // Do not return myPool()->nsolvables;
103 // nsolvables is the array size including
104 // invalid Solvables.
106 for_( it, reposBegin(), reposEnd() )
108 ret += it->solvablesSize();
113 Pool::SolvableIterator Pool::solvablesBegin() const
114 { return SolvableIterator( myPool().getFirstId() ); }
116 Pool::SolvableIterator Pool::solvablesEnd() const
117 { return SolvableIterator(); }
119 Repository Pool::reposInsert( const std::string & alias_r )
121 Repository ret( reposFind( alias_r ) );
125 ret = Repository( myPool()._createRepo( alias_r ) );
126 if ( ret.isSystemRepo() )
128 // autoprovide (dummy) RepoInfo
130 info.setAlias( alias_r );
131 info.setName( alias_r );
132 info.setAutorefresh( true );
133 info.setEnabled( true );
139 Repository Pool::reposFind( const std::string & alias_r ) const
141 for_( it, reposBegin(), reposEnd() )
143 if ( alias_r == it->alias() )
149 Repository Pool::findSystemRepo() const
151 return Repository( myPool().systemRepo() );
154 Repository Pool::systemRepo()
156 if ( myPool().systemRepo() )
157 return Repository( myPool().systemRepo() );
158 return reposInsert( systemRepoAlias() );
161 Repository Pool::addRepoSolv( const Pathname & file_r, const std::string & alias_r )
163 // Using a temporay repo! (The additional parenthesis are required.)
164 AutoDispose<Repository> tmprepo( (Repository::EraseFromPool()) );
165 *tmprepo = reposInsert( alias_r );
166 tmprepo->addSolv( file_r );
168 // no exceptions so we keep it:
169 tmprepo.resetDispose();
173 Repository Pool::addRepoSolv( const Pathname & file_r )
174 { return addRepoSolv( file_r, file_r.basename() ); }
176 Repository Pool::addRepoSolv( const Pathname & file_r, const RepoInfo & info_r )
178 Repository ret( addRepoSolv( file_r, info_r.alias() ) );
179 ret.setInfo( info_r );
183 /////////////////////////////////////////////////////////////////
185 Repository Pool::addRepoHelix( 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->addHelix( file_r );
192 // no exceptions so we keep it:
193 tmprepo.resetDispose();
197 Repository Pool::addRepoHelix( const Pathname & file_r )
198 { return addRepoHelix( file_r, file_r.basename() ); }
200 Repository Pool::addRepoHelix( const Pathname & file_r, const RepoInfo & info_r )
202 Repository ret( addRepoHelix( file_r, info_r.alias() ) );
203 ret.setInfo( info_r );
207 /////////////////////////////////////////////////////////////////
209 void Pool::setTextLocale( const Locale & locale_r )
210 { myPool().setTextLocale( locale_r ); }
212 void Pool::setRequestedLocales( const LocaleSet & locales_r )
213 { myPool().setRequestedLocales( locales_r ); }
215 bool Pool::addRequestedLocale( const Locale & locale_r )
216 { return myPool().addRequestedLocale( locale_r ); }
218 bool Pool::eraseRequestedLocale( const Locale & locale_r )
219 { return myPool().eraseRequestedLocale( locale_r ); }
221 const LocaleSet & Pool::getRequestedLocales() const
222 { return myPool().getRequestedLocales(); }
224 bool Pool::isRequestedLocale( const Locale & locale_r ) const
225 { return myPool().isRequestedLocale( locale_r ); }
227 void Pool::initRequestedLocales( const LocaleSet & locales_r ) { myPool().initRequestedLocales( locales_r ); }
228 const LocaleSet & Pool::getAddedRequestedLocales() const { return myPool().getAddedRequestedLocales(); }
229 const LocaleSet & Pool::getRemovedRequestedLocales() const { return myPool().getRemovedRequestedLocales(); }
231 const LocaleSet & Pool::getAvailableLocales() const
232 { return myPool().getAvailableLocales(); }
234 bool Pool::isAvailableLocale( const Locale & locale_r ) const
235 { return myPool().isAvailableLocale( locale_r ); }
237 const Pool::MultiversionList & Pool::multiversion() const
238 { return myPool().multiversionList(); }
240 Queue Pool::autoInstalled() const { return myPool().autoInstalled(); }
241 void Pool::setAutoInstalled( const Queue & autoInstalled_r ){ myPool().setAutoInstalled( autoInstalled_r ); }
243 /******************************************************************
245 ** FUNCTION NAME : operator<<
246 ** FUNCTION TYPE : std::ostream &
248 std::ostream & operator<<( std::ostream & str, const Pool & obj )
250 return str << "sat::pool(" << obj.serial() << ")["
251 << obj.capacity() << "]{"
252 << obj.reposSize() << "repos|"
253 << obj.solvablesSize() << "slov}";
256 /////////////////////////////////////////////////////////////////
257 #undef ZYPP_BASE_LOGGER_LOGGROUP
258 #define ZYPP_BASE_LOGGER_LOGGROUP "solvidx"
260 void updateSolvFileIndex( const Pathname & solvfile_r )
262 AutoDispose<FILE*> solv( ::fopen( solvfile_r.c_str(), "re" ), ::fclose );
266 ERR << "Can't open solv-file: " << solv << endl;
270 std::string solvidxfile( solvfile_r.extend(".idx").asString() );
271 if ( ::unlink( solvidxfile.c_str() ) == -1 && errno != ENOENT )
273 ERR << "Can't unlink solv-idx: " << Errno() << endl;
277 int fd = ::open( solvidxfile.c_str(), O_CREAT|O_EXCL|O_WRONLY|O_TRUNC, 0644 );
280 ERR << "Can't create solv-idx: " << Errno() << endl;
285 std::ofstream idx( solvidxfile.c_str() );
288 detail::CPool * _pool = ::pool_create();
289 detail::CRepo * _repo = ::repo_create( _pool, "" );
290 if ( ::repo_add_solv( _repo, solv, 0 ) == 0 )
293 detail::CSolvable * _solv = nullptr;
294 FOR_REPO_SOLVABLES( _repo, _id, _solv )
299 #define idstr(V) pool_id2str( _pool, _solv->V )
300 if ( _solv->arch == ARCH_SRC || _solv->arch == ARCH_NOSRC )
301 idx << "srcpackage:" << idstr(name) << SEP << idstr(evr) << SEP << "noarch" << endl;
303 idx << idstr(name) << SEP << idstr(evr) << SEP << idstr(arch) << endl;
309 ERR << "Can't read solv-file: " << ::pool_errstr( _pool ) << endl;
311 ::repo_free( _repo, 0 );
312 ::pool_free( _pool );
315 /////////////////////////////////////////////////////////////////
317 ///////////////////////////////////////////////////////////////////
318 /////////////////////////////////////////////////////////////////
320 ///////////////////////////////////////////////////////////////////