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/ProvideNumericId.h>
8 #include <zypp/AutoDispose.h>
10 #include "zypp/ZYppFactory.h"
11 #include "zypp/ResPoolProxy.h"
12 #include <zypp/CapMatchHelper.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/Package.h"
20 #include "zypp/Pattern.h"
21 #include "zypp/Language.h"
22 #include "zypp/Digest.h"
23 #include "zypp/PackageKeyword.h"
24 #include "zypp/ManagedFile.h"
25 #include "zypp/NameKindProxy.h"
26 #include "zypp/pool/GetResolvablesToInsDel.h"
28 #include "zypp/parser/TagParser.h"
29 #include "zypp/parser/susetags/PackagesFileReader.h"
30 #include "zypp/parser/susetags/PackagesLangFileReader.h"
31 #include "zypp/parser/susetags/PatternFileReader.h"
32 #include "zypp/parser/susetags/ContentFileReader.h"
33 #include "zypp/parser/susetags/RepoIndex.h"
34 #include "zypp/parser/susetags/RepoParser.h"
35 #include "zypp/cache/CacheStore.h"
36 #include "zypp/RepoManager.h"
37 #include "zypp/RepoInfo.h"
39 #include "zypp/repo/PackageProvider.h"
41 #include "zypp/ui/PatchContents.h"
42 #include "zypp/ResPoolProxy.h"
44 #include "zypp/sat/Pool.h"
45 #include "zypp/sat/Repo.h"
46 #include "zypp/sat/Solvable.h"
47 #include "zypp/sat/detail/PoolImpl.h"
49 #include <boost/mpl/int.hpp>
53 using namespace zypp::functor;
54 using namespace zypp::ui;
55 using zypp::parser::TagParser;
57 ///////////////////////////////////////////////////////////////////
59 static const Pathname sysRoot( "/Local/ROOT" );
61 ///////////////////////////////////////////////////////////////////
62 ///////////////////////////////////////////////////////////////////
64 { /////////////////////////////////////////////////////////////////
66 bool queryInstalledEditionHelper( const std::string & name_r,
70 if ( ed_r == Edition::noedition )
72 if ( name_r == "kernel-default" && ed_r == Edition("2.6.22.5-10") )
74 if ( name_r == "update-test-affects-package-manager" && ed_r == Edition("1.1-6") )
81 ManagedFile repoProvidePackage( const PoolItem & pi )
83 ResPool _pool( getZYpp()->pool() );
84 repo::RepoMediaAccess _access;
86 // Redirect PackageProvider queries for installed editions
87 // (in case of patch/delta rpm processing) to rpmDb.
88 repo::PackageProviderPolicy packageProviderPolicy;
89 packageProviderPolicy.queryInstalledCB( queryInstalledEditionHelper );
91 Package::constPtr p = asKind<Package>(pi.resolvable());
93 // Build a repository list for repos
94 // contributing to the pool
95 repo::DeltaCandidates deltas( repo::makeDeltaCandidates( _pool.knownRepositoriesBegin(),
96 _pool.knownRepositoriesEnd() ) );
97 repo::PackageProvider pkgProvider( _access, p, deltas, packageProviderPolicy );
98 return pkgProvider.providePackage();
101 /////////////////////////////////////////////////////////////////
103 ///////////////////////////////////////////////////////////////////
104 ///////////////////////////////////////////////////////////////////
108 template <class _LIterator, class _RIterator, class _Function>
109 inline int invokeOnEach( _LIterator lbegin_r, _LIterator lend_r,
110 _RIterator rbegin_r, _RIterator rend_r,
114 for ( _LIterator lit = lbegin_r; lit != lend_r; ++lit )
116 for ( _RIterator rit = rbegin_r; rit != rend_r; ++rit )
119 if ( ! fnc_r( *lit, *rit ) )
128 void dbgDu( Selectable::Ptr sel )
130 if ( sel->installedPoolItem() )
132 DBG << "i: " << sel->installedPoolItem() << endl
133 << sel->installedPoolItem()->diskusage() << endl;
135 if ( sel->candidatePoolItem() )
137 DBG << "c: " << sel->candidatePoolItem() << endl
138 << sel->candidatePoolItem()->diskusage() << endl;
141 << getZYpp()->diskUsage() << endl;
144 ///////////////////////////////////////////////////////////////////
148 bool operator()( const PoolItem & obj_r )
150 if ( obj_r.status().isLocked() )
151 SEC << obj_r << endl;
153 // handle( asKind<Package>( obj_r ) );
154 // handle( asKind<Patch>( obj_r ) );
155 // handle( asKind<Pattern>( obj_r ) );
156 // handle( asKind<Product>( obj_r ) );
160 void handle( const Package_constPtr & p )
165 WAR << p->size() << endl;
166 MIL << p->diskusage() << endl;
169 void handle( const Patch_constPtr & p )
175 void handle( const Pattern_constPtr & p )
180 if ( p->vendor().empty() )
182 else if ( p->vendor() == "SUSE (assumed)" )
186 void handle( const Product_constPtr & p )
192 USR << p->vendor() << endl;
193 USR << p->type() << endl;
197 bool operator()( const _C & obj_r )
203 ///////////////////////////////////////////////////////////////////
204 struct SetTransactValue
206 SetTransactValue( ResStatus::TransactValue newVal_r, ResStatus::TransactByValue causer_r )
207 : _newVal( newVal_r )
208 , _causer( causer_r )
211 ResStatus::TransactValue _newVal;
212 ResStatus::TransactByValue _causer;
214 bool operator()( const PoolItem & pi ) const
216 bool ret = pi.status().setTransactValue( _newVal, _causer );
218 ERR << _newVal << _causer << " " << pi << endl;
223 struct StatusReset : public SetTransactValue
226 : SetTransactValue( ResStatus::KEEP_STATE, ResStatus::USER )
230 struct StatusInstall : public SetTransactValue
233 : SetTransactValue( ResStatus::TRANSACT, ResStatus::USER )
237 inline bool g( const NameKindProxy & nkp, Arch arch = Arch() )
239 if ( nkp.availableEmpty() )
241 ERR << "No Item to select: " << nkp << endl;
243 ZYPP_THROW( Exception("No Item to select") );
246 if ( arch != Arch() )
248 typeof( nkp.availableBegin() ) it = nkp.availableBegin();
249 for ( ; it != nkp.availableEnd(); ++it )
251 if ( (*it)->arch() == arch )
252 return (*it).status().setTransact( true, ResStatus::USER );
256 return nkp.availableBegin()->status().setTransact( true, ResStatus::USER );
259 ///////////////////////////////////////////////////////////////////
261 bool solve( bool establish = false )
267 zypp::base::LogControl::TmpLineWriter shutUp;
268 eres = getZYpp()->resolver()->establishPool();
272 ERR << "establish " << eres << endl;
275 MIL << "establish " << eres << endl;
280 zypp::base::LogControl::TmpLineWriter shutUp;
281 rres = getZYpp()->resolver()->resolvePool();
285 ERR << "resolve " << rres << endl;
288 MIL << "resolve " << rres << endl;
294 SEC << getZYpp()->commit( ZYppCommitPolicy() ) << endl;
298 ///////////////////////////////////////////////////////////////////
300 struct ConvertDbReceive : public callback::ReceiveReport<target::ScriptResolvableReport>
302 virtual void start( const Resolvable::constPtr & script_r,
303 const Pathname & path_r,
306 SEC << __FUNCTION__ << endl
307 << " " << script_r << endl
308 << " " << path_r << endl
309 << " " << task_r << endl;
312 virtual bool progress( Notify notify_r, const std::string & text_r )
314 SEC << __FUNCTION__ << endl
315 << " " << notify_r << endl
316 << " " << text_r << endl;
320 virtual void problem( const std::string & description_r )
322 SEC << __FUNCTION__ << endl
323 << " " << description_r << endl;
326 virtual void finish()
328 SEC << __FUNCTION__ << endl;
332 ///////////////////////////////////////////////////////////////////
334 struct DigestReceive : public callback::ReceiveReport<DigestReport>
341 virtual bool askUserToAcceptNoDigest( const zypp::Pathname &file )
346 virtual bool askUserToAccepUnknownDigest( const Pathname &file, const std::string &name )
351 virtual bool askUserToAcceptWrongDigest( const Pathname &file, const std::string &requested, const std::string &found )
353 USR << "fle " << PathInfo(file) << endl;
354 USR << "req " << requested << endl;
355 USR << "fnd " << found << endl;
360 struct KeyRingSignalsReceive : public callback::ReceiveReport<KeyRingSignals>
362 KeyRingSignalsReceive()
366 virtual void trustedKeyAdded( const PublicKey &/*key*/ )
370 virtual void trustedKeyRemoved( const PublicKey &/*key*/ )
376 ///////////////////////////////////////////////////////////////////
378 struct MediaChangeReceive : public callback::ReceiveReport<media::MediaChangeReport>
380 virtual Action requestMedia( Url & source
383 , const std::string & description )
385 SEC << __FUNCTION__ << endl
386 << " " << source << endl
387 << " " << mediumNr << endl
388 << " " << error << endl
389 << " " << description << endl;
394 ///////////////////////////////////////////////////////////////////
399 bool isIn( const std::set<_Tp> & cont, const typename std::set<_Tp>::value_type & val )
400 { return cont.find( val ) != cont.end(); }
402 ///////////////////////////////////////////////////////////////////
404 void itCmp( const sat::Pool::SolvableIterator & l, const sat::Pool::SolvableIterator & r )
406 SEC << *l << " - " << *r << endl;
407 INT << "== " << (l==r) << endl;
408 INT << "!= " << (l!=r) << endl;
411 bool isTrue() { return true; }
412 bool isFalse() { return false; }
416 for ( unsigned i = 0; i < 30; ++i )
418 DBG << i << '\t' << sat::IdStr( i ) << endl;
422 /******************************************************************
424 ** FUNCTION NAME : main
425 ** FUNCTION TYPE : int
427 int main( int argc, char * argv[] )
429 //zypp::base::LogControl::instance().logfile( "log.restrict" );
430 INT << "===[START]==========================================" << endl;
433 sat::Pool satpool( sat::Pool::instance() );
436 //sat::Repo r( satpool.addRepoSolv( "sl10.1-beta7-packages.solv" ) );
437 sat::Repo s( satpool.addRepoSolv( "sl10.1-beta7-selections.solv" ) );
439 std::for_each( satpool.solvablesBegin(), satpool.solvablesEnd(), Print() );
441 ///////////////////////////////////////////////////////////////////
442 INT << "===[END]============================================" << endl << endl;
443 zypp::base::LogControl::instance().logNothing();
447 setenv( "ZYPP_CONF", (sysRoot/"zypp.conf").c_str(), 1 );
449 ResPool pool( getZYpp()->pool() );
450 USR << "pool: " << pool << endl;
453 RepoManager repoManager( makeRepoManager( sysRoot ) );
454 RepoInfoList repos = repoManager.knownRepositories();
455 // SEC << "/Local/ROOT " << repos << endl;
458 for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
460 RepoInfo & nrepo( *it );
461 SEC << nrepo << endl;
463 if ( ! nrepo.enabled() )
466 if ( ! repoManager.isCached( nrepo ) || 0 )
468 if ( repoManager.isCached( nrepo ) )
470 SEC << "cleanCache" << endl;
471 repoManager.cleanCache( nrepo );
473 SEC << "refreshMetadata" << endl;
474 repoManager.refreshMetadata( nrepo, RepoManager::RefreshForced );
475 SEC << "buildCache" << endl;
476 repoManager.buildCache( nrepo );
480 // create from cache:
481 std::list<Repository> repositories;
484 Measure x( "CREATE FROM CACHE" );
485 for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
487 RepoInfo & nrepo( *it );
488 if ( ! nrepo.enabled() )
491 Measure x( "CREATE FROM CACHE "+nrepo.alias() );
492 Repository nrep( repoManager.createFromCache( nrepo ) );
493 const zypp::ResStore & store( nrep.resolvables() );
494 repositories.push_back( nrep );
500 Measure x( "LOAD POOL" );
501 for_( it, repositories.begin(), repositories.end() )
503 Measure x( "LOAD POOL "+(*it).info().alias() );
504 const zypp::ResStore & store( (*it).resolvables() );
505 getZYpp()->addResolvables( store );
512 Measure x( "INIT TARGET" );
514 zypp::base::LogControl::TmpLineWriter shutUp;
515 getZYpp()->initTarget( sysRoot );
516 //getZYpp()->initTarget( "/" );
518 dumpPoolStats( SEC << "TargetStore: " << endl,
519 getZYpp()->target()->resolvables().begin(),
520 getZYpp()->target()->resolvables().end() ) << endl;
523 USR << "pool: " << pool << endl;
526 //std::for_each( pool.begin(), pool.end(), Xprint() );
528 //sat::detail::PoolImpl satpool;
530 //MIL << satpool << endl;
532 ///////////////////////////////////////////////////////////////////
533 INT << "===[END]============================================" << endl << endl;
534 zypp::base::LogControl::instance().logNothing();