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/ResPoolProxy.h"
12 #include "zypp/ZYppCallbacks.h"
13 #include "zypp/NVRAD.h"
14 #include "zypp/ResPool.h"
15 #include "zypp/ResFilters.h"
16 #include "zypp/CapFilters.h"
17 #include "zypp/Package.h"
18 #include "zypp/Pattern.h"
19 #include "zypp/Language.h"
20 #include "zypp/Digest.h"
21 #include "zypp/PackageKeyword.h"
22 #include "zypp/ManagedFile.h"
23 #include "zypp/NameKindProxy.h"
24 #include "zypp/pool/GetResolvablesToInsDel.h"
26 #include "zypp/RepoManager.h"
27 #include "zypp/RepoInfo.h"
29 #include "zypp/repo/PackageProvider.h"
31 #include "zypp/ui/PatchContents.h"
32 #include "zypp/ResPoolProxy.h"
34 #include "zypp/sat/Pool.h"
35 #include "zypp/sat/Repo.h"
36 #include "zypp/sat/Solvable.h"
37 #include "zypp/sat/detail/PoolImpl.h"
39 #include <boost/mpl/int.hpp>
43 using namespace zypp::functor;
44 using namespace zypp::ui;
46 ///////////////////////////////////////////////////////////////////
48 static const Pathname sysRoot( "/Local/ROOT" );
50 ///////////////////////////////////////////////////////////////////
51 ///////////////////////////////////////////////////////////////////
53 { /////////////////////////////////////////////////////////////////
55 bool queryInstalledEditionHelper( const std::string & name_r,
59 if ( ed_r == Edition::noedition )
61 if ( name_r == "kernel-default" && ed_r == Edition("2.6.22.5-10") )
63 if ( name_r == "update-test-affects-package-manager" && ed_r == Edition("1.1-6") )
70 ManagedFile repoProvidePackage( const PoolItem & pi )
72 ResPool _pool( getZYpp()->pool() );
73 repo::RepoMediaAccess _access;
75 // Redirect PackageProvider queries for installed editions
76 // (in case of patch/delta rpm processing) to rpmDb.
77 repo::PackageProviderPolicy packageProviderPolicy;
78 packageProviderPolicy.queryInstalledCB( queryInstalledEditionHelper );
80 Package::constPtr p = asKind<Package>(pi.resolvable());
82 // Build a repository list for repos
83 // contributing to the pool
84 repo::DeltaCandidates deltas( repo::makeDeltaCandidates( _pool.knownRepositoriesBegin(),
85 _pool.knownRepositoriesEnd() ) );
86 repo::PackageProvider pkgProvider( _access, p, deltas, packageProviderPolicy );
87 return pkgProvider.providePackage();
90 /////////////////////////////////////////////////////////////////
92 ///////////////////////////////////////////////////////////////////
93 ///////////////////////////////////////////////////////////////////
97 template <class _LIterator, class _RIterator, class _Function>
98 inline int invokeOnEach( _LIterator lbegin_r, _LIterator lend_r,
99 _RIterator rbegin_r, _RIterator rend_r,
103 for ( _LIterator lit = lbegin_r; lit != lend_r; ++lit )
105 for ( _RIterator rit = rbegin_r; rit != rend_r; ++rit )
108 if ( ! fnc_r( *lit, *rit ) )
117 void dbgDu( Selectable::Ptr sel )
119 if ( sel->installedPoolItem() )
121 DBG << "i: " << sel->installedPoolItem() << endl
122 << sel->installedPoolItem()->diskusage() << endl;
124 if ( sel->candidatePoolItem() )
126 DBG << "c: " << sel->candidatePoolItem() << endl
127 << sel->candidatePoolItem()->diskusage() << endl;
130 << getZYpp()->diskUsage() << endl;
133 ///////////////////////////////////////////////////////////////////
137 bool operator()( const PoolItem & obj_r )
139 MIL << obj_r << endl;
140 DBG << " -> " << obj_r->satSolvable() << endl;
145 bool operator()( const sat::Solvable & obj_r )
147 dumpOn( MIL, obj_r ) << endl;
152 ///////////////////////////////////////////////////////////////////
153 struct SetTransactValue
155 SetTransactValue( ResStatus::TransactValue newVal_r, ResStatus::TransactByValue causer_r )
156 : _newVal( newVal_r )
157 , _causer( causer_r )
160 ResStatus::TransactValue _newVal;
161 ResStatus::TransactByValue _causer;
163 bool operator()( const PoolItem & pi ) const
165 bool ret = pi.status().setTransactValue( _newVal, _causer );
167 ERR << _newVal << _causer << " " << pi << endl;
172 struct StatusReset : public SetTransactValue
175 : SetTransactValue( ResStatus::KEEP_STATE, ResStatus::USER )
179 struct StatusInstall : public SetTransactValue
182 : SetTransactValue( ResStatus::TRANSACT, ResStatus::USER )
186 inline bool g( const NameKindProxy & nkp, Arch arch = Arch() )
188 if ( nkp.availableEmpty() )
190 ERR << "No Item to select: " << nkp << endl;
192 ZYPP_THROW( Exception("No Item to select") );
195 if ( arch != Arch() )
197 typeof( nkp.availableBegin() ) it = nkp.availableBegin();
198 for ( ; it != nkp.availableEnd(); ++it )
200 if ( (*it)->arch() == arch )
201 return (*it).status().setTransact( true, ResStatus::USER );
205 return nkp.availableBegin()->status().setTransact( true, ResStatus::USER );
208 ///////////////////////////////////////////////////////////////////
214 zypp::base::LogControl::TmpLineWriter shutUp;
215 rres = getZYpp()->resolver()->resolvePool();
219 ERR << "resolve " << rres << endl;
222 MIL << "resolve " << rres << endl;
228 SEC << getZYpp()->commit( ZYppCommitPolicy() ) << endl;
232 ///////////////////////////////////////////////////////////////////
234 struct ConvertDbReceive : public callback::ReceiveReport<target::ScriptResolvableReport>
236 virtual void start( const Resolvable::constPtr & script_r,
237 const Pathname & path_r,
240 SEC << __FUNCTION__ << endl
241 << " " << script_r << endl
242 << " " << path_r << endl
243 << " " << task_r << endl;
246 virtual bool progress( Notify notify_r, const std::string & text_r )
248 SEC << __FUNCTION__ << endl
249 << " " << notify_r << endl
250 << " " << text_r << endl;
254 virtual void problem( const std::string & description_r )
256 SEC << __FUNCTION__ << endl
257 << " " << description_r << endl;
260 virtual void finish()
262 SEC << __FUNCTION__ << endl;
266 ///////////////////////////////////////////////////////////////////
268 struct DigestReceive : public callback::ReceiveReport<DigestReport>
275 virtual bool askUserToAcceptNoDigest( const zypp::Pathname &file )
280 virtual bool askUserToAccepUnknownDigest( const Pathname &file, const std::string &name )
285 virtual bool askUserToAcceptWrongDigest( const Pathname &file, const std::string &requested, const std::string &found )
287 USR << "fle " << PathInfo(file) << endl;
288 USR << "req " << requested << endl;
289 USR << "fnd " << found << endl;
294 struct KeyRingSignalsReceive : public callback::ReceiveReport<KeyRingSignals>
296 KeyRingSignalsReceive()
300 virtual void trustedKeyAdded( const PublicKey &/*key*/ )
304 virtual void trustedKeyRemoved( const PublicKey &/*key*/ )
310 ///////////////////////////////////////////////////////////////////
312 struct MediaChangeReceive : public callback::ReceiveReport<media::MediaChangeReport>
314 virtual Action requestMedia( Url & source
317 , const std::string & description )
319 SEC << __FUNCTION__ << endl
320 << " " << source << endl
321 << " " << mediumNr << endl
322 << " " << error << endl
323 << " " << description << endl;
328 ///////////////////////////////////////////////////////////////////
333 bool isIn( const std::set<_Tp> & cont, const typename std::set<_Tp>::value_type & val )
334 { return cont.find( val ) != cont.end(); }
336 ///////////////////////////////////////////////////////////////////
338 void itCmp( const sat::Pool::SolvableIterator & l, const sat::Pool::SolvableIterator & r )
340 SEC << *l << " - " << *r << endl;
341 INT << "== " << (l==r) << endl;
342 INT << "!= " << (l!=r) << endl;
345 bool isTrue() { return true; }
346 bool isFalse() { return false; }
350 for ( int i = -3; i < 30; ++i )
352 DBG << i << '\t' << IdString( i ) << endl;
356 void ttt( const char * lhs, const char * rhs )
358 DBG << lhs << " <=> " << rhs << " --> " << ::strcmp( lhs, rhs ) << endl;
363 template <class _MemFun, class _Value>
367 HasValue( _MemFun fun_r, _Value val_r )
368 : _fun( fun_r ), _val( val_r )
371 bool operator()( const _Tp & obj_r ) const
372 { return( _fun && (obj_r.*_fun)() == _val ); }
378 template <class _MemFun, class _Value>
379 HasValue<_MemFun, _Value> byValue( _MemFun fun_r, _Value val_r )
380 { return HasValue<_MemFun, _Value>( fun_r, val_r ); }
388 struct _TestO { _TestO( const L & lhs ) : _lhs( lhs ) {} const L & _lhs; };
391 std::ostream & operator<<( std::ostream & str, const _TestO<L> & obj )
392 { const L & lhs( obj._lhs); return str << (lhs?'_':'*') << (lhs.empty()?'e':'_') << "'" << lhs << "'"; }
395 _TestO<L> testO( const L & lhs )
396 { return _TestO<L>( lhs ); }
398 template <class L, class R>
399 void testCMP( const L & lhs, const R & rhs )
401 MIL << "LHS " << testO(lhs) << endl;
402 MIL << "RHS " << rhs << endl;
404 #define OUTS(S) DBG << #S << ": " << (S) << endl
405 OUTS( lhs.compare(rhs) );
415 /******************************************************************
417 ** FUNCTION NAME : main
418 ** FUNCTION TYPE : int
420 int main( int argc, char * argv[] )
422 //zypp::base::LogControl::instance().logfile( "log.restrict" );
423 INT << "===[START]==========================================" << endl;
425 sat::Pool satpool( sat::Pool::instance() );
428 sat::Repo s( satpool.addRepoSolv( "10.3.solv" ) );
429 //sat::Repo s( satpool.addRepoSolv( "target.solv" ) );
431 Capability lc( "foo <= 13" );
432 Capability rc( "Baa > 5" );
433 int nid = ::rel2id( satpool.get(), lc.id(), rc.id(), 16, /*create*/true );
438 INT << dump(t) << endl;
442 Capabilities r( (*satpool.solvablesBegin())[Dep::PROVIDES] );
444 Capabilities::const_iterator it = r.begin();
451 r = (*satpool.solvablesBegin())[Dep::REQUIRES];
452 for_( it, r.begin(), r.end() )
455 WAR << *it << " (is prereq)" << endl;
457 MIL << dump(*it) << endl;
462 std::for_each( make_filter_iterator( filter::byValue( &sat::Solvable::name, "bash" ),
463 satpool.solvablesBegin(), satpool.solvablesEnd() ),
464 make_filter_iterator( filter::byValue( &sat::Solvable::name, "bash" ),
465 satpool.solvablesEnd(), satpool.solvablesEnd() ),
467 std::for_each( make_filter_iterator( filter::byValue( &sat::Solvable::name, "pattern:yast2_install_wf" ),
468 satpool.solvablesBegin(), satpool.solvablesEnd() ),
469 make_filter_iterator( filter::byValue( &sat::Solvable::name, "pattern:yast2_install_wf" ),
470 satpool.solvablesEnd(), satpool.solvablesEnd() ),
476 // make_filter_iterator(detail::ByRepo( *this ),
477 // Repo.cc- detail::SolvableIterator(_repo->end),
478 // Repo.cc- detail::SolvableIterator(_repo->end) );
481 // DBG << satpool.solvablesBegin()->name() << endl;
482 // DBG << (*satpool.solvablesBegin())[Dep::PROVIDES] << endl;
484 //std::for_each( satpool.solvablesBegin(), satpool.solvablesEnd(), Xprint() );
486 ///////////////////////////////////////////////////////////////////
487 INT << "===[END]============================================" << endl << endl;
488 zypp::base::LogControl::instance().logNothing();
492 setenv( "ZYPP_CONF", (sysRoot/"zypp.conf").c_str(), 1 );
494 ResPool pool( getZYpp()->pool() );
495 USR << "pool: " << pool << endl;
497 RepoManager repoManager( makeRepoManager( sysRoot ) );
498 RepoInfoList repos = repoManager.knownRepositories();
499 // SEC << "/Local/ROOT " << repos << endl;
502 for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
504 RepoInfo & nrepo( *it );
505 SEC << nrepo << endl;
507 if ( ! nrepo.enabled() )
510 if ( ! repoManager.isCached( nrepo ) || 0 )
512 if ( repoManager.isCached( nrepo ) )
514 SEC << "cleanCache" << endl;
515 repoManager.cleanCache( nrepo );
517 SEC << "refreshMetadata" << endl;
518 repoManager.refreshMetadata( nrepo, RepoManager::RefreshForced );
519 SEC << "buildCache" << endl;
520 repoManager.buildCache( nrepo );
524 // create from cache:
525 std::list<Repository> repositories;
528 Measure x( "CREATE FROM CACHE" );
529 for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
531 RepoInfo & nrepo( *it );
532 if ( ! nrepo.enabled() )
535 Measure x( "CREATE FROM CACHE "+nrepo.alias() );
536 Repository nrep( repoManager.createFromCache( nrepo ) );
537 const zypp::ResStore & store( nrep.resolvables() );
538 repositories.push_back( nrep );
544 Measure x( "LOAD POOL" );
545 for_( it, repositories.begin(), repositories.end() )
547 Measure x( "LOAD POOL "+(*it).info().alias() );
548 const zypp::ResStore & store( (*it).resolvables() );
549 getZYpp()->addResolvables( store );
556 Measure x( "INIT TARGET" );
558 zypp::base::LogControl::TmpLineWriter shutUp;
559 getZYpp()->initTarget( sysRoot );
560 //getZYpp()->initTarget( "/" );
562 dumpPoolStats( SEC << "TargetStore: " << endl,
563 getZYpp()->target()->resolvables().begin(),
564 getZYpp()->target()->resolvables().end() ) << endl;
567 USR << "pool: " << pool << endl;
570 //std::for_each( pool.begin(), pool.end(), Xprint() );
572 MIL << satpool << endl;
573 for_( it, satpool.solvablesBegin(), satpool.solvablesEnd() )
576 //MIL << dump(*it) << endl;
579 ///////////////////////////////////////////////////////////////////
580 INT << "===[END]============================================" << endl << endl;
581 zypp::base::LogControl::instance().logNothing();