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/Debug.h>
8 #include <zypp/base/Functional.h>
9 #include <zypp/base/ProvideNumericId.h>
10 #include <zypp/AutoDispose.h>
12 #include "zypp/ResPoolProxy.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/ResObjects.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/PoolMember.h"
38 #include "zypp/sat/detail/PoolImpl.h"
40 #include <zypp/base/GzStream.h>
42 #include <boost/mpl/int.hpp>
46 using namespace zypp::functor;
47 using namespace zypp::ui;
49 ///////////////////////////////////////////////////////////////////
51 static const Pathname sysRoot( getenv("SYSROOT") ? getenv("SYSROOT") : "/Local/ROOT" );
53 ///////////////////////////////////////////////////////////////////
54 ///////////////////////////////////////////////////////////////////
56 { /////////////////////////////////////////////////////////////////
58 bool queryInstalledEditionHelper( const std::string & name_r,
62 if ( ed_r == Edition::noedition )
64 if ( name_r == "kernel-default" && ed_r == Edition("2.6.22.5-10") )
66 if ( name_r == "update-test-affects-package-manager" && ed_r == Edition("1.1-6") )
73 ManagedFile repoProvidePackage( const PoolItem & pi )
75 ResPool _pool( getZYpp()->pool() );
76 repo::RepoMediaAccess _access;
78 // Redirect PackageProvider queries for installed editions
79 // (in case of patch/delta rpm processing) to rpmDb.
80 repo::PackageProviderPolicy packageProviderPolicy;
81 packageProviderPolicy.queryInstalledCB( queryInstalledEditionHelper );
83 Package::constPtr p = asKind<Package>(pi.resolvable());
85 // Build a repository list for repos
86 // contributing to the pool
87 repo::DeltaCandidates deltas( repo::makeDeltaCandidates( _pool.knownRepositoriesBegin(),
88 _pool.knownRepositoriesEnd() ) );
89 repo::PackageProvider pkgProvider( _access, p, deltas, packageProviderPolicy );
90 return pkgProvider.providePackage();
93 /////////////////////////////////////////////////////////////////
95 ///////////////////////////////////////////////////////////////////
96 ///////////////////////////////////////////////////////////////////
100 template <class _LIterator, class _RIterator, class _Function>
101 inline int invokeOnEach( _LIterator lbegin_r, _LIterator lend_r,
102 _RIterator rbegin_r, _RIterator rend_r,
106 for ( _LIterator lit = lbegin_r; lit != lend_r; ++lit )
108 for ( _RIterator rit = rbegin_r; rit != rend_r; ++rit )
111 if ( ! fnc_r( *lit, *rit ) )
120 void dbgDu( Selectable::Ptr sel )
122 if ( sel->installedPoolItem() )
124 DBG << "i: " << sel->installedPoolItem() << endl
125 << sel->installedPoolItem()->diskusage() << endl;
127 if ( sel->candidatePoolItem() )
129 DBG << "c: " << sel->candidatePoolItem() << endl
130 << sel->candidatePoolItem()->diskusage() << endl;
133 << getZYpp()->diskUsage() << endl;
136 ///////////////////////////////////////////////////////////////////
140 bool operator()( const PoolItem & obj_r )
142 //MIL << obj_r << endl;
143 //DBG << " -> " << obj_r->satSolvable() << endl;
148 bool operator()( const sat::Solvable & obj_r )
150 //dumpOn( MIL, obj_r ) << endl;
155 ///////////////////////////////////////////////////////////////////
156 struct SetTransactValue
158 SetTransactValue( ResStatus::TransactValue newVal_r, ResStatus::TransactByValue causer_r )
159 : _newVal( newVal_r )
160 , _causer( causer_r )
163 ResStatus::TransactValue _newVal;
164 ResStatus::TransactByValue _causer;
166 bool operator()( const PoolItem & pi ) const
168 bool ret = pi.status().setTransactValue( _newVal, _causer );
170 ERR << _newVal << _causer << " " << pi << endl;
175 struct StatusReset : public SetTransactValue
178 : SetTransactValue( ResStatus::KEEP_STATE, ResStatus::USER )
182 struct StatusInstall : public SetTransactValue
185 : SetTransactValue( ResStatus::TRANSACT, ResStatus::USER )
189 inline bool g( const NameKindProxy & nkp, Arch arch = Arch() )
191 if ( nkp.availableEmpty() )
193 ERR << "No Item to select: " << nkp << endl;
195 ZYPP_THROW( Exception("No Item to select") );
198 if ( arch != Arch() )
200 typeof( nkp.availableBegin() ) it = nkp.availableBegin();
201 for ( ; it != nkp.availableEnd(); ++it )
203 if ( (*it)->arch() == arch )
204 return (*it).status().setTransact( true, ResStatus::USER );
208 return nkp.availableBegin()->status().setTransact( true, ResStatus::USER );
211 ///////////////////////////////////////////////////////////////////
217 //zypp::base::LogControl::TmpLineWriter shutUp;
218 rres = getZYpp()->resolver()->resolvePool();
222 ERR << "resolve " << rres << endl;
225 MIL << "resolve " << rres << endl;
231 SEC << getZYpp()->commit( ZYppCommitPolicy() ) << endl;
235 ///////////////////////////////////////////////////////////////////
237 struct ConvertDbReceive : public callback::ReceiveReport<target::ScriptResolvableReport>
239 virtual void start( const Resolvable::constPtr & script_r,
240 const Pathname & path_r,
243 SEC << __FUNCTION__ << endl
244 << " " << script_r << endl
245 << " " << path_r << endl
246 << " " << task_r << endl;
249 virtual bool progress( Notify notify_r, const std::string & text_r )
251 SEC << __FUNCTION__ << endl
252 << " " << notify_r << endl
253 << " " << text_r << endl;
257 virtual void problem( const std::string & description_r )
259 SEC << __FUNCTION__ << endl
260 << " " << description_r << endl;
263 virtual void finish()
265 SEC << __FUNCTION__ << endl;
269 ///////////////////////////////////////////////////////////////////
271 struct DigestReceive : public callback::ReceiveReport<DigestReport>
278 virtual bool askUserToAcceptNoDigest( const zypp::Pathname &file )
283 virtual bool askUserToAccepUnknownDigest( const Pathname &file, const std::string &name )
288 virtual bool askUserToAcceptWrongDigest( const Pathname &file, const std::string &requested, const std::string &found )
290 USR << "fle " << PathInfo(file) << endl;
291 USR << "req " << requested << endl;
292 USR << "fnd " << found << endl;
297 struct KeyRingSignalsReceive : public callback::ReceiveReport<KeyRingSignals>
299 KeyRingSignalsReceive()
303 virtual void trustedKeyAdded( const PublicKey &/*key*/ )
307 virtual void trustedKeyRemoved( const PublicKey &/*key*/ )
313 ///////////////////////////////////////////////////////////////////
315 struct MediaChangeReceive : public callback::ReceiveReport<media::MediaChangeReport>
317 virtual Action requestMedia( Url & source
320 , const std::string & description )
322 SEC << __FUNCTION__ << endl
323 << " " << source << endl
324 << " " << mediumNr << endl
325 << " " << error << endl
326 << " " << description << endl;
331 ///////////////////////////////////////////////////////////////////
336 bool isIn( const std::set<_Tp> & cont, const typename std::set<_Tp>::value_type & val )
337 { return cont.find( val ) != cont.end(); }
339 ///////////////////////////////////////////////////////////////////
341 void itCmp( const sat::Pool::SolvableIterator & l, const sat::Pool::SolvableIterator & r )
343 SEC << *l << " - " << *r << endl;
344 INT << "== " << (l==r) << endl;
345 INT << "!= " << (l!=r) << endl;
348 bool isTrue() { return true; }
349 bool isFalse() { return false; }
353 for ( int i = -3; i < 30; ++i )
355 DBG << i << '\t' << IdString( i ) << endl;
359 void ttt( const char * lhs, const char * rhs )
361 DBG << lhs << " <=> " << rhs << " --> " << ::strcmp( lhs, rhs ) << endl;
366 template <class _MemFun, class _Value>
370 HasValue( _MemFun fun_r, _Value val_r )
371 : _fun( fun_r ), _val( val_r )
374 bool operator()( const _Tp & obj_r ) const
375 { return( _fun && (obj_r.*_fun)() == _val ); }
381 template <class _MemFun, class _Value>
382 HasValue<_MemFun, _Value> byValue( _MemFun fun_r, _Value val_r )
383 { return HasValue<_MemFun, _Value>( fun_r, val_r ); }
391 struct _TestO { _TestO( const L & lhs ) : _lhs( lhs ) {} const L & _lhs; };
394 std::ostream & operator<<( std::ostream & str, const _TestO<L> & obj )
395 { const L & lhs( obj._lhs); return str << (lhs?'_':'*') << (lhs.empty()?'e':'_') << "'" << lhs << "'"; }
398 _TestO<L> testO( const L & lhs )
399 { return _TestO<L>( lhs ); }
401 template <class L, class R>
402 void testCMP( const L & lhs, const R & rhs )
404 MIL << "LHS " << testO(lhs) << endl;
405 MIL << "RHS " << rhs << endl;
407 #define OUTS(S) DBG << #S << ": " << (S) << endl
408 OUTS( lhs.compare(rhs) );
418 ///////////////////////////////////////////////////////////////////
420 { /////////////////////////////////////////////////////////////////
421 ///////////////////////////////////////////////////////////////////
423 { /////////////////////////////////////////////////////////////////
425 class ByLocaleSupport
428 typedef bool (sat::Solvable::*LS1) (const Locale &) const;
429 typedef bool (sat::Solvable::*LS2) (const LocaleSet &) const;
432 /** Solvables with locale support. */
434 : _sel( mem_fun_ref( &sat::Solvable::supportsLocales ) )
437 /** Solvables supporting \c locale_r. */
438 ByLocaleSupport( const Locale & locale_r )
439 : _sel( bind( mem_fun_ref( (LS1)&sat::Solvable::supportsLocale ), _1, locale_r ) )
442 /** Solvables supporting at least one locale in \c locales_r. */
443 ByLocaleSupport( const LocaleSet & locales_r )
444 : _sel( bind( boost::mem_fun_ref( (LS2)&sat::Solvable::supportsLocale ), _1, locales_r ) )
448 bool operator()( const sat::Solvable & solv_r ) const
449 { return _sel && _sel( solv_r ); }
452 template<class _Solv>
453 bool operator()( const _Solv & solv_r ) const
454 { return operator()( solv_r.satSolvable() ); }
457 function<bool(const sat::Solvable &)> _sel;
461 /////////////////////////////////////////////////////////////////
463 ///////////////////////////////////////////////////////////////////
465 /////////////////////////////////////////////////////////////////
467 ///////////////////////////////////////////////////////////////////
470 /******************************************************************
472 ** FUNCTION NAME : main
473 ** FUNCTION TYPE : int
475 int main( int argc, char * argv[] )
477 //zypp::base::LogControl::instance().logfile( "log.restrict" );
478 INT << "===[START]==========================================" << endl;
480 sat::Pool satpool( sat::Pool::instance() );
481 ResPool pool( ResPool::instance() );
482 USR << "pool: " << pool << endl;
484 RepoManager repoManager( makeRepoManager( sysRoot ) );
485 RepoInfoList repos = repoManager.knownRepositories();
488 for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
490 RepoInfo & nrepo( *it );
491 SEC << nrepo << endl;
493 if ( ! nrepo.enabled() )
496 if ( ! repoManager.isCached( nrepo ) || /*force*/false )
498 if ( repoManager.isCached( nrepo ) )
500 SEC << "cleanCache" << endl;
501 repoManager.cleanCache( nrepo );
503 SEC << "refreshMetadata" << endl;
504 repoManager.refreshMetadata( nrepo, RepoManager::RefreshForced );
505 SEC << "buildCache" << endl;
506 repoManager.buildCache( nrepo );
510 // create from cache:
512 Measure x( "CREATE FROM CACHE" );
513 for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
515 RepoInfo & nrepo( *it );
516 if ( ! nrepo.enabled() )
519 Measure x( "CREATE FROM CACHE "+nrepo.alias() );
520 repoManager.loadFromCache( nrepo );
521 USR << "pool: " << pool << endl;
527 Measure x( "INIT TARGET" );
529 getZYpp()->initializeTarget( sysRoot );
530 getZYpp()->target()->load();
534 USR << "pool: " << pool << endl;
535 ///////////////////////////////////////////////////////////////////
537 satpool.addRequestedLocale( Locale("de") );
538 satpool.addRequestedLocale( Locale("cs") );
541 s.insert( Locale("de") );
543 // MIL << satpool.getAvailableLocales() << endl;
547 sat::ByLocaleSupport f( Locale("de") );
548 for_( it, satpool.filterBegin(f), satpool.filterEnd(f) )
558 //MIL << sat::WhatProvides( Capability("amarok") ) << endl;
559 //MIL << sat::WhatProvides( Capability("amarok == 1.4.7-37.4") ) << endl;
563 Measure x( "Upgrade" );
565 getZYpp()->resolver()->doUpgrade( u );
570 PoolItem pi ( getPi<Package>("amarok") );
574 pi.status().setTransact( true, ResStatus::USER );
576 vdumpPoolStats( USR << "Transacting:"<< endl,
577 make_filter_begin<resfilter::ByTransact>(pool),
578 make_filter_end<resfilter::ByTransact>(pool) ) << endl;
582 //vdumpPoolStats( USR << "Pool:"<< endl, pool.begin(), pool.end() ) << endl;
585 //std::for_each( pool.begin(), pool.end(), Xprint() );
587 ///////////////////////////////////////////////////////////////////
588 INT << "===[END]============================================" << endl << endl;
589 zypp::base::LogControl::instance().logNothing();