3 #include <zypp/base/PtrTypes.h>
4 #include <zypp/base/Exception.h>
5 #include <zypp/base/Gettext.h>
6 #include <zypp/base/LogTools.h>
7 #include <zypp/base/ProvideNumericId.h>
8 #include <zypp/AutoDispose.h>
10 #include "zypp/ZYppFactory.h"
11 #include "zypp/ResPoolProxy.h"
12 #include <zypp/CapMatchHelper.h>
14 #include "zypp/ZYppCallbacks.h"
15 #include "zypp/NVRAD.h"
16 #include "zypp/ResPool.h"
17 #include "zypp/ResFilters.h"
18 #include "zypp/CapFilters.h"
19 #include "zypp/Package.h"
20 #include "zypp/Pattern.h"
21 #include "zypp/Language.h"
22 #include "zypp/Digest.h"
23 #include "zypp/PackageKeyword.h"
24 #include "zypp/ManagedFile.h"
25 #include "zypp/NameKindProxy.h"
26 #include "zypp/pool/GetResolvablesToInsDel.h"
28 #include "zypp/parser/TagParser.h"
29 #include "zypp/parser/susetags/PackagesFileReader.h"
30 #include "zypp/parser/susetags/PackagesLangFileReader.h"
31 #include "zypp/parser/susetags/PatternFileReader.h"
32 #include "zypp/parser/susetags/ContentFileReader.h"
33 #include "zypp/parser/susetags/RepoIndex.h"
34 #include "zypp/parser/susetags/RepoParser.h"
35 #include "zypp/cache/CacheStore.h"
36 #include "zypp/RepoManager.h"
37 #include "zypp/RepoInfo.h"
39 #include "zypp/repo/PackageProvider.h"
41 #include "zypp/ui/PatchContents.h"
42 #include "zypp/ResPoolProxy.h"
44 #include "zypp/sat/Pool.h"
45 #include "zypp/sat/Repo.h"
46 #include "zypp/sat/Solvable.h"
47 #include "zypp/sat/detail/PoolImpl.h"
49 #include <boost/mpl/int.hpp>
53 using namespace zypp::functor;
54 using namespace zypp::ui;
55 using zypp::parser::TagParser;
57 ///////////////////////////////////////////////////////////////////
59 static const Pathname sysRoot( "/Local/ROOT" );
61 ///////////////////////////////////////////////////////////////////
62 ///////////////////////////////////////////////////////////////////
64 { /////////////////////////////////////////////////////////////////
66 bool queryInstalledEditionHelper( const std::string & name_r,
70 if ( ed_r == Edition::noedition )
72 if ( name_r == "kernel-default" && ed_r == Edition("2.6.22.5-10") )
74 if ( name_r == "update-test-affects-package-manager" && ed_r == Edition("1.1-6") )
81 ManagedFile repoProvidePackage( const PoolItem & pi )
83 ResPool _pool( getZYpp()->pool() );
84 repo::RepoMediaAccess _access;
86 // Redirect PackageProvider queries for installed editions
87 // (in case of patch/delta rpm processing) to rpmDb.
88 repo::PackageProviderPolicy packageProviderPolicy;
89 packageProviderPolicy.queryInstalledCB( queryInstalledEditionHelper );
91 Package::constPtr p = asKind<Package>(pi.resolvable());
93 // Build a repository list for repos
94 // contributing to the pool
95 repo::DeltaCandidates deltas( repo::makeDeltaCandidates( _pool.knownRepositoriesBegin(),
96 _pool.knownRepositoriesEnd() ) );
97 repo::PackageProvider pkgProvider( _access, p, deltas, packageProviderPolicy );
98 return pkgProvider.providePackage();
101 /////////////////////////////////////////////////////////////////
103 ///////////////////////////////////////////////////////////////////
104 ///////////////////////////////////////////////////////////////////
108 template <class _LIterator, class _RIterator, class _Function>
109 inline int invokeOnEach( _LIterator lbegin_r, _LIterator lend_r,
110 _RIterator rbegin_r, _RIterator rend_r,
114 for ( _LIterator lit = lbegin_r; lit != lend_r; ++lit )
116 for ( _RIterator rit = rbegin_r; rit != rend_r; ++rit )
119 if ( ! fnc_r( *lit, *rit ) )
128 void dbgDu( Selectable::Ptr sel )
130 if ( sel->installedPoolItem() )
132 DBG << "i: " << sel->installedPoolItem() << endl
133 << sel->installedPoolItem()->diskusage() << endl;
135 if ( sel->candidatePoolItem() )
137 DBG << "c: " << sel->candidatePoolItem() << endl
138 << sel->candidatePoolItem()->diskusage() << endl;
141 << getZYpp()->diskUsage() << endl;
144 ///////////////////////////////////////////////////////////////////
148 bool operator()( const PoolItem & obj_r )
150 MIL << obj_r << endl;
151 DBG << " -> " << obj_r .satSolvable() << endl;
156 bool operator()( const sat::Solvable & obj_r )
158 dumpOn( MIL, obj_r ) << endl;
163 ///////////////////////////////////////////////////////////////////
164 struct SetTransactValue
166 SetTransactValue( ResStatus::TransactValue newVal_r, ResStatus::TransactByValue causer_r )
167 : _newVal( newVal_r )
168 , _causer( causer_r )
171 ResStatus::TransactValue _newVal;
172 ResStatus::TransactByValue _causer;
174 bool operator()( const PoolItem & pi ) const
176 bool ret = pi.status().setTransactValue( _newVal, _causer );
178 ERR << _newVal << _causer << " " << pi << endl;
183 struct StatusReset : public SetTransactValue
186 : SetTransactValue( ResStatus::KEEP_STATE, ResStatus::USER )
190 struct StatusInstall : public SetTransactValue
193 : SetTransactValue( ResStatus::TRANSACT, ResStatus::USER )
197 inline bool g( const NameKindProxy & nkp, Arch arch = Arch() )
199 if ( nkp.availableEmpty() )
201 ERR << "No Item to select: " << nkp << endl;
203 ZYPP_THROW( Exception("No Item to select") );
206 if ( arch != Arch() )
208 typeof( nkp.availableBegin() ) it = nkp.availableBegin();
209 for ( ; it != nkp.availableEnd(); ++it )
211 if ( (*it)->arch() == arch )
212 return (*it).status().setTransact( true, ResStatus::USER );
216 return nkp.availableBegin()->status().setTransact( true, ResStatus::USER );
219 ///////////////////////////////////////////////////////////////////
221 bool solve( bool establish = false )
227 zypp::base::LogControl::TmpLineWriter shutUp;
228 eres = getZYpp()->resolver()->establishPool();
232 ERR << "establish " << eres << endl;
235 MIL << "establish " << eres << endl;
240 zypp::base::LogControl::TmpLineWriter shutUp;
241 rres = getZYpp()->resolver()->resolvePool();
245 ERR << "resolve " << rres << endl;
248 MIL << "resolve " << rres << endl;
254 SEC << getZYpp()->commit( ZYppCommitPolicy() ) << endl;
258 ///////////////////////////////////////////////////////////////////
260 struct ConvertDbReceive : public callback::ReceiveReport<target::ScriptResolvableReport>
262 virtual void start( const Resolvable::constPtr & script_r,
263 const Pathname & path_r,
266 SEC << __FUNCTION__ << endl
267 << " " << script_r << endl
268 << " " << path_r << endl
269 << " " << task_r << endl;
272 virtual bool progress( Notify notify_r, const std::string & text_r )
274 SEC << __FUNCTION__ << endl
275 << " " << notify_r << endl
276 << " " << text_r << endl;
280 virtual void problem( const std::string & description_r )
282 SEC << __FUNCTION__ << endl
283 << " " << description_r << endl;
286 virtual void finish()
288 SEC << __FUNCTION__ << endl;
292 ///////////////////////////////////////////////////////////////////
294 struct DigestReceive : public callback::ReceiveReport<DigestReport>
301 virtual bool askUserToAcceptNoDigest( const zypp::Pathname &file )
306 virtual bool askUserToAccepUnknownDigest( const Pathname &file, const std::string &name )
311 virtual bool askUserToAcceptWrongDigest( const Pathname &file, const std::string &requested, const std::string &found )
313 USR << "fle " << PathInfo(file) << endl;
314 USR << "req " << requested << endl;
315 USR << "fnd " << found << endl;
320 struct KeyRingSignalsReceive : public callback::ReceiveReport<KeyRingSignals>
322 KeyRingSignalsReceive()
326 virtual void trustedKeyAdded( const PublicKey &/*key*/ )
330 virtual void trustedKeyRemoved( const PublicKey &/*key*/ )
336 ///////////////////////////////////////////////////////////////////
338 struct MediaChangeReceive : public callback::ReceiveReport<media::MediaChangeReport>
340 virtual Action requestMedia( Url & source
343 , const std::string & description )
345 SEC << __FUNCTION__ << endl
346 << " " << source << endl
347 << " " << mediumNr << endl
348 << " " << error << endl
349 << " " << description << endl;
354 ///////////////////////////////////////////////////////////////////
359 bool isIn( const std::set<_Tp> & cont, const typename std::set<_Tp>::value_type & val )
360 { return cont.find( val ) != cont.end(); }
362 ///////////////////////////////////////////////////////////////////
364 void itCmp( const sat::Pool::SolvableIterator & l, const sat::Pool::SolvableIterator & r )
366 SEC << *l << " - " << *r << endl;
367 INT << "== " << (l==r) << endl;
368 INT << "!= " << (l!=r) << endl;
371 bool isTrue() { return true; }
372 bool isFalse() { return false; }
376 for ( int i = -3; i < 30; ++i )
378 DBG << i << '\t' << sat::IdStr( i ) << endl;
382 void ttt( const char * lhs, const char * rhs )
384 DBG << lhs << " <=> " << rhs << " --> " << ::strcmp( lhs, rhs ) << endl;
389 template <class _MemFun, class _Value>
393 HasValue( _MemFun fun_r, _Value val_r )
394 : _fun( fun_r ), _val( val_r )
397 bool operator()( const _Tp & obj_r ) const
398 { return( _fun && (obj_r.*_fun)() == _val ); }
404 template <class _MemFun, class _Value>
405 HasValue<_MemFun, _Value> byValue( _MemFun fun_r, _Value val_r )
406 { return HasValue<_MemFun, _Value>( fun_r, val_r ); }
412 /******************************************************************
414 ** FUNCTION NAME : main
415 ** FUNCTION TYPE : int
417 int main( int argc, char * argv[] )
419 //zypp::base::LogControl::instance().logfile( "log.restrict" );
420 INT << "===[START]==========================================" << endl;
422 sat::Pool satpool( sat::Pool::instance() );
425 //sat::Repo r( satpool.addRepoSolv( "sl10.1-beta7-packages.solv" ) );
426 //sat::Repo s( satpool.addRepoSolv( "sl10.1-beta7-selections.solv" ) );
427 sat::Repo s( satpool.addRepoSolv( "target.solv" ) );
429 sat::Capabilities r( (*satpool.solvablesBegin())[Dep::PROVIDES] );
431 sat::Capabilities::const_iterator it = r.begin();
437 std::for_each( make_filter_iterator( filter::byValue( &sat::Solvable::name, "bash" ),
438 satpool.solvablesBegin(), satpool.solvablesEnd() ),
439 make_filter_iterator( filter::byValue( &sat::Solvable::name, "bash" ),
440 satpool.solvablesEnd(), satpool.solvablesEnd() ),
443 // make_filter_iterator(detail::ByRepo( *this ),
444 // Repo.cc- detail::SolvableIterator(_repo->end),
445 // Repo.cc- detail::SolvableIterator(_repo->end) );
448 // DBG << satpool.solvablesBegin()->name() << endl;
449 // DBG << (*satpool.solvablesBegin())[Dep::PROVIDES] << endl;
451 //std::for_each( satpool.solvablesBegin(), satpool.solvablesEnd(), Xprint() );
453 ///////////////////////////////////////////////////////////////////
454 INT << "===[END]============================================" << endl << endl;
455 zypp::base::LogControl::instance().logNothing();
459 setenv( "ZYPP_CONF", (sysRoot/"zypp.conf").c_str(), 1 );
461 ResPool pool( getZYpp()->pool() );
462 USR << "pool: " << pool << endl;
465 RepoManager repoManager( makeRepoManager( sysRoot ) );
466 RepoInfoList repos = repoManager.knownRepositories();
467 // SEC << "/Local/ROOT " << repos << endl;
470 for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
472 RepoInfo & nrepo( *it );
473 SEC << nrepo << endl;
475 if ( ! nrepo.enabled() )
478 if ( ! repoManager.isCached( nrepo ) || 0 )
480 if ( repoManager.isCached( nrepo ) )
482 SEC << "cleanCache" << endl;
483 repoManager.cleanCache( nrepo );
485 SEC << "refreshMetadata" << endl;
486 repoManager.refreshMetadata( nrepo, RepoManager::RefreshForced );
487 SEC << "buildCache" << endl;
488 repoManager.buildCache( nrepo );
492 // create from cache:
493 std::list<Repository> repositories;
496 Measure x( "CREATE FROM CACHE" );
497 for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
499 RepoInfo & nrepo( *it );
500 if ( ! nrepo.enabled() )
503 Measure x( "CREATE FROM CACHE "+nrepo.alias() );
504 Repository nrep( repoManager.createFromCache( nrepo ) );
505 const zypp::ResStore & store( nrep.resolvables() );
506 repositories.push_back( nrep );
512 Measure x( "LOAD POOL" );
513 for_( it, repositories.begin(), repositories.end() )
515 Measure x( "LOAD POOL "+(*it).info().alias() );
516 const zypp::ResStore & store( (*it).resolvables() );
517 getZYpp()->addResolvables( store );
524 Measure x( "INIT TARGET" );
526 zypp::base::LogControl::TmpLineWriter shutUp;
527 getZYpp()->initTarget( sysRoot );
528 //getZYpp()->initTarget( "/" );
530 dumpPoolStats( SEC << "TargetStore: " << endl,
531 getZYpp()->target()->resolvables().begin(),
532 getZYpp()->target()->resolvables().end() ) << endl;
535 USR << "pool: " << pool << endl;
540 //std::for_each( pool.begin(), pool.end(), Xprint() );
542 //sat::detail::PoolImpl satpool;
544 //MIL << satpool << endl;
546 ///////////////////////////////////////////////////////////////////
547 INT << "===[END]============================================" << endl << endl;
548 zypp::base::LogControl::instance().logNothing();