3 #include "zypp/PoolQueryResult.h"
5 #include <zypp/base/PtrTypes.h>
6 #include <zypp/base/Exception.h>
7 #include <zypp/base/Gettext.h>
8 #include <zypp/base/LogTools.h>
9 #include <zypp/base/Debug.h>
10 #include <zypp/base/Functional.h>
11 #include <zypp/base/IOStream.h>
12 #include <zypp/base/InputStream.h>
13 #include <zypp/base/ProvideNumericId.h>
14 #include <zypp/base/Flags.h>
15 #include <zypp/AutoDispose.h>
17 #include "zypp/ResPoolProxy.h"
19 #include "zypp/ZYppCallbacks.h"
20 #include "zypp/ResPool.h"
21 #include "zypp/ResFilters.h"
22 #include "zypp/ResObjects.h"
23 #include "zypp/Digest.h"
24 #include "zypp/PackageKeyword.h"
25 #include "zypp/TmpPath.h"
26 #include "zypp/ManagedFile.h"
29 #include "zypp/RepoManager.h"
30 #include "zypp/Repository.h"
31 #include "zypp/RepoInfo.h"
33 #include "zypp/repo/PackageProvider.h"
35 #include "zypp/ResPoolProxy.h"
37 #include "zypp/sat/Pool.h"
38 #include "zypp/sat/LocaleSupport.h"
39 #include "zypp/sat/LookupAttr.h"
40 #include "zypp/sat/SolvableSet.h"
41 #include "zypp/sat/SolvIterMixin.h"
42 #include "zypp/sat/detail/PoolImpl.h"
43 #include "zypp/sat/WhatObsoletes.h"
44 #include "zypp/PoolQuery.h"
45 #include "zypp/ServiceInfo.h"
47 #include <boost/mpl/int.hpp>
51 using namespace zypp::functor;
52 using namespace zypp::ui;
54 ///////////////////////////////////////////////////////////////////
56 static const Pathname sysRoot( getenv("SYSROOT") ? getenv("SYSROOT") : "/Local/ROOT" );
58 ///////////////////////////////////////////////////////////////////
59 ///////////////////////////////////////////////////////////////////
61 { /////////////////////////////////////////////////////////////////
63 bool queryInstalledEditionHelper( const std::string & name_r,
67 if ( ed_r == Edition::noedition )
69 if ( name_r == "kernel-default" && ed_r == Edition("2.6.22.5-10") )
71 if ( name_r == "update-test-affects-package-manager" && ed_r == Edition("1.1-6") )
78 ManagedFile repoProvidePackage( const PoolItem & pi )
80 ResPool _pool( getZYpp()->pool() );
81 repo::RepoMediaAccess _access;
83 // Redirect PackageProvider queries for installed editions
84 // (in case of patch/delta rpm processing) to rpmDb.
85 repo::PackageProviderPolicy packageProviderPolicy;
86 packageProviderPolicy.queryInstalledCB( queryInstalledEditionHelper );
88 Package::constPtr p = asKind<Package>(pi.resolvable());
90 // Build a repository list for repos
91 // contributing to the pool
92 repo::DeltaCandidates deltas( repo::makeDeltaCandidates( _pool.knownRepositoriesBegin(),
93 _pool.knownRepositoriesEnd() ) );
94 repo::PackageProvider pkgProvider( _access, p, deltas, packageProviderPolicy );
95 return pkgProvider.providePackage();
98 /////////////////////////////////////////////////////////////////
100 ///////////////////////////////////////////////////////////////////
101 ///////////////////////////////////////////////////////////////////
105 template <class TLIterator, class TRIterator, class TFunction>
106 inline int invokeOnEach( TLIterator lbegin_r, TLIterator lend_r,
107 TRIterator rbegin_r, TRIterator rend_r,
111 for ( TLIterator lit = lbegin_r; lit != lend_r; ++lit )
113 for ( TRIterator rit = rbegin_r; rit != rend_r; ++rit )
116 if ( ! fnc_r( *lit, *rit ) )
124 ///////////////////////////////////////////////////////////////////
126 std::ostream & testDump( std::ostream & str, const PoolItem & pi )
129 Package::constPtr p( asKind<Package>(pi) );
132 #define OUTS(V) str << str::form("%-25s: ",#V) << p->V() << endl
134 str << str::form("%-25s: ",l.code().c_str()) << p->summary(l) << endl;
136 str << str::form("%-25s: ",l.code().c_str()) << p->summary(l) << endl;
137 l = Locale( "dsdf" );
138 str << str::form("%-25s: ",l.code().c_str()) << p->summary(l) << endl;
141 OUTS( downloadSize );
142 OUTS( sourcePkgName );
143 OUTS( sourcePkgEdition );
155 bool operator()( const PoolItem & obj_r )
157 //MIL << obj_r << endl;
158 //DBG << " -> " << obj_r->satSolvable() << endl;
163 bool operator()( const sat::Solvable & obj_r )
165 //dumpOn( MIL, obj_r ) << endl;
170 ///////////////////////////////////////////////////////////////////
171 struct SetTransactValue
173 SetTransactValue( ResStatus::TransactValue newVal_r, ResStatus::TransactByValue causer_r )
174 : _newVal( newVal_r )
175 , _causer( causer_r )
178 ResStatus::TransactValue _newVal;
179 ResStatus::TransactByValue _causer;
181 bool operator()( const PoolItem & pi ) const
183 bool ret = pi.status().setTransactValue( _newVal, _causer );
185 ERR << _newVal << _causer << " " << pi << endl;
190 struct StatusReset : public SetTransactValue
193 : SetTransactValue( ResStatus::KEEP_STATE, ResStatus::USER )
197 struct StatusInstall : public SetTransactValue
200 : SetTransactValue( ResStatus::TRANSACT, ResStatus::USER )
204 ///////////////////////////////////////////////////////////////////
210 //zypp::base::LogControl::TmpLineWriter shutUp;
211 rres = getZYpp()->resolver()->resolvePool();
215 ERR << "resolve " << rres << endl;
216 getZYpp()->resolver()->problems();
219 MIL << "resolve " << rres << endl;
225 ZYppCommitPolicy pol;
227 pol.rpmInstFlags( pol.rpmInstFlags().setFlag( target::rpm::RPMINST_JUSTDB ) );
228 SEC << getZYpp()->commit( pol ) << endl;
234 getZYpp()->resolver()->createSolverTestcase( "./solverTestcase" );
237 ///////////////////////////////////////////////////////////////////
239 struct DigestReceive : public callback::ReceiveReport<DigestReport>
246 virtual bool askUserToAcceptNoDigest( const zypp::Pathname &file )
251 virtual bool askUserToAccepUnknownDigest( const Pathname &file, const std::string &name )
256 virtual bool askUserToAcceptWrongDigest( const Pathname &file, const std::string &requested, const std::string &found )
258 USR << "fle " << PathInfo(file) << endl;
259 USR << "req " << requested << endl;
260 USR << "fnd " << found << endl;
265 struct KeyRingSignalsReceive : public callback::ReceiveReport<KeyRingSignals>
267 KeyRingSignalsReceive()
271 virtual void trustedKeyAdded( const PublicKey &/*key*/ )
275 virtual void trustedKeyRemoved( const PublicKey &/*key*/ )
281 ///////////////////////////////////////////////////////////////////
283 struct MediaChangeReceive : public callback::ReceiveReport<media::MediaChangeReport>
285 virtual Action requestMedia( Url & source
287 , const std::string & label
289 , const std::string & description
290 , const std::vector<std::string> & devices
291 , unsigned int & dev_current )
293 SEC << __FUNCTION__ << endl
294 << " " << source << endl
295 << " " << mediumNr << endl
296 << " " << label << endl
297 << " " << error << endl
298 << " " << description << endl
299 << " " << devices << endl
300 << " " << dev_current << endl;
305 ///////////////////////////////////////////////////////////////////
310 bool isIn( const std::set<Tp> & cont, const typename std::set<Tp>::value_type & val )
311 { return cont.find( val ) != cont.end(); }
313 ///////////////////////////////////////////////////////////////////
315 void itCmp( const sat::Pool::SolvableIterator & l, const sat::Pool::SolvableIterator & r )
317 SEC << *l << " - " << *r << endl;
318 INT << "== " << (l==r) << endl;
319 INT << "!= " << (l!=r) << endl;
322 bool isTrue() { return true; }
323 bool isFalse() { return false; }
327 for ( int i = -3; i < 30; ++i )
329 DBG << i << '\t' << IdString( i ) << endl;
333 void ttt( const char * lhs, const char * rhs )
335 DBG << lhs << " <=> " << rhs << " --> " << ::strcmp( lhs, rhs ) << endl;
342 template <class TMemFun, class TValue>
346 HasValue( TMemFun fun_r, TValue val_r )
347 : _fun( fun_r ), _val( val_r )
350 bool operator()( const Tp & obj_r ) const
351 { return( _fun && (obj_r.*_fun)() == _val ); }
357 template <class TMemFun, class TValue>
358 HasValue<TMemFun, TValue> byValue( TMemFun fun_r, TValue val_r )
359 { return HasValue<TMemFun, TValue>( fun_r, val_r ); }
365 struct TestO { TestO( const L & lhs ) : _lhs( lhs ) {} const L & _lhs; };
368 std::ostream & operator<<( std::ostream & str, const TestO<L> & obj )
369 { const L & lhs( obj._lhs); return str << (lhs?'_':'*') << (lhs.empty()?'e':'_') << "'" << lhs << "'"; }
372 TestO<L> testO( const L & lhs )
373 { return TestO<L>( lhs ); }
375 template <class L, class R>
376 void testCMP( const L & lhs, const R & rhs )
378 MIL << "LHS " << testO(lhs) << endl;
379 MIL << "RHS " << rhs << endl;
381 #define OUTS(S) DBG << #S << ": " << (S) << endl
382 OUTS( lhs.compare(rhs) );
392 inline bool useRepo( RepoInfo & repo )
394 //return repo.alias() == "matest";
395 return repo.enabled();
398 /******************************************************************
400 ** FUNCTION NAME : main
401 ** FUNCTION TYPE : int
403 int main( int argc, char * argv[] )
407 zypp::base::LogControl::instance().logToStdErr();
408 INT << "===[START]==========================================" << endl;
411 ResPool pool( ResPool::instance() );
412 sat::Pool satpool( sat::Pool::instance() );
416 Measure x( "INIT TARGET" );
419 zypp::base::LogControl::TmpLineWriter shutUp;
420 getZYpp()->initializeTarget( sysRoot );
422 getZYpp()->target()->load();
423 USR << getZYpp()->target()->targetDistribution() << endl;
424 USR << getZYpp()->target()->targetDistributionRelease() << endl;
430 RepoManager repoManager( makeRepoManager( sysRoot ) );
431 RepoInfoList repos = repoManager.knownRepositories();
434 for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
436 RepoInfo & nrepo( *it );
437 SEC << nrepo << endl;
439 if ( ! useRepo( nrepo ) )
442 if ( ! repoManager.isCached( nrepo ) || nrepo.type() == repo::RepoType::RPMPLAINDIR )
444 if ( repoManager.isCached( nrepo ) )
446 SEC << "cleanCache" << endl;
447 repoManager.cleanCache( nrepo );
449 SEC << "refreshMetadata" << endl;
450 //repoManager.refreshMetadata( nrepo );
451 SEC << "buildCache" << endl;
452 repoManager.buildCache( nrepo );
456 // create from cache:
458 Measure x( "CREATE FROM CACHE" );
459 for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
461 RepoInfo & nrepo( *it );
462 if ( ! useRepo( nrepo ) )
465 Measure x( "CREATE FROM CACHE "+nrepo.alias() );
468 repoManager.loadFromCache( nrepo );
470 catch ( const Exception & exp )
472 MIL << "Try to rebuild cache..." << endl;
473 SEC << "cleanCache" << endl;
474 repoManager.cleanCache( nrepo );
475 SEC << "buildCache" << endl;
476 repoManager.buildCache( nrepo );
477 SEC << "Create from cache" << endl;
478 repoManager.loadFromCache( nrepo );
481 USR << "pool: " << pool << endl;
486 dumpRange( USR, satpool.reposBegin(), satpool.reposEnd() );
487 USR << "pool: " << pool << endl;
489 ///////////////////////////////////////////////////////////////////
493 Measure x( "Upgrade" );
494 getZYpp()->resolver()->doUpgrade();
497 ///////////////////////////////////////////////////////////////////
498 ///////////////////////////////////////////////////////////////////
499 // UNTh_(2)product:openSUSE-11.1.x86_64(openSUSE-dvd-11.1)
500 // U_Th_(583)yast2-ntp-client-2.17.1-1.26.noarch(openSUSE-dvd-11.1)
501 // U_Th_(1652)kernel-default-2.6.27-7.2.x86_64(openSUSE-dvd-11.1)
502 // U_Th_(2490)ntp-4.2.4p5-1.6.x86_64(openSUSE-dvd-11.1)
503 // UNTh_(2545)openSUSE-release-11.1-1.4.x86_64(openSUSE-dvd-11.1)
504 // USTh_(3462)pattern:base-11.1-46.1.x86_64(openSUSE-dvd-11.1)
505 // USTh_(3672)pattern:x11-11.1-46.1.x86_64(openSUSE-dvd-11.1)
506 // USTu_(3680)pattern:xfce-11.1-46.1.x86_64(openSUSE-dvd-11.1)
509 getZYpp()->resolver()->addRequire( Capability("product:openSUSE") );
510 getZYpp()->resolver()->addRequire( Capability("yast2-ntp-client") );
511 getZYpp()->resolver()->addRequire( Capability("kernel-default") );
512 getZYpp()->resolver()->addRequire( Capability("ntp") );
513 getZYpp()->resolver()->addRequire( Capability("openSUSE-release") );
514 getZYpp()->resolver()->addRequire( Capability("pattern:base") );
515 getZYpp()->resolver()->addRequire( Capability("pattern:x11") );
516 getZYpp()->resolver()->addRequire( Capability("pattern:xfce") );
520 vdumpPoolStats( USR << "Transacting:"<< endl,
521 make_filter_begin<resfilter::ByTransact>(pool),
522 make_filter_end<resfilter::ByTransact>(pool) ) << endl;
526 DiskUsageCounter ducounter( DiskUsageCounter::justRootPartition() );
527 for_( it, make_filter_begin<resfilter::ByTransact>(pool), make_filter_end<resfilter::ByTransact>(pool) )
530 ByteCount csze( ducounter.disk_usage( *it ).begin()->commitDiff() );
531 sze += (*it)->installSize();
533 DBG <<(*it)->installSize() << " vs. " << csze << " | " << ByteCount( dusze-sze ) << endl;
537 SEC << dusze << endl;
539 SEC << zypp::getZYpp()->diskUsage() << endl;
541 ///////////////////////////////////////////////////////////////////
542 INT << "===[END]============================================" << endl << endl;
543 zypp::base::LogControl::instance().logNothing();
546 catch ( const Exception & exp )
548 INT << exp << endl << exp.historyAsString();