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 _LIterator, class _RIterator, class _Function>
106
inline int invokeOnEach( _LIterator lbegin_r, _LIterator lend_r,
107
_RIterator rbegin_r, _RIterator rend_r,
111
for ( _LIterator lit = lbegin_r; lit != lend_r; ++lit )
113
for ( _RIterator rit = rbegin_r; rit != rend_r; ++rit )
116
if ( ! fnc_r( *lit, *rit ) )
125
void dbgDu( Selectable::Ptr sel )
127
if ( sel->installedObj() )
129
DBG << "i: " << sel->installedObj() << endl
130
<< sel->installedObj()->diskusage() << endl;
132
if ( sel->candidateObj() )
134
DBG << "c: " << sel->candidateObj() << endl
135
<< sel->candidateObj()->diskusage() << endl;
138
<< getZYpp()->diskUsage() << endl;
141
///////////////////////////////////////////////////////////////////
143
std::ostream & testDump( std::ostream & str, const PoolItem & pi )
146
Package::constPtr p( asKind<Package>(pi) );
149
#define OUTS(V) str << str::form("%-25s: ",#V) << p->V() << endl
151
str << str::form("%-25s: ",l.code().c_str()) << p->summary(l) << endl;
153
str << str::form("%-25s: ",l.code().c_str()) << p->summary(l) << endl;
154
l = Locale( "dsdf" );
155
str << str::form("%-25s: ",l.code().c_str()) << p->summary(l) << endl;
158
OUTS( downloadSize );
159
OUTS( sourcePkgName );
160
OUTS( sourcePkgEdition );
172
bool operator()( const PoolItem & obj_r )
174
//MIL << obj_r << endl;
175
//DBG << " -> " << obj_r->satSolvable() << endl;
180
bool operator()( const sat::Solvable & obj_r )
182
//dumpOn( MIL, obj_r ) << endl;
187
///////////////////////////////////////////////////////////////////
188
struct SetTransactValue
190
SetTransactValue( ResStatus::TransactValue newVal_r, ResStatus::TransactByValue causer_r )
191
: _newVal( newVal_r )
192
, _causer( causer_r )
195
ResStatus::TransactValue _newVal;
196
ResStatus::TransactByValue _causer;
198
bool operator()( const PoolItem & pi ) const
200
bool ret = pi.status().setTransactValue( _newVal, _causer );
202
ERR << _newVal << _causer << " " << pi << endl;
207
struct StatusReset : public SetTransactValue
210
: SetTransactValue( ResStatus::KEEP_STATE, ResStatus::USER )
214
struct StatusInstall : public SetTransactValue
217
: SetTransactValue( ResStatus::TRANSACT, ResStatus::USER )
221
///////////////////////////////////////////////////////////////////
227
//zypp::base::LogControl::TmpLineWriter shutUp;
228
rres = getZYpp()->resolver()->resolvePool();
232
ERR << "resolve " << rres << endl;
233
getZYpp()->resolver()->problems();
236
MIL << "resolve " << rres << endl;
242
ZYppCommitPolicy pol;
244
pol.rpmInstFlags( pol.rpmInstFlags().setFlag( target::rpm::RPMINST_JUSTDB ) );
245
SEC << getZYpp()->commit( pol ) << endl;
251
getZYpp()->resolver()->createSolverTestcase( "./solverTestcase" );
254
///////////////////////////////////////////////////////////////////
256
struct DigestReceive : public callback::ReceiveReport<DigestReport>
263
virtual bool askUserToAcceptNoDigest( const zypp::Pathname &file )
268
virtual bool askUserToAccepUnknownDigest( const Pathname &file, const std::string &name )
273
virtual bool askUserToAcceptWrongDigest( const Pathname &file, const std::string &requested, const std::string &found )
275
USR << "fle " << PathInfo(file) << endl;
276
USR << "req " << requested << endl;
277
USR << "fnd " << found << endl;
282
struct KeyRingSignalsReceive : public callback::ReceiveReport<KeyRingSignals>
284
KeyRingSignalsReceive()
288
virtual void trustedKeyAdded( const PublicKey &/*key*/ )
292
virtual void trustedKeyRemoved( const PublicKey &/*key*/ )
298
///////////////////////////////////////////////////////////////////
300
struct MediaChangeReceive : public callback::ReceiveReport<media::MediaChangeReport>
302
virtual Action requestMedia( Url & source
304
, const std::string & label
306
, const std::string & description
307
, const std::vector<std::string> & devices
308
, unsigned int & dev_current )
310
SEC << __FUNCTION__ << endl
311
<< " " << source << endl
312
<< " " << mediumNr << endl
313
<< " " << label << endl
314
<< " " << error << endl
315
<< " " << description << endl
316
<< " " << devices << endl
317
<< " " << dev_current << endl;
322
///////////////////////////////////////////////////////////////////
327
bool isIn( const std::set<_Tp> & cont, const typename std::set<_Tp>::value_type & val )
328
{ return cont.find( val ) != cont.end(); }
330
///////////////////////////////////////////////////////////////////
332
void itCmp( const sat::Pool::SolvableIterator & l, const sat::Pool::SolvableIterator & r )
334
SEC << *l << " - " << *r << endl;
335
INT << "== " << (l==r) << endl;
336
INT << "!= " << (l!=r) << endl;
339
bool isTrue() { return true; }
340
bool isFalse() { return false; }
344
for ( int i = -3; i < 30; ++i )
346
DBG << i << '\t' << IdString( i ) << endl;
350
void ttt( const char * lhs, const char * rhs )
352
DBG << lhs << " <=> " << rhs << " --> " << ::strcmp( lhs, rhs ) << endl;
359
template <class _MemFun, class _Value>
363
HasValue( _MemFun fun_r, _Value val_r )
364
: _fun( fun_r ), _val( val_r )
367
bool operator()( const _Tp & obj_r ) const
368
{ return( _fun && (obj_r.*_fun)() == _val ); }
374
template <class _MemFun, class _Value>
375
HasValue<_MemFun, _Value> byValue( _MemFun fun_r, _Value val_r )
376
{ return HasValue<_MemFun, _Value>( fun_r, val_r ); }
382
struct _TestO { _TestO( const L & lhs ) : _lhs( lhs ) {} const L & _lhs; };
385
std::ostream & operator<<( std::ostream & str, const _TestO<L> & obj )
386
{ const L & lhs( obj._lhs); return str << (lhs?'_':'*') << (lhs.empty()?'e':'_') << "'" << lhs << "'"; }
389
_TestO<L> testO( const L & lhs )
390
{ return _TestO<L>( lhs ); }
392
template <class L, class R>
393
void testCMP( const L & lhs, const R & rhs )
395
MIL << "LHS " << testO(lhs) << endl;
396
MIL << "RHS " << rhs << endl;
398
#define OUTS(S) DBG << #S << ": " << (S) << endl
399
OUTS( lhs.compare(rhs) );
409
inline bool useRepo( RepoInfo & repo )
411
return repo.alias() == "matest";
412
return repo.enabled();
415
/******************************************************************
417
** FUNCTION NAME : main
418
** FUNCTION TYPE : int
420
int main( int argc, char * argv[] )
424
zypp::base::LogControl::instance().logToStdErr();
425
INT << "===[START]==========================================" << endl;
428
ResPool pool( ResPool::instance() );
429
sat::Pool satpool( sat::Pool::instance() );
433
Measure x( "INIT TARGET" );
436
zypp::base::LogControl::TmpLineWriter shutUp;
437
getZYpp()->initializeTarget( sysRoot );
439
getZYpp()->target()->load();
440
USR << getZYpp()->target()->targetDistribution() << endl;
441
USR << getZYpp()->target()->targetDistributionRelease() << endl;
447
RepoManager repoManager( makeRepoManager( sysRoot ) );
448
RepoInfoList repos = repoManager.knownRepositories();
451
for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
453
RepoInfo & nrepo( *it );
454
SEC << nrepo << endl;
456
if ( ! useRepo( nrepo ) )
459
if ( ! repoManager.isCached( nrepo ) || nrepo.type() == repo::RepoType::RPMPLAINDIR )
461
if ( repoManager.isCached( nrepo ) )
463
SEC << "cleanCache" << endl;
464
repoManager.cleanCache( nrepo );
466
SEC << "refreshMetadata" << endl;
467
//repoManager.refreshMetadata( nrepo );
468
SEC << "buildCache" << endl;
469
repoManager.buildCache( nrepo );
473
// create from cache:
475
Measure x( "CREATE FROM CACHE" );
476
for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
478
RepoInfo & nrepo( *it );
479
if ( ! useRepo( nrepo ) )
482
Measure x( "CREATE FROM CACHE "+nrepo.alias() );
485
repoManager.loadFromCache( nrepo );
487
catch ( const Exception & exp )
489
MIL << "Try to rebuild cache..." << endl;
490
SEC << "cleanCache" << endl;
491
repoManager.cleanCache( nrepo );
492
SEC << "buildCache" << endl;
493
repoManager.buildCache( nrepo );
494
SEC << "Create from cache" << endl;
495
repoManager.loadFromCache( nrepo );
498
USR << "pool: " << pool << endl;
503
dumpRange( USR, satpool.reposBegin(), satpool.reposEnd() );
504
USR << "pool: " << pool << endl;
506
///////////////////////////////////////////////////////////////////
510
Measure x( "Upgrade" );
511
getZYpp()->resolver()->doUpgrade();
514
///////////////////////////////////////////////////////////////////
515
///////////////////////////////////////////////////////////////////
516
// UNTh_(2)product:openSUSE-11.1.x86_64(openSUSE-dvd-11.1)
517
// U_Th_(583)yast2-ntp-client-2.17.1-1.26.noarch(openSUSE-dvd-11.1)
518
// U_Th_(1652)kernel-default-2.6.27-7.2.x86_64(openSUSE-dvd-11.1)
519
// U_Th_(2490)ntp-4.2.4p5-1.6.x86_64(openSUSE-dvd-11.1)
520
// UNTh_(2545)openSUSE-release-11.1-1.4.x86_64(openSUSE-dvd-11.1)
521
// USTh_(3462)pattern:base-11.1-46.1.x86_64(openSUSE-dvd-11.1)
522
// USTh_(3672)pattern:x11-11.1-46.1.x86_64(openSUSE-dvd-11.1)
523
// USTu_(3680)pattern:xfce-11.1-46.1.x86_64(openSUSE-dvd-11.1)
526
getZYpp()->resolver()->addRequire( Capability("product:openSUSE") );
527
getZYpp()->resolver()->addRequire( Capability("yast2-ntp-client") );
528
getZYpp()->resolver()->addRequire( Capability("kernel-default") );
529
getZYpp()->resolver()->addRequire( Capability("ntp") );
530
getZYpp()->resolver()->addRequire( Capability("openSUSE-release") );
531
getZYpp()->resolver()->addRequire( Capability("pattern:base") );
532
getZYpp()->resolver()->addRequire( Capability("pattern:x11") );
533
getZYpp()->resolver()->addRequire( Capability("pattern:xfce") );
537
vdumpPoolStats( USR << "Transacting:"<< endl,
538
make_filter_begin<resfilter::ByTransact>(pool),
539
make_filter_end<resfilter::ByTransact>(pool) ) << endl;
543
DiskUsageCounter ducounter( DiskUsageCounter::justRootPartition() );
544
for_( it, make_filter_begin<resfilter::ByTransact>(pool), make_filter_end<resfilter::ByTransact>(pool) )
547
ByteCount csze( ducounter.disk_usage( *it ).begin()->commitDiff() );
548
sze += (*it)->installSize();
550
DBG <<(*it)->installSize() << " vs. " << csze << " | " << ByteCount( dusze-sze ) << endl;
554
SEC << dusze << endl;
556
SEC << zypp::getZYpp()->diskUsage() << endl;
558
///////////////////////////////////////////////////////////////////
559
INT << "===[END]============================================" << endl << endl;
560
zypp::base::LogControl::instance().logNothing();
563
catch ( const Exception & exp )
565
INT << exp << endl << exp.historyAsString();