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"
48 #include "zypp/sat/IdStrType.h"
50 #include <boost/mpl/int.hpp>
54 using namespace zypp::functor;
55 using namespace zypp::ui;
56 using zypp::parser::TagParser;
58 ///////////////////////////////////////////////////////////////////
60 static const Pathname sysRoot( "/Local/ROOT" );
62 ///////////////////////////////////////////////////////////////////
63 ///////////////////////////////////////////////////////////////////
65 { /////////////////////////////////////////////////////////////////
67 bool queryInstalledEditionHelper( const std::string & name_r,
71 if ( ed_r == Edition::noedition )
73 if ( name_r == "kernel-default" && ed_r == Edition("2.6.22.5-10") )
75 if ( name_r == "update-test-affects-package-manager" && ed_r == Edition("1.1-6") )
82 ManagedFile repoProvidePackage( const PoolItem & pi )
84 ResPool _pool( getZYpp()->pool() );
85 repo::RepoMediaAccess _access;
87 // Redirect PackageProvider queries for installed editions
88 // (in case of patch/delta rpm processing) to rpmDb.
89 repo::PackageProviderPolicy packageProviderPolicy;
90 packageProviderPolicy.queryInstalledCB( queryInstalledEditionHelper );
92 Package::constPtr p = asKind<Package>(pi.resolvable());
94 // Build a repository list for repos
95 // contributing to the pool
96 repo::DeltaCandidates deltas( repo::makeDeltaCandidates( _pool.knownRepositoriesBegin(),
97 _pool.knownRepositoriesEnd() ) );
98 repo::PackageProvider pkgProvider( _access, p, deltas, packageProviderPolicy );
99 return pkgProvider.providePackage();
102 /////////////////////////////////////////////////////////////////
104 ///////////////////////////////////////////////////////////////////
105 ///////////////////////////////////////////////////////////////////
109 template <class _LIterator, class _RIterator, class _Function>
110 inline int invokeOnEach( _LIterator lbegin_r, _LIterator lend_r,
111 _RIterator rbegin_r, _RIterator rend_r,
115 for ( _LIterator lit = lbegin_r; lit != lend_r; ++lit )
117 for ( _RIterator rit = rbegin_r; rit != rend_r; ++rit )
120 if ( ! fnc_r( *lit, *rit ) )
129 void dbgDu( Selectable::Ptr sel )
131 if ( sel->installedPoolItem() )
133 DBG << "i: " << sel->installedPoolItem() << endl
134 << sel->installedPoolItem()->diskusage() << endl;
136 if ( sel->candidatePoolItem() )
138 DBG << "c: " << sel->candidatePoolItem() << endl
139 << sel->candidatePoolItem()->diskusage() << endl;
142 << getZYpp()->diskUsage() << endl;
145 ///////////////////////////////////////////////////////////////////
149 bool operator()( const PoolItem & obj_r )
151 MIL << obj_r << endl;
152 DBG << " -> " << obj_r .satSolvable() << endl;
157 bool operator()( const sat::Solvable & obj_r )
159 dumpOn( MIL, obj_r ) << endl;
164 ///////////////////////////////////////////////////////////////////
165 struct SetTransactValue
167 SetTransactValue( ResStatus::TransactValue newVal_r, ResStatus::TransactByValue causer_r )
168 : _newVal( newVal_r )
169 , _causer( causer_r )
172 ResStatus::TransactValue _newVal;
173 ResStatus::TransactByValue _causer;
175 bool operator()( const PoolItem & pi ) const
177 bool ret = pi.status().setTransactValue( _newVal, _causer );
179 ERR << _newVal << _causer << " " << pi << endl;
184 struct StatusReset : public SetTransactValue
187 : SetTransactValue( ResStatus::KEEP_STATE, ResStatus::USER )
191 struct StatusInstall : public SetTransactValue
194 : SetTransactValue( ResStatus::TRANSACT, ResStatus::USER )
198 inline bool g( const NameKindProxy & nkp, Arch arch = Arch() )
200 if ( nkp.availableEmpty() )
202 ERR << "No Item to select: " << nkp << endl;
204 ZYPP_THROW( Exception("No Item to select") );
207 if ( arch != Arch() )
209 typeof( nkp.availableBegin() ) it = nkp.availableBegin();
210 for ( ; it != nkp.availableEnd(); ++it )
212 if ( (*it)->arch() == arch )
213 return (*it).status().setTransact( true, ResStatus::USER );
217 return nkp.availableBegin()->status().setTransact( true, ResStatus::USER );
220 ///////////////////////////////////////////////////////////////////
222 bool solve( bool establish = false )
228 zypp::base::LogControl::TmpLineWriter shutUp;
229 eres = getZYpp()->resolver()->establishPool();
233 ERR << "establish " << eres << endl;
236 MIL << "establish " << eres << endl;
241 zypp::base::LogControl::TmpLineWriter shutUp;
242 rres = getZYpp()->resolver()->resolvePool();
246 ERR << "resolve " << rres << endl;
249 MIL << "resolve " << rres << endl;
255 SEC << getZYpp()->commit( ZYppCommitPolicy() ) << endl;
259 ///////////////////////////////////////////////////////////////////
261 struct ConvertDbReceive : public callback::ReceiveReport<target::ScriptResolvableReport>
263 virtual void start( const Resolvable::constPtr & script_r,
264 const Pathname & path_r,
267 SEC << __FUNCTION__ << endl
268 << " " << script_r << endl
269 << " " << path_r << endl
270 << " " << task_r << endl;
273 virtual bool progress( Notify notify_r, const std::string & text_r )
275 SEC << __FUNCTION__ << endl
276 << " " << notify_r << endl
277 << " " << text_r << endl;
281 virtual void problem( const std::string & description_r )
283 SEC << __FUNCTION__ << endl
284 << " " << description_r << endl;
287 virtual void finish()
289 SEC << __FUNCTION__ << endl;
293 ///////////////////////////////////////////////////////////////////
295 struct DigestReceive : public callback::ReceiveReport<DigestReport>
302 virtual bool askUserToAcceptNoDigest( const zypp::Pathname &file )
307 virtual bool askUserToAccepUnknownDigest( const Pathname &file, const std::string &name )
312 virtual bool askUserToAcceptWrongDigest( const Pathname &file, const std::string &requested, const std::string &found )
314 USR << "fle " << PathInfo(file) << endl;
315 USR << "req " << requested << endl;
316 USR << "fnd " << found << endl;
321 struct KeyRingSignalsReceive : public callback::ReceiveReport<KeyRingSignals>
323 KeyRingSignalsReceive()
327 virtual void trustedKeyAdded( const PublicKey &/*key*/ )
331 virtual void trustedKeyRemoved( const PublicKey &/*key*/ )
337 ///////////////////////////////////////////////////////////////////
339 struct MediaChangeReceive : public callback::ReceiveReport<media::MediaChangeReport>
341 virtual Action requestMedia( Url & source
344 , const std::string & description )
346 SEC << __FUNCTION__ << endl
347 << " " << source << endl
348 << " " << mediumNr << endl
349 << " " << error << endl
350 << " " << description << endl;
355 ///////////////////////////////////////////////////////////////////
360 bool isIn( const std::set<_Tp> & cont, const typename std::set<_Tp>::value_type & val )
361 { return cont.find( val ) != cont.end(); }
363 ///////////////////////////////////////////////////////////////////
365 void itCmp( const sat::Pool::SolvableIterator & l, const sat::Pool::SolvableIterator & r )
367 SEC << *l << " - " << *r << endl;
368 INT << "== " << (l==r) << endl;
369 INT << "!= " << (l!=r) << endl;
372 bool isTrue() { return true; }
373 bool isFalse() { return false; }
377 for ( int i = -3; i < 30; ++i )
379 DBG << i << '\t' << sat::IdStr( i ) << endl;
383 void ttt( const char * lhs, const char * rhs )
385 DBG << lhs << " <=> " << rhs << " --> " << ::strcmp( lhs, rhs ) << endl;
390 template <class _MemFun, class _Value>
394 HasValue( _MemFun fun_r, _Value val_r )
395 : _fun( fun_r ), _val( val_r )
398 bool operator()( const _Tp & obj_r ) const
399 { return( _fun && (obj_r.*_fun)() == _val ); }
405 template <class _MemFun, class _Value>
406 HasValue<_MemFun, _Value> byValue( _MemFun fun_r, _Value val_r )
407 { return HasValue<_MemFun, _Value>( fun_r, val_r ); }
420 class Foo : public sat::IdStrType<Foo>
424 explicit Foo( sat::detail::IdType id_r ) : _str( str::toLower(sat::IdStr(id_r).c_str()) ) {}
425 explicit Foo( const sat::IdStr & idstr_r ) : _str( str::toLower(idstr_r.c_str()) ) {}
426 explicit Foo( const char * cstr_r ) : _str( str::toLower(cstr_r) ) {}
427 explicit Foo( const std::string & str_r ) : _str( str::toLower(str_r) ) {}
429 int _doDompareC( const char * rhs ) const
430 { return str::compareCI( _str.c_str(), rhs ); }
432 friend class sat::IdStrType<Foo>;
440 struct _TestO { _TestO( const L & lhs ) : _lhs( lhs ) {} const L & _lhs; };
443 std::ostream & operator<<( std::ostream & str, const _TestO<L> & obj )
444 { const L & lhs( obj._lhs); return str << (lhs?'_':'*') << (lhs.empty()?'e':'_') << "'" << lhs << "'"; }
447 _TestO<L> testO( const L & lhs )
448 { return _TestO<L>( lhs ); }
451 template <class L, class R>
452 void testCMP( const L & lhs, const R & rhs )
454 MIL << "LHS " << testO(lhs) << endl;
455 MIL << "RHS " << rhs << endl;
457 #define OUTS(S) DBG << #S << ": " << (S) << endl
458 OUTS( lhs.compare(rhs) );
468 /******************************************************************
470 ** FUNCTION NAME : main
471 ** FUNCTION TYPE : int
473 int main( int argc, char * argv[] )
475 //zypp::base::LogControl::instance().logfile( "log.restrict" );
476 INT << "===[START]==========================================" << endl;
478 sat::Pool satpool( sat::Pool::instance() );
481 sat::Repo s( satpool.addRepoSolv( "10.3.solv" ) );
482 //sat::Repo s( satpool.addRepoSolv( "target.solv" ) );
484 sat::Capabilities r( (*satpool.solvablesBegin())[Dep::PROVIDES] );
486 sat::Capabilities::const_iterator it = r.begin();
493 std::for_each( make_filter_iterator( filter::byValue( &sat::Solvable::name, "bash" ),
494 satpool.solvablesBegin(), satpool.solvablesEnd() ),
495 make_filter_iterator( filter::byValue( &sat::Solvable::name, "bash" ),
496 satpool.solvablesEnd(), satpool.solvablesEnd() ),
498 std::for_each( make_filter_iterator( filter::byValue( &sat::Solvable::name, "pattern:yast2_install_wf" ),
499 satpool.solvablesBegin(), satpool.solvablesEnd() ),
500 make_filter_iterator( filter::byValue( &sat::Solvable::name, "pattern:yast2_install_wf" ),
501 satpool.solvablesEnd(), satpool.solvablesEnd() ),
507 // make_filter_iterator(detail::ByRepo( *this ),
508 // Repo.cc- detail::SolvableIterator(_repo->end),
509 // Repo.cc- detail::SolvableIterator(_repo->end) );
512 // DBG << satpool.solvablesBegin()->name() << endl;
513 // DBG << (*satpool.solvablesBegin())[Dep::PROVIDES] << endl;
515 //std::for_each( satpool.solvablesBegin(), satpool.solvablesEnd(), Xprint() );
517 ///////////////////////////////////////////////////////////////////
518 INT << "===[END]============================================" << endl << endl;
519 zypp::base::LogControl::instance().logNothing();
523 setenv( "ZYPP_CONF", (sysRoot/"zypp.conf").c_str(), 1 );
525 ResPool pool( getZYpp()->pool() );
526 USR << "pool: " << pool << endl;
529 RepoManager repoManager( makeRepoManager( sysRoot ) );
530 RepoInfoList repos = repoManager.knownRepositories();
531 // SEC << "/Local/ROOT " << repos << endl;
534 for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
536 RepoInfo & nrepo( *it );
537 SEC << nrepo << endl;
539 if ( ! nrepo.enabled() )
542 if ( ! repoManager.isCached( nrepo ) || 0 )
544 if ( repoManager.isCached( nrepo ) )
546 SEC << "cleanCache" << endl;
547 repoManager.cleanCache( nrepo );
549 SEC << "refreshMetadata" << endl;
550 repoManager.refreshMetadata( nrepo, RepoManager::RefreshForced );
551 SEC << "buildCache" << endl;
552 repoManager.buildCache( nrepo );
556 // create from cache:
557 std::list<Repository> repositories;
560 Measure x( "CREATE FROM CACHE" );
561 for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
563 RepoInfo & nrepo( *it );
564 if ( ! nrepo.enabled() )
567 Measure x( "CREATE FROM CACHE "+nrepo.alias() );
568 Repository nrep( repoManager.createFromCache( nrepo ) );
569 const zypp::ResStore & store( nrep.resolvables() );
570 repositories.push_back( nrep );
576 Measure x( "LOAD POOL" );
577 for_( it, repositories.begin(), repositories.end() )
579 Measure x( "LOAD POOL "+(*it).info().alias() );
580 const zypp::ResStore & store( (*it).resolvables() );
581 getZYpp()->addResolvables( store );
588 Measure x( "INIT TARGET" );
590 zypp::base::LogControl::TmpLineWriter shutUp;
591 getZYpp()->initTarget( sysRoot );
592 //getZYpp()->initTarget( "/" );
594 dumpPoolStats( SEC << "TargetStore: " << endl,
595 getZYpp()->target()->resolvables().begin(),
596 getZYpp()->target()->resolvables().end() ) << endl;
599 USR << "pool: " << pool << endl;
603 //std::for_each( pool.begin(), pool.end(), Xprint() );
605 MIL << satpool << endl;
606 for_( it, satpool.solvablesBegin(), satpool.solvablesEnd() )
609 //MIL << dump(*it) << endl;
612 ///////////////////////////////////////////////////////////////////
613 INT << "===[END]============================================" << endl << endl;
614 zypp::base::LogControl::instance().logNothing();