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/ProvideNumericId.h>
9 #include <zypp/AutoDispose.h>
11 #include "zypp/ResPoolProxy.h"
13 #include "zypp/ZYppCallbacks.h"
14 #include "zypp/NVRAD.h"
15 #include "zypp/ResPool.h"
16 #include "zypp/ResFilters.h"
17 #include "zypp/CapFilters.h"
18 #include "zypp/ResObjects.h"
19 #include "zypp/Digest.h"
20 #include "zypp/PackageKeyword.h"
21 #include "zypp/ManagedFile.h"
22 #include "zypp/NameKindProxy.h"
23 #include "zypp/pool/GetResolvablesToInsDel.h"
25 #include "zypp/RepoManager.h"
26 #include "zypp/RepoInfo.h"
28 #include "zypp/repo/PackageProvider.h"
30 #include "zypp/ui/PatchContents.h"
31 #include "zypp/ResPoolProxy.h"
33 #include "zypp/sat/Pool.h"
34 #include "zypp/sat/Repo.h"
35 #include "zypp/sat/Solvable.h"
36 #include "zypp/sat/detail/PoolImpl.h"
38 #include <zypp/base/GzStream.h>
40 #include <boost/mpl/int.hpp>
44 using namespace zypp::functor;
45 using namespace zypp::ui;
47 ///////////////////////////////////////////////////////////////////
49 static const Pathname sysRoot( "/Local/ROOT" );
51 ///////////////////////////////////////////////////////////////////
52 ///////////////////////////////////////////////////////////////////
54 { /////////////////////////////////////////////////////////////////
56 bool queryInstalledEditionHelper( const std::string & name_r,
60 if ( ed_r == Edition::noedition )
62 if ( name_r == "kernel-default" && ed_r == Edition("2.6.22.5-10") )
64 if ( name_r == "update-test-affects-package-manager" && ed_r == Edition("1.1-6") )
71 ManagedFile repoProvidePackage( const PoolItem & pi )
73 ResPool _pool( getZYpp()->pool() );
74 repo::RepoMediaAccess _access;
76 // Redirect PackageProvider queries for installed editions
77 // (in case of patch/delta rpm processing) to rpmDb.
78 repo::PackageProviderPolicy packageProviderPolicy;
79 packageProviderPolicy.queryInstalledCB( queryInstalledEditionHelper );
81 Package::constPtr p = asKind<Package>(pi.resolvable());
83 // Build a repository list for repos
84 // contributing to the pool
85 repo::DeltaCandidates deltas( repo::makeDeltaCandidates( _pool.knownRepositoriesBegin(),
86 _pool.knownRepositoriesEnd() ) );
87 repo::PackageProvider pkgProvider( _access, p, deltas, packageProviderPolicy );
88 return pkgProvider.providePackage();
91 /////////////////////////////////////////////////////////////////
93 ///////////////////////////////////////////////////////////////////
94 ///////////////////////////////////////////////////////////////////
98 template <class _LIterator, class _RIterator, class _Function>
99 inline int invokeOnEach( _LIterator lbegin_r, _LIterator lend_r,
100 _RIterator rbegin_r, _RIterator rend_r,
104 for ( _LIterator lit = lbegin_r; lit != lend_r; ++lit )
106 for ( _RIterator rit = rbegin_r; rit != rend_r; ++rit )
109 if ( ! fnc_r( *lit, *rit ) )
118 void dbgDu( Selectable::Ptr sel )
120 if ( sel->installedPoolItem() )
122 DBG << "i: " << sel->installedPoolItem() << endl
123 << sel->installedPoolItem()->diskusage() << endl;
125 if ( sel->candidatePoolItem() )
127 DBG << "c: " << sel->candidatePoolItem() << endl
128 << sel->candidatePoolItem()->diskusage() << endl;
131 << getZYpp()->diskUsage() << endl;
134 ///////////////////////////////////////////////////////////////////
138 bool operator()( const PoolItem & obj_r )
140 MIL << obj_r << endl;
141 DBG << " -> " << obj_r->satSolvable() << endl;
146 bool operator()( const sat::Solvable & obj_r )
148 dumpOn( MIL, obj_r ) << endl;
153 ///////////////////////////////////////////////////////////////////
154 struct SetTransactValue
156 SetTransactValue( ResStatus::TransactValue newVal_r, ResStatus::TransactByValue causer_r )
157 : _newVal( newVal_r )
158 , _causer( causer_r )
161 ResStatus::TransactValue _newVal;
162 ResStatus::TransactByValue _causer;
164 bool operator()( const PoolItem & pi ) const
166 bool ret = pi.status().setTransactValue( _newVal, _causer );
168 ERR << _newVal << _causer << " " << pi << endl;
173 struct StatusReset : public SetTransactValue
176 : SetTransactValue( ResStatus::KEEP_STATE, ResStatus::USER )
180 struct StatusInstall : public SetTransactValue
183 : SetTransactValue( ResStatus::TRANSACT, ResStatus::USER )
187 inline bool g( const NameKindProxy & nkp, Arch arch = Arch() )
189 if ( nkp.availableEmpty() )
191 ERR << "No Item to select: " << nkp << endl;
193 ZYPP_THROW( Exception("No Item to select") );
196 if ( arch != Arch() )
198 typeof( nkp.availableBegin() ) it = nkp.availableBegin();
199 for ( ; it != nkp.availableEnd(); ++it )
201 if ( (*it)->arch() == arch )
202 return (*it).status().setTransact( true, ResStatus::USER );
206 return nkp.availableBegin()->status().setTransact( true, ResStatus::USER );
209 ///////////////////////////////////////////////////////////////////
215 zypp::base::LogControl::TmpLineWriter shutUp;
216 rres = getZYpp()->resolver()->resolvePool();
220 ERR << "resolve " << rres << endl;
223 MIL << "resolve " << rres << endl;
229 SEC << getZYpp()->commit( ZYppCommitPolicy() ) << endl;
233 ///////////////////////////////////////////////////////////////////
235 struct ConvertDbReceive : public callback::ReceiveReport<target::ScriptResolvableReport>
237 virtual void start( const Resolvable::constPtr & script_r,
238 const Pathname & path_r,
241 SEC << __FUNCTION__ << endl
242 << " " << script_r << endl
243 << " " << path_r << endl
244 << " " << task_r << endl;
247 virtual bool progress( Notify notify_r, const std::string & text_r )
249 SEC << __FUNCTION__ << endl
250 << " " << notify_r << endl
251 << " " << text_r << endl;
255 virtual void problem( const std::string & description_r )
257 SEC << __FUNCTION__ << endl
258 << " " << description_r << endl;
261 virtual void finish()
263 SEC << __FUNCTION__ << endl;
267 ///////////////////////////////////////////////////////////////////
269 struct DigestReceive : public callback::ReceiveReport<DigestReport>
276 virtual bool askUserToAcceptNoDigest( const zypp::Pathname &file )
281 virtual bool askUserToAccepUnknownDigest( const Pathname &file, const std::string &name )
286 virtual bool askUserToAcceptWrongDigest( const Pathname &file, const std::string &requested, const std::string &found )
288 USR << "fle " << PathInfo(file) << endl;
289 USR << "req " << requested << endl;
290 USR << "fnd " << found << endl;
295 struct KeyRingSignalsReceive : public callback::ReceiveReport<KeyRingSignals>
297 KeyRingSignalsReceive()
301 virtual void trustedKeyAdded( const PublicKey &/*key*/ )
305 virtual void trustedKeyRemoved( const PublicKey &/*key*/ )
311 ///////////////////////////////////////////////////////////////////
313 struct MediaChangeReceive : public callback::ReceiveReport<media::MediaChangeReport>
315 virtual Action requestMedia( Url & source
318 , const std::string & description )
320 SEC << __FUNCTION__ << endl
321 << " " << source << endl
322 << " " << mediumNr << endl
323 << " " << error << endl
324 << " " << description << endl;
329 ///////////////////////////////////////////////////////////////////
334 bool isIn( const std::set<_Tp> & cont, const typename std::set<_Tp>::value_type & val )
335 { return cont.find( val ) != cont.end(); }
337 ///////////////////////////////////////////////////////////////////
339 void itCmp( const sat::Pool::SolvableIterator & l, const sat::Pool::SolvableIterator & r )
341 SEC << *l << " - " << *r << endl;
342 INT << "== " << (l==r) << endl;
343 INT << "!= " << (l!=r) << endl;
346 bool isTrue() { return true; }
347 bool isFalse() { return false; }
351 for ( int i = -3; i < 30; ++i )
353 DBG << i << '\t' << IdString( i ) << endl;
357 void ttt( const char * lhs, const char * rhs )
359 DBG << lhs << " <=> " << rhs << " --> " << ::strcmp( lhs, rhs ) << endl;
364 template <class _MemFun, class _Value>
368 HasValue( _MemFun fun_r, _Value val_r )
369 : _fun( fun_r ), _val( val_r )
372 bool operator()( const _Tp & obj_r ) const
373 { return( _fun && (obj_r.*_fun)() == _val ); }
379 template <class _MemFun, class _Value>
380 HasValue<_MemFun, _Value> byValue( _MemFun fun_r, _Value val_r )
381 { return HasValue<_MemFun, _Value>( fun_r, val_r ); }
389 struct _TestO { _TestO( const L & lhs ) : _lhs( lhs ) {} const L & _lhs; };
392 std::ostream & operator<<( std::ostream & str, const _TestO<L> & obj )
393 { const L & lhs( obj._lhs); return str << (lhs?'_':'*') << (lhs.empty()?'e':'_') << "'" << lhs << "'"; }
396 _TestO<L> testO( const L & lhs )
397 { return _TestO<L>( lhs ); }
399 template <class L, class R>
400 void testCMP( const L & lhs, const R & rhs )
402 MIL << "LHS " << testO(lhs) << endl;
403 MIL << "RHS " << rhs << endl;
405 #define OUTS(S) DBG << #S << ": " << (S) << endl
406 OUTS( lhs.compare(rhs) );
416 /******************************************************************
418 ** FUNCTION NAME : main
419 ** FUNCTION TYPE : int
421 int main( int argc, char * argv[] )
423 //zypp::base::LogControl::instance().logfile( "log.restrict" );
424 INT << "===[START]==========================================" << endl;
425 setenv( "ZYPP_CONF", (sysRoot/"zypp.conf").c_str(), 1 );
427 sat::Pool satpool( sat::Pool::instance() );
428 ResPool pool( ResPool::instance() );
429 USR << "pool: " << pool << endl;
431 RepoManager repoManager( makeRepoManager( sysRoot ) );
432 RepoInfoList repos = repoManager.knownRepositories();
435 for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
437 RepoInfo & nrepo( *it );
438 SEC << nrepo << endl;
440 if ( ! nrepo.enabled() )
443 if ( ! repoManager.isCached( nrepo ) || /*force*/false )
445 if ( repoManager.isCached( nrepo ) )
447 SEC << "cleanCache" << endl;
448 repoManager.cleanCache( nrepo );
450 SEC << "refreshMetadata" << endl;
451 repoManager.refreshMetadata( nrepo, RepoManager::RefreshForced );
452 SEC << "buildCache" << endl;
453 repoManager.buildCache( nrepo );
457 // create from cache:
459 Measure x( "CREATE FROM CACHE" );
460 for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
462 RepoInfo & nrepo( *it );
463 if ( ! nrepo.enabled() )
466 Measure x( "CREATE FROM CACHE "+nrepo.alias() );
467 repoManager.loadFromCache( nrepo );
468 USR << "pool: " << pool << endl;
474 Measure x( "INIT TARGET" );
476 // zypp::base::LogControl::TmpLineWriter shutUp;
477 getZYpp()->initializeTarget( sysRoot );
478 getZYpp()->target()->load();
482 MIL << satpool << endl;
483 USR << "pool: " << pool << endl;
485 vdumpPoolStats( USR << "Pool:"<< endl,
486 pool.begin(), pool.end() ) << endl;
490 //std::for_each( pool.begin(), pool.end(), Xprint() );
492 // for_( it, satpool.solvablesBegin(), satpool.solvablesEnd() )
494 // MIL << *it << endl;
495 // //MIL << dump(*it) << endl;
498 ///////////////////////////////////////////////////////////////////
499 INT << "===[END]============================================" << endl << endl;
500 zypp::base::LogControl::instance().logNothing();