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/IOStream.h>
10 #include <zypp/base/ProvideNumericId.h>
11 #include <zypp/AutoDispose.h>
13 #include "zypp/ResPoolProxy.h"
15 #include "zypp/ZYppCallbacks.h"
16 #include "zypp/NVRAD.h"
17 #include "zypp/ResPool.h"
18 #include "zypp/ResFilters.h"
19 #include "zypp/ResObjects.h"
20 #include "zypp/Digest.h"
21 #include "zypp/PackageKeyword.h"
22 #include "zypp/TmpPath.h"
23 #include "zypp/ManagedFile.h"
24 #include "zypp/NameKindProxy.h"
25 #include "zypp/pool/GetResolvablesToInsDel.h"
27 #include "zypp/RepoManager.h"
28 #include "zypp/Repository.h"
29 #include "zypp/RepoInfo.h"
31 #include "zypp/repo/PackageProvider.h"
33 #include "zypp/ui/PatchContents.h"
34 #include "zypp/ResPoolProxy.h"
36 #include "zypp/sat/Pool.h"
37 #include "zypp/sat/LocaleSupport.h"
38 #include "zypp/sat/LookupAttr.h"
39 #include "zypp/sat/SolvableSet.h"
40 #include "zypp/sat/SolvIterMixin.h"
41 #include "zypp/sat/detail/PoolImpl.h"
42 #include "zypp/PoolQuery.h"
44 #include <zypp/base/GzStream.h>
46 #include <boost/mpl/int.hpp>
50 using namespace zypp::functor;
51 using namespace zypp::ui;
53 ///////////////////////////////////////////////////////////////////
55 static const Pathname sysRoot( getenv("SYSROOT") ? getenv("SYSROOT") : "/Local/ROOT" );
57 ///////////////////////////////////////////////////////////////////
58 ///////////////////////////////////////////////////////////////////
60 { /////////////////////////////////////////////////////////////////
62 bool queryInstalledEditionHelper( const std::string & name_r,
66 if ( ed_r == Edition::noedition )
68 if ( name_r == "kernel-default" && ed_r == Edition("2.6.22.5-10") )
70 if ( name_r == "update-test-affects-package-manager" && ed_r == Edition("1.1-6") )
77 ManagedFile repoProvidePackage( const PoolItem & pi )
79 ResPool _pool( getZYpp()->pool() );
80 repo::RepoMediaAccess _access;
82 // Redirect PackageProvider queries for installed editions
83 // (in case of patch/delta rpm processing) to rpmDb.
84 repo::PackageProviderPolicy packageProviderPolicy;
85 packageProviderPolicy.queryInstalledCB( queryInstalledEditionHelper );
87 Package::constPtr p = asKind<Package>(pi.resolvable());
89 // Build a repository list for repos
90 // contributing to the pool
91 repo::DeltaCandidates deltas( repo::makeDeltaCandidates( _pool.knownRepositoriesBegin(),
92 _pool.knownRepositoriesEnd() ) );
93 repo::PackageProvider pkgProvider( _access, p, deltas, packageProviderPolicy );
94 return pkgProvider.providePackage();
97 /////////////////////////////////////////////////////////////////
99 ///////////////////////////////////////////////////////////////////
100 ///////////////////////////////////////////////////////////////////
104 template <class _LIterator, class _RIterator, class _Function>
105 inline int invokeOnEach( _LIterator lbegin_r, _LIterator lend_r,
106 _RIterator rbegin_r, _RIterator rend_r,
110 for ( _LIterator lit = lbegin_r; lit != lend_r; ++lit )
112 for ( _RIterator rit = rbegin_r; rit != rend_r; ++rit )
115 if ( ! fnc_r( *lit, *rit ) )
124 void dbgDu( Selectable::Ptr sel )
126 if ( sel->installedObj() )
128 DBG << "i: " << sel->installedObj() << endl
129 << sel->installedObj()->diskusage() << endl;
131 if ( sel->candidateObj() )
133 DBG << "c: " << sel->candidateObj() << endl
134 << sel->candidateObj()->diskusage() << endl;
137 << getZYpp()->diskUsage() << endl;
140 ///////////////////////////////////////////////////////////////////
142 std::ostream & testDump( std::ostream & str, const PoolItem & pi )
145 Package::constPtr p( asKind<Package>(pi) );
148 #define OUTS(V) str << str::form("%-25s: ",#V) << p->V() << endl
150 str << str::form("%-25s: ",l.code().c_str()) << p->summary(l) << endl;
152 str << str::form("%-25s: ",l.code().c_str()) << p->summary(l) << endl;
153 l = Locale( "dsdf" );
154 str << str::form("%-25s: ",l.code().c_str()) << p->summary(l) << endl;
157 OUTS( downloadSize );
158 OUTS( sourcePkgName );
159 OUTS( sourcePkgEdition );
171 bool operator()( const PoolItem & obj_r )
173 //MIL << obj_r << endl;
174 //DBG << " -> " << obj_r->satSolvable() << endl;
179 bool operator()( const sat::Solvable & obj_r )
181 //dumpOn( MIL, obj_r ) << endl;
186 ///////////////////////////////////////////////////////////////////
187 struct SetTransactValue
189 SetTransactValue( ResStatus::TransactValue newVal_r, ResStatus::TransactByValue causer_r )
190 : _newVal( newVal_r )
191 , _causer( causer_r )
194 ResStatus::TransactValue _newVal;
195 ResStatus::TransactByValue _causer;
197 bool operator()( const PoolItem & pi ) const
199 bool ret = pi.status().setTransactValue( _newVal, _causer );
201 ERR << _newVal << _causer << " " << pi << endl;
206 struct StatusReset : public SetTransactValue
209 : SetTransactValue( ResStatus::KEEP_STATE, ResStatus::USER )
213 struct StatusInstall : public SetTransactValue
216 : SetTransactValue( ResStatus::TRANSACT, ResStatus::USER )
220 inline bool g( const NameKindProxy & nkp, Arch arch = Arch() )
222 if ( nkp.availableEmpty() )
224 ERR << "No Item to select: " << nkp << endl;
226 ZYPP_THROW( Exception("No Item to select") );
229 if ( arch != Arch() )
231 typeof( nkp.availableBegin() ) it = nkp.availableBegin();
232 for ( ; it != nkp.availableEnd(); ++it )
234 if ( (*it)->arch() == arch )
235 return (*it).status().setTransact( true, ResStatus::USER );
239 return nkp.availableBegin()->status().setTransact( true, ResStatus::USER );
242 ///////////////////////////////////////////////////////////////////
248 //zypp::base::LogControl::TmpLineWriter shutUp;
249 rres = getZYpp()->resolver()->resolvePool();
253 ERR << "resolve " << rres << endl;
256 MIL << "resolve " << rres << endl;
262 SEC << getZYpp()->commit( ZYppCommitPolicy() ) << endl;
266 ///////////////////////////////////////////////////////////////////
268 struct ConvertDbReceive : public callback::ReceiveReport<target::ScriptResolvableReport>
270 virtual void start( const Resolvable::constPtr & script_r,
271 const Pathname & path_r,
274 SEC << __FUNCTION__ << endl
275 << " " << script_r << endl
276 << " " << path_r << endl
277 << " " << task_r << endl;
280 virtual bool progress( Notify notify_r, const std::string & text_r )
282 SEC << __FUNCTION__ << endl
283 << " " << notify_r << endl
284 << " " << text_r << endl;
288 virtual void problem( const std::string & description_r )
290 SEC << __FUNCTION__ << endl
291 << " " << description_r << endl;
294 virtual void finish()
296 SEC << __FUNCTION__ << endl;
300 ///////////////////////////////////////////////////////////////////
302 struct DigestReceive : public callback::ReceiveReport<DigestReport>
309 virtual bool askUserToAcceptNoDigest( const zypp::Pathname &file )
314 virtual bool askUserToAccepUnknownDigest( const Pathname &file, const std::string &name )
319 virtual bool askUserToAcceptWrongDigest( const Pathname &file, const std::string &requested, const std::string &found )
321 USR << "fle " << PathInfo(file) << endl;
322 USR << "req " << requested << endl;
323 USR << "fnd " << found << endl;
328 struct KeyRingSignalsReceive : public callback::ReceiveReport<KeyRingSignals>
330 KeyRingSignalsReceive()
334 virtual void trustedKeyAdded( const PublicKey &/*key*/ )
338 virtual void trustedKeyRemoved( const PublicKey &/*key*/ )
344 ///////////////////////////////////////////////////////////////////
346 struct MediaChangeReceive : public callback::ReceiveReport<media::MediaChangeReport>
348 virtual Action requestMedia( Url & source
350 , const std::string & label
352 , const std::string & description
353 , const std::vector<std::string> & devices
354 , unsigned int & dev_current )
356 SEC << __FUNCTION__ << endl
357 << " " << source << endl
358 << " " << mediumNr << endl
359 << " " << label << endl
360 << " " << error << endl
361 << " " << description << endl
362 << " " << devices << endl
363 << " " << dev_current << endl;
368 ///////////////////////////////////////////////////////////////////
373 bool isIn( const std::set<_Tp> & cont, const typename std::set<_Tp>::value_type & val )
374 { return cont.find( val ) != cont.end(); }
376 ///////////////////////////////////////////////////////////////////
378 void itCmp( const sat::Pool::SolvableIterator & l, const sat::Pool::SolvableIterator & r )
380 SEC << *l << " - " << *r << endl;
381 INT << "== " << (l==r) << endl;
382 INT << "!= " << (l!=r) << endl;
385 bool isTrue() { return true; }
386 bool isFalse() { return false; }
390 for ( int i = -3; i < 30; ++i )
392 DBG << i << '\t' << IdString( i ) << endl;
396 void ttt( const char * lhs, const char * rhs )
398 DBG << lhs << " <=> " << rhs << " --> " << ::strcmp( lhs, rhs ) << endl;
405 template <class _MemFun, class _Value>
409 HasValue( _MemFun fun_r, _Value val_r )
410 : _fun( fun_r ), _val( val_r )
413 bool operator()( const _Tp & obj_r ) const
414 { return( _fun && (obj_r.*_fun)() == _val ); }
420 template <class _MemFun, class _Value>
421 HasValue<_MemFun, _Value> byValue( _MemFun fun_r, _Value val_r )
422 { return HasValue<_MemFun, _Value>( fun_r, val_r ); }
428 struct _TestO { _TestO( const L & lhs ) : _lhs( lhs ) {} const L & _lhs; };
431 std::ostream & operator<<( std::ostream & str, const _TestO<L> & obj )
432 { const L & lhs( obj._lhs); return str << (lhs?'_':'*') << (lhs.empty()?'e':'_') << "'" << lhs << "'"; }
435 _TestO<L> testO( const L & lhs )
436 { return _TestO<L>( lhs ); }
438 template <class L, class R>
439 void testCMP( const L & lhs, const R & rhs )
441 MIL << "LHS " << testO(lhs) << endl;
442 MIL << "RHS " << rhs << endl;
444 #define OUTS(S) DBG << #S << ": " << (S) << endl
445 OUTS( lhs.compare(rhs) );
458 template <class _Filter>
461 typedef filter_iterator<_Filter,ResPool::const_iterator> iterator;
467 PoolFilter( const _Filter & filter_r )
468 : _filter( filter_r )
471 iterator begin() const
472 { return ResPool::instance().filterBegin(_filter); }
475 { return ResPool::instance().filterEnd(_filter); }
481 template <class _Filter>
482 PoolFilter<_Filter> makePoolFilter( const _Filter & filter_r )
483 { return PoolFilter<_Filter>( filter_r ); }
486 void tt( const std::string & name_r, ResKind kind_r = ResKind::package )
488 Capability cap( name_r, kind_r );
489 sat::WhatProvides possibleProviders(cap);
490 (possibleProviders.empty()?WAR:MIL) << name_r << endl;
491 for_(iter, possibleProviders.begin(), possibleProviders.end())
493 MIL << name_r << endl;
494 PoolItem provider = ResPool::instance().find(*iter);
498 bool myfilter( const PoolItem & pi )
500 if ( pi->name() == "ruby" )
505 struct Foo : private debug::TraceCAD<Foo>
515 void dit( const Pattern::Contents & c_r )
518 sat::WhatProvides c( Capability("amarok") );
519 dumpRange( MIL, c.solvableBegin(), c.solvableEnd() ) << endl;
520 dumpRange( MIL, c.poolItemBegin(), c.poolItemEnd() ) << endl;
521 dumpRange( MIL, c.selectableBegin(), c.selectableEnd() ) << endl;
524 const Pattern::Contents & c( c_r );
525 dumpRange( MIL, c.solvableBegin(), c.solvableEnd() ) << endl;
526 dumpRange( WAR, c.poolItemBegin(), c.poolItemEnd() ) << endl;
527 dumpRange( ERR, c.selectableBegin(), c.selectableEnd() ) << endl;
531 void ditest( sat::Solvable slv_r )
533 MIL << slv_r << endl;
534 Package::Ptr pkg( make<Package>( slv_r ) );
535 dumpRange( DBG, pkg->keywords().begin(), pkg->keywords().end() ) << endl;
539 void ditest( const PoolItem & pi_r )
541 ditest( pi_r.satSolvable() );
545 /******************************************************************
547 ** FUNCTION NAME : main
548 ** FUNCTION TYPE : int
550 int main( int argc, char * argv[] )
554 zypp::base::LogControl::instance().logToStdErr();
555 INT << "===[START]==========================================" << endl;
556 ZConfig::instance().setTextLocale(Locale("de"));
558 sat::Pool satpool( sat::Pool::instance() );
559 ResPool pool( ResPool::instance() );
560 USR << "pool: " << pool << endl;
564 RepoManager repoManager( makeRepoManager( sysRoot ) );
565 RepoInfoList repos = repoManager.knownRepositories();
568 for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
570 RepoInfo & nrepo( *it );
571 SEC << nrepo << endl;
573 if ( ! nrepo.enabled() )
576 if ( ! repoManager.isCached( nrepo ) || /*force*/false )
578 if ( repoManager.isCached( nrepo ) )
580 SEC << "cleanCache" << endl;
581 repoManager.cleanCache( nrepo );
583 //SEC << "refreshMetadata" << endl;
584 //repoManager.refreshMetadata( nrepo, RepoManager::RefreshForced );
585 SEC << "buildCache" << endl;
586 repoManager.buildCache( nrepo );
590 // create from cache:
592 Measure x( "CREATE FROM CACHE" );
593 for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
595 RepoInfo & nrepo( *it );
596 if ( ! nrepo.enabled() )
599 Measure x( "CREATE FROM CACHE "+nrepo.alias() );
602 repoManager.loadFromCache( nrepo );
604 catch ( const Exception & exp )
606 MIL << "Try to rebuild cache..." << endl;
607 SEC << "cleanCache" << endl;
608 repoManager.cleanCache( nrepo );
609 SEC << "buildCache" << endl;
610 repoManager.buildCache( nrepo );
611 SEC << "Create from cache" << endl;
612 repoManager.loadFromCache( nrepo );
615 USR << "pool: " << pool << endl;
622 Measure x( "INIT TARGET" );
624 getZYpp()->initializeTarget( sysRoot );
625 getZYpp()->target()->load();
629 dumpRange( USR, satpool.reposBegin(), satpool.reposEnd() );
630 USR << "pool: " << pool << endl;
632 ///////////////////////////////////////////////////////////////////
635 Measure x( "Upgrade" );
637 getZYpp()->resolver()->doUpgrade( u );
639 ///////////////////////////////////////////////////////////////////
640 ///////////////////////////////////////////////////////////////////
642 //vdumpPoolStats( USR << "Pool:"<< endl, pool.begin(), pool.end() ) << endl;
646 std::string name( pool.begin()->resolvable()->name() );
647 PoolItem pi ( getPi<Package>( name ) );
651 pi.status().setTransact( true, ResStatus::USER );
653 vdumpPoolStats( USR << "Transacting:"<< endl,
654 make_filter_begin<resfilter::ByTransact>(pool),
655 make_filter_end<resfilter::ByTransact>(pool) ) << endl;
658 pi = getPi<Package>( name );
661 INT << "Still here? " << getPi<Package>("ant") << endl;
666 ///////////////////////////////////////////////////////////////////
667 INT << "===[END]============================================" << endl << endl;
668 zypp::base::LogControl::instance().logNothing();
672 Measure x( "PROCXY" );
677 Measure x( "ALL PATTERNS" );
679 for_( it, pool.byKindBegin<Pattern>(), pool.byKindEnd<Pattern>() )
681 Measure x( string(" ") + (*it)->name() );
682 Pattern::Contents c( asKind<Pattern>(*it)->contents() );
684 Measure x( " poolitem" );
685 dumpRange( WAR, c.poolItemBegin(), c.poolItemEnd() ) << endl;
688 Measure x( " selectable" );
689 dumpRange( ERR, c.selectableBegin(), c.selectableEnd() ) << endl;
695 SEC << zypp::getZYpp()->diskUsage() << endl;
699 PoolItem pi ( getPi<Package>("amarok") );
703 pi.status().setTransact( true, ResStatus::USER );
705 vdumpPoolStats( USR << "Transacting:"<< endl,
706 make_filter_begin<resfilter::ByTransact>(pool),
707 make_filter_end<resfilter::ByTransact>(pool) ) << endl;
712 SEC << zypp::getZYpp()->diskUsage() << endl;
714 //vdumpPoolStats( USR << "Pool:"<< endl, pool.begin(), pool.end() ) << endl;
717 //std::for_each( pool.begin(), pool.end(), Xprint() );
719 ///////////////////////////////////////////////////////////////////
720 INT << "===[END]============================================" << endl << endl;
721 zypp::base::LogControl::instance().logNothing();
724 catch ( const Exception & exp )
726 INT << exp << endl << exp.historyAsString();