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"
38 #include <boost/mpl/int.hpp>
42 using namespace zypp::functor;
43 using namespace zypp::ui;
45 ///////////////////////////////////////////////////////////////////
47 static const Pathname sysRoot( "/Local/ROOT" );
49 ///////////////////////////////////////////////////////////////////
50 ///////////////////////////////////////////////////////////////////
52 { /////////////////////////////////////////////////////////////////
54 bool queryInstalledEditionHelper( const std::string & name_r,
58 if ( ed_r == Edition::noedition )
60 if ( name_r == "kernel-default" && ed_r == Edition("2.6.22.5-10") )
62 if ( name_r == "update-test-affects-package-manager" && ed_r == Edition("1.1-6") )
69 ManagedFile repoProvidePackage( const PoolItem & pi )
71 ResPool _pool( getZYpp()->pool() );
72 repo::RepoMediaAccess _access;
74 // Redirect PackageProvider queries for installed editions
75 // (in case of patch/delta rpm processing) to rpmDb.
76 repo::PackageProviderPolicy packageProviderPolicy;
77 packageProviderPolicy.queryInstalledCB( queryInstalledEditionHelper );
79 Package::constPtr p = asKind<Package>(pi.resolvable());
81 // Build a repository list for repos
82 // contributing to the pool
83 repo::DeltaCandidates deltas( repo::makeDeltaCandidates( _pool.knownRepositoriesBegin(),
84 _pool.knownRepositoriesEnd() ) );
85 repo::PackageProvider pkgProvider( _access, p, deltas, packageProviderPolicy );
86 return pkgProvider.providePackage();
89 /////////////////////////////////////////////////////////////////
91 ///////////////////////////////////////////////////////////////////
92 ///////////////////////////////////////////////////////////////////
96 template <class _LIterator, class _RIterator, class _Function>
97 inline int invokeOnEach( _LIterator lbegin_r, _LIterator lend_r,
98 _RIterator rbegin_r, _RIterator rend_r,
102 for ( _LIterator lit = lbegin_r; lit != lend_r; ++lit )
104 for ( _RIterator rit = rbegin_r; rit != rend_r; ++rit )
107 if ( ! fnc_r( *lit, *rit ) )
116 void dbgDu( Selectable::Ptr sel )
118 if ( sel->installedPoolItem() )
120 DBG << "i: " << sel->installedPoolItem() << endl
121 << sel->installedPoolItem()->diskusage() << endl;
123 if ( sel->candidatePoolItem() )
125 DBG << "c: " << sel->candidatePoolItem() << endl
126 << sel->candidatePoolItem()->diskusage() << endl;
129 << getZYpp()->diskUsage() << endl;
132 ///////////////////////////////////////////////////////////////////
136 bool operator()( const PoolItem & obj_r )
138 MIL << obj_r << endl;
139 DBG << " -> " << obj_r->satSolvable() << endl;
144 bool operator()( const sat::Solvable & obj_r )
146 dumpOn( MIL, obj_r ) << endl;
151 ///////////////////////////////////////////////////////////////////
152 struct SetTransactValue
154 SetTransactValue( ResStatus::TransactValue newVal_r, ResStatus::TransactByValue causer_r )
155 : _newVal( newVal_r )
156 , _causer( causer_r )
159 ResStatus::TransactValue _newVal;
160 ResStatus::TransactByValue _causer;
162 bool operator()( const PoolItem & pi ) const
164 bool ret = pi.status().setTransactValue( _newVal, _causer );
166 ERR << _newVal << _causer << " " << pi << endl;
171 struct StatusReset : public SetTransactValue
174 : SetTransactValue( ResStatus::KEEP_STATE, ResStatus::USER )
178 struct StatusInstall : public SetTransactValue
181 : SetTransactValue( ResStatus::TRANSACT, ResStatus::USER )
185 inline bool g( const NameKindProxy & nkp, Arch arch = Arch() )
187 if ( nkp.availableEmpty() )
189 ERR << "No Item to select: " << nkp << endl;
191 ZYPP_THROW( Exception("No Item to select") );
194 if ( arch != Arch() )
196 typeof( nkp.availableBegin() ) it = nkp.availableBegin();
197 for ( ; it != nkp.availableEnd(); ++it )
199 if ( (*it)->arch() == arch )
200 return (*it).status().setTransact( true, ResStatus::USER );
204 return nkp.availableBegin()->status().setTransact( true, ResStatus::USER );
207 ///////////////////////////////////////////////////////////////////
213 zypp::base::LogControl::TmpLineWriter shutUp;
214 rres = getZYpp()->resolver()->resolvePool();
218 ERR << "resolve " << rres << endl;
221 MIL << "resolve " << rres << endl;
227 SEC << getZYpp()->commit( ZYppCommitPolicy() ) << endl;
231 ///////////////////////////////////////////////////////////////////
233 struct ConvertDbReceive : public callback::ReceiveReport<target::ScriptResolvableReport>
235 virtual void start( const Resolvable::constPtr & script_r,
236 const Pathname & path_r,
239 SEC << __FUNCTION__ << endl
240 << " " << script_r << endl
241 << " " << path_r << endl
242 << " " << task_r << endl;
245 virtual bool progress( Notify notify_r, const std::string & text_r )
247 SEC << __FUNCTION__ << endl
248 << " " << notify_r << endl
249 << " " << text_r << endl;
253 virtual void problem( const std::string & description_r )
255 SEC << __FUNCTION__ << endl
256 << " " << description_r << endl;
259 virtual void finish()
261 SEC << __FUNCTION__ << endl;
265 ///////////////////////////////////////////////////////////////////
267 struct DigestReceive : public callback::ReceiveReport<DigestReport>
274 virtual bool askUserToAcceptNoDigest( const zypp::Pathname &file )
279 virtual bool askUserToAccepUnknownDigest( const Pathname &file, const std::string &name )
284 virtual bool askUserToAcceptWrongDigest( const Pathname &file, const std::string &requested, const std::string &found )
286 USR << "fle " << PathInfo(file) << endl;
287 USR << "req " << requested << endl;
288 USR << "fnd " << found << endl;
293 struct KeyRingSignalsReceive : public callback::ReceiveReport<KeyRingSignals>
295 KeyRingSignalsReceive()
299 virtual void trustedKeyAdded( const PublicKey &/*key*/ )
303 virtual void trustedKeyRemoved( const PublicKey &/*key*/ )
309 ///////////////////////////////////////////////////////////////////
311 struct MediaChangeReceive : public callback::ReceiveReport<media::MediaChangeReport>
313 virtual Action requestMedia( Url & source
316 , const std::string & description )
318 SEC << __FUNCTION__ << endl
319 << " " << source << endl
320 << " " << mediumNr << endl
321 << " " << error << endl
322 << " " << description << endl;
327 ///////////////////////////////////////////////////////////////////
332 bool isIn( const std::set<_Tp> & cont, const typename std::set<_Tp>::value_type & val )
333 { return cont.find( val ) != cont.end(); }
335 ///////////////////////////////////////////////////////////////////
337 void itCmp( const sat::Pool::SolvableIterator & l, const sat::Pool::SolvableIterator & r )
339 SEC << *l << " - " << *r << endl;
340 INT << "== " << (l==r) << endl;
341 INT << "!= " << (l!=r) << endl;
344 bool isTrue() { return true; }
345 bool isFalse() { return false; }
349 for ( int i = -3; i < 30; ++i )
351 DBG << i << '\t' << IdString( i ) << endl;
355 void ttt( const char * lhs, const char * rhs )
357 DBG << lhs << " <=> " << rhs << " --> " << ::strcmp( lhs, rhs ) << endl;
362 template <class _MemFun, class _Value>
366 HasValue( _MemFun fun_r, _Value val_r )
367 : _fun( fun_r ), _val( val_r )
370 bool operator()( const _Tp & obj_r ) const
371 { return( _fun && (obj_r.*_fun)() == _val ); }
377 template <class _MemFun, class _Value>
378 HasValue<_MemFun, _Value> byValue( _MemFun fun_r, _Value val_r )
379 { return HasValue<_MemFun, _Value>( fun_r, val_r ); }
387 struct _TestO { _TestO( const L & lhs ) : _lhs( lhs ) {} const L & _lhs; };
390 std::ostream & operator<<( std::ostream & str, const _TestO<L> & obj )
391 { const L & lhs( obj._lhs); return str << (lhs?'_':'*') << (lhs.empty()?'e':'_') << "'" << lhs << "'"; }
394 _TestO<L> testO( const L & lhs )
395 { return _TestO<L>( lhs ); }
397 template <class L, class R>
398 void testCMP( const L & lhs, const R & rhs )
400 MIL << "LHS " << testO(lhs) << endl;
401 MIL << "RHS " << rhs << endl;
403 #define OUTS(S) DBG << #S << ": " << (S) << endl
404 OUTS( lhs.compare(rhs) );
414 /******************************************************************
416 ** FUNCTION NAME : main
417 ** FUNCTION TYPE : int
419 int main( int argc, char * argv[] )
421 //zypp::base::LogControl::instance().logfile( "log.restrict" );
422 INT << "===[START]==========================================" << endl;
424 sat::Pool satpool( sat::Pool::instance() );
426 Patch::Ptr p = make<Patch>( sat::Solvable(23) );
430 sat::Repo s( satpool.addRepoSolv( "10.3.solv" ) );
431 //sat::Repo s( satpool.addRepoSolv( "target.solv" ) );
433 Capabilities r( (*satpool.solvablesBegin())[Dep::PROVIDES] );
435 Capabilities::const_iterator it = r.begin();
442 std::for_each( make_filter_iterator( filter::byValue( &sat::Solvable::name, "bash" ),
443 satpool.solvablesBegin(), satpool.solvablesEnd() ),
444 make_filter_iterator( filter::byValue( &sat::Solvable::name, "bash" ),
445 satpool.solvablesEnd(), satpool.solvablesEnd() ),
447 std::for_each( make_filter_iterator( filter::byValue( &sat::Solvable::name, "pattern:yast2_install_wf" ),
448 satpool.solvablesBegin(), satpool.solvablesEnd() ),
449 make_filter_iterator( filter::byValue( &sat::Solvable::name, "pattern:yast2_install_wf" ),
450 satpool.solvablesEnd(), satpool.solvablesEnd() ),
456 // make_filter_iterator(detail::ByRepo( *this ),
457 // Repo.cc- detail::SolvableIterator(_repo->end),
458 // Repo.cc- detail::SolvableIterator(_repo->end) );
461 // DBG << satpool.solvablesBegin()->name() << endl;
462 // DBG << (*satpool.solvablesBegin())[Dep::PROVIDES] << endl;
464 //std::for_each( satpool.solvablesBegin(), satpool.solvablesEnd(), Xprint() );
466 ///////////////////////////////////////////////////////////////////
467 INT << "===[END]============================================" << endl << endl;
468 zypp::base::LogControl::instance().logNothing();
472 setenv( "ZYPP_CONF", (sysRoot/"zypp.conf").c_str(), 1 );
474 ResPool pool( getZYpp()->pool() );
475 USR << "pool: " << pool << endl;
477 RepoManager repoManager( makeRepoManager( sysRoot ) );
478 RepoInfoList repos = repoManager.knownRepositories();
479 // SEC << "/Local/ROOT " << repos << endl;
482 for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
484 RepoInfo & nrepo( *it );
485 SEC << nrepo << endl;
487 if ( ! nrepo.enabled() )
490 if ( ! repoManager.isCached( nrepo ) || 0 )
492 if ( repoManager.isCached( nrepo ) )
494 SEC << "cleanCache" << endl;
495 repoManager.cleanCache( nrepo );
497 SEC << "refreshMetadata" << endl;
498 repoManager.refreshMetadata( nrepo, RepoManager::RefreshForced );
499 SEC << "buildCache" << endl;
500 repoManager.buildCache( nrepo );
504 // create from cache:
505 std::list<Repository> repositories;
508 Measure x( "CREATE FROM CACHE" );
509 for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
511 RepoInfo & nrepo( *it );
512 if ( ! nrepo.enabled() )
515 Measure x( "CREATE FROM CACHE "+nrepo.alias() );
516 Repository nrep( repoManager.createFromCache( nrepo ) );
517 const zypp::ResStore & store( nrep.resolvables() );
518 repositories.push_back( nrep );
524 Measure x( "LOAD POOL" );
525 for_( it, repositories.begin(), repositories.end() )
527 Measure x( "LOAD POOL "+(*it).info().alias() );
528 const zypp::ResStore & store( (*it).resolvables() );
529 getZYpp()->addResolvables( store );
536 Measure x( "INIT TARGET" );
538 zypp::base::LogControl::TmpLineWriter shutUp;
539 getZYpp()->initTarget( sysRoot );
540 //getZYpp()->initTarget( "/" );
542 dumpPoolStats( SEC << "TargetStore: " << endl,
543 getZYpp()->target()->resolvables().begin(),
544 getZYpp()->target()->resolvables().end() ) << endl;
547 USR << "pool: " << pool << endl;
550 //std::for_each( pool.begin(), pool.end(), Xprint() );
552 MIL << satpool << endl;
553 for_( it, satpool.solvablesBegin(), satpool.solvablesEnd() )
556 //MIL << dump(*it) << endl;
559 ///////////////////////////////////////////////////////////////////
560 INT << "===[END]============================================" << endl << endl;
561 zypp::base::LogControl::instance().logNothing();