3 #include <zypp/base/PtrTypes.h>
4 #include <zypp/base/Exception.h>
5 #include <zypp/base/LogTools.h>
6 #include <zypp/base/ProvideNumericId.h>
7 #include <zypp/AutoDispose.h>
9 #include "zypp/ZYppFactory.h"
10 #include "zypp/ResPoolProxy.h"
11 #include <zypp/CapMatchHelper.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/Package.h"
19 #include "zypp/Pattern.h"
20 #include "zypp/Language.h"
21 #include "zypp/Digest.h"
22 #include "zypp/PackageKeyword.h"
23 #include "zypp/ManagedFile.h"
24 #include "zypp/NameKindProxy.h"
25 #include "zypp/pool/GetResolvablesToInsDel.h"
27 #include "zypp/parser/TagParser.h"
28 #include "zypp/parser/susetags/PackagesFileReader.h"
29 #include "zypp/parser/susetags/PackagesLangFileReader.h"
30 #include "zypp/parser/susetags/PatternFileReader.h"
31 #include "zypp/parser/susetags/ContentFileReader.h"
32 #include "zypp/parser/susetags/RepoIndex.h"
33 #include "zypp/parser/susetags/RepoParser.h"
34 #include "zypp/cache/CacheStore.h"
35 #include "zypp/RepoManager.h"
36 #include "zypp/RepoInfo.h"
38 #include "zypp/repo/PackageProvider.h"
40 #include "zypp/ui/PatchContents.h"
41 #include "zypp/ResPoolProxy.h"
45 using namespace zypp::functor;
46 using namespace zypp::ui;
47 using zypp::parser::TagParser;
49 ///////////////////////////////////////////////////////////////////
51 static const Pathname sysRoot( "/Local/ROOT" );
53 ///////////////////////////////////////////////////////////////////
54 ///////////////////////////////////////////////////////////////////
56 { /////////////////////////////////////////////////////////////////
58 bool queryInstalledEditionHelper( const std::string & name_r,
62 if ( ed_r == Edition::noedition )
64 if ( name_r == "kernel-default" && ed_r == Edition("2.6.22.5-10") )
66 if ( name_r == "update-test-affects-package-manager" && ed_r == Edition("1.1-6") )
73 ManagedFile repoProvidePackage( const PoolItem & pi )
75 ResPool _pool( getZYpp()->pool() );
76 repo::RepoMediaAccess _access;
78 // Redirect PackageProvider queries for installed editions
79 // (in case of patch/delta rpm processing) to rpmDb.
80 repo::PackageProviderPolicy packageProviderPolicy;
81 packageProviderPolicy.queryInstalledCB( queryInstalledEditionHelper );
83 Package::constPtr p = asKind<Package>(pi.resolvable());
85 // Build a repository list for repos
86 // contributing to the pool
87 repo::DeltaCandidates deltas( repo::makeDeltaCandidates( _pool.knownRepositoriesBegin(),
88 _pool.knownRepositoriesEnd() ) );
89 repo::PackageProvider pkgProvider( _access, p, deltas, packageProviderPolicy );
90 return pkgProvider.providePackage();
93 /////////////////////////////////////////////////////////////////
95 ///////////////////////////////////////////////////////////////////
96 ///////////////////////////////////////////////////////////////////
100 template <class _LIterator, class _RIterator, class _Function>
101 inline int invokeOnEach( _LIterator lbegin_r, _LIterator lend_r,
102 _RIterator rbegin_r, _RIterator rend_r,
106 for ( _LIterator lit = lbegin_r; lit != lend_r; ++lit )
108 for ( _RIterator rit = rbegin_r; rit != rend_r; ++rit )
111 if ( ! fnc_r( *lit, *rit ) )
120 Selectable::Ptr getSel( const std::string & name_r )
122 ResPoolProxy uipool( getZYpp()->poolProxy() );
123 for_(it, uipool.byKindBegin<_Res>(), uipool.byKindEnd<_Res>() )
125 if ( (*it)->name() == name_r )
132 PoolItem getPi( const std::string & name_r, const Edition & ed_r, const Arch & arch_r )
135 ResPool pool( getZYpp()->pool() );
136 for_(it, pool.byNameBegin(name_r), pool.byNameEnd(name_r) )
138 if ( !ret && isKind<_Res>( (*it).resolvable() )
139 && ( ed_r == Edition() || ed_r == (*it)->edition() )
140 && ( arch_r == Arch() || arch_r == (*it)->arch() ) )
143 MIL << " ->" << *it << endl;
147 DBG << " ?" << *it << endl;
153 PoolItem getPi( const std::string & name_r )
155 return getPi<_Res>( name_r, Edition(), Arch() );
158 PoolItem getPi( const std::string & name_r, const Edition & ed_r )
160 return getPi<_Res>( name_r, ed_r, Arch() );
163 PoolItem getPi( const std::string & name_r, const Arch & arch_r )
165 return getPi<_Res>( name_r, Edition(), arch_r );
168 void dbgDu( Selectable::Ptr sel )
170 if ( sel->installedPoolItem() )
172 DBG << "i: " << sel->installedPoolItem() << endl
173 << sel->installedPoolItem()->diskusage() << endl;
175 if ( sel->candidatePoolItem() )
177 DBG << "c: " << sel->candidatePoolItem() << endl
178 << sel->candidatePoolItem()->diskusage() << endl;
181 << getZYpp()->diskUsage() << endl;
184 ///////////////////////////////////////////////////////////////////
188 bool operator()( const PoolItem & obj_r )
190 if ( obj_r.status().isLocked() )
191 SEC << obj_r << endl;
193 // handle( asKind<Package>( obj_r ) );
194 // handle( asKind<Patch>( obj_r ) );
195 // handle( asKind<Pattern>( obj_r ) );
196 // handle( asKind<Product>( obj_r ) );
200 void handle( const Package_constPtr & p )
205 WAR << p->size() << endl;
206 MIL << p->diskusage() << endl;
209 void handle( const Patch_constPtr & p )
215 void handle( const Pattern_constPtr & p )
220 if ( p->vendor().empty() )
222 else if ( p->vendor() == "SUSE (assumed)" )
226 void handle( const Product_constPtr & p )
232 USR << p->vendor() << endl;
233 USR << p->type() << endl;
237 bool operator()( const _C & obj_r )
243 ///////////////////////////////////////////////////////////////////
244 struct SetTransactValue
246 SetTransactValue( ResStatus::TransactValue newVal_r, ResStatus::TransactByValue causer_r )
247 : _newVal( newVal_r )
248 , _causer( causer_r )
251 ResStatus::TransactValue _newVal;
252 ResStatus::TransactByValue _causer;
254 bool operator()( const PoolItem & pi ) const
256 bool ret = pi.status().setTransactValue( _newVal, _causer );
258 ERR << _newVal << _causer << " " << pi << endl;
263 struct StatusReset : public SetTransactValue
266 : SetTransactValue( ResStatus::KEEP_STATE, ResStatus::USER )
270 struct StatusInstall : public SetTransactValue
273 : SetTransactValue( ResStatus::TRANSACT, ResStatus::USER )
277 inline bool g( const NameKindProxy & nkp, Arch arch = Arch() )
279 if ( nkp.availableEmpty() )
281 ERR << "No Item to select: " << nkp << endl;
283 ZYPP_THROW( Exception("No Item to select") );
286 if ( arch != Arch() )
288 typeof( nkp.availableBegin() ) it = nkp.availableBegin();
289 for ( ; it != nkp.availableEnd(); ++it )
291 if ( (*it)->arch() == arch )
292 return (*it).status().setTransact( true, ResStatus::USER );
296 return nkp.availableBegin()->status().setTransact( true, ResStatus::USER );
299 ///////////////////////////////////////////////////////////////////
301 bool solve( bool establish = false )
307 zypp::base::LogControl::TmpLineWriter shutUp;
308 eres = getZYpp()->resolver()->establishPool();
312 ERR << "establish " << eres << endl;
315 MIL << "establish " << eres << endl;
320 zypp::base::LogControl::TmpLineWriter shutUp;
321 rres = getZYpp()->resolver()->resolvePool();
325 ERR << "resolve " << rres << endl;
328 MIL << "resolve " << rres << endl;
334 SEC << getZYpp()->commit( ZYppCommitPolicy() ) << endl;
338 ///////////////////////////////////////////////////////////////////
340 struct ConvertDbReceive : public callback::ReceiveReport<target::ScriptResolvableReport>
342 virtual void start( const Resolvable::constPtr & script_r,
343 const Pathname & path_r,
346 SEC << __FUNCTION__ << endl
347 << " " << script_r << endl
348 << " " << path_r << endl
349 << " " << task_r << endl;
352 virtual bool progress( Notify notify_r, const std::string & text_r )
354 SEC << __FUNCTION__ << endl
355 << " " << notify_r << endl
356 << " " << text_r << endl;
360 virtual void problem( const std::string & description_r )
362 SEC << __FUNCTION__ << endl
363 << " " << description_r << endl;
366 virtual void finish()
368 SEC << __FUNCTION__ << endl;
372 ///////////////////////////////////////////////////////////////////
374 struct DigestReceive : public callback::ReceiveReport<DigestReport>
381 virtual bool askUserToAcceptNoDigest( const zypp::Pathname &file )
386 virtual bool askUserToAccepUnknownDigest( const Pathname &file, const std::string &name )
391 virtual bool askUserToAcceptWrongDigest( const Pathname &file, const std::string &requested, const std::string &found )
393 USR << "fle " << PathInfo(file) << endl;
394 USR << "req " << requested << endl;
395 USR << "fnd " << found << endl;
400 struct KeyRingSignalsReceive : public callback::ReceiveReport<KeyRingSignals>
402 KeyRingSignalsReceive()
406 virtual void trustedKeyAdded( const PublicKey &/*key*/ )
410 virtual void trustedKeyRemoved( const PublicKey &/*key*/ )
416 ///////////////////////////////////////////////////////////////////
418 struct MediaChangeReceive : public callback::ReceiveReport<media::MediaChangeReport>
420 virtual Action requestMedia( Url & source
423 , const std::string & description )
425 SEC << __FUNCTION__ << endl
426 << " " << source << endl
427 << " " << mediumNr << endl
428 << " " << error << endl
429 << " " << description << endl;
434 ///////////////////////////////////////////////////////////////////
439 bool isIn( const std::set<_Tp> & cont, const typename std::set<_Tp>::value_type & val )
440 { return cont.find( val ) != cont.end(); }
443 /******************************************************************
445 ** FUNCTION NAME : main
446 ** FUNCTION TYPE : int
448 int main( int argc, char * argv[] )
450 //zypp::base::LogControl::instance().logfile( "log.restrict" );
451 INT << "===[START]==========================================" << endl;
452 zypp::base::LogControl::instance().logNothing();
454 setenv( "ZYPP_CONF", (sysRoot/"zypp.conf").c_str(), 1 );
456 RepoManager repoManager( makeRepoManager( sysRoot ) );
457 RepoInfoList repos = repoManager.knownRepositories();
458 // SEC << "/Local/ROOT " << repos << endl;
461 for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
463 RepoInfo & nrepo( *it );
464 SEC << nrepo << endl;
466 if ( ! nrepo.enabled() )
469 if ( ! repoManager.isCached( nrepo ) || 0 )
471 if ( repoManager.isCached( nrepo ) )
473 SEC << "cleanCache" << endl;
474 repoManager.cleanCache( nrepo );
476 //SEC << "refreshMetadata" << endl;
477 //repoManager.refreshMetadata( nrepo, RepoManager::RefreshForced );
478 SEC << "buildCache" << endl;
479 repoManager.buildCache( nrepo );
483 // create from cache:
484 std::list<Repository> repositories;
487 Measure x( "CREATE FROM CACHE" );
488 for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
490 RepoInfo & nrepo( *it );
491 if ( ! nrepo.enabled() )
494 Measure x( "CREATE FROM CACHE "+nrepo.alias() );
495 Repository nrep( repoManager.createFromCache( nrepo ) );
496 const zypp::ResStore & store( nrep.resolvables() );
497 repositories.push_back( nrep );
503 Measure x( "LOAD POOL" );
504 for_( it, repositories.begin(), repositories.end() )
506 Measure x( "LOAD POOL "+(*it).info().alias() );
507 const zypp::ResStore & store( (*it).resolvables() );
508 getZYpp()->addResolvables( store );
515 Measure x( "INIT TARGET" );
517 zypp::base::LogControl::TmpLineWriter shutUp;
518 getZYpp()->initTarget( sysRoot );
519 //getZYpp()->initTarget( "/" );
521 dumpPoolStats( SEC << "TargetStore: " << endl,
522 getZYpp()->target()->resolvables().begin(),
523 getZYpp()->target()->resolvables().end() ) << endl;
526 ResPool pool( getZYpp()->pool() );
527 USR << "pool: " << pool << endl;
532 //std::for_each( pool.begin(), pool.end(), Xprint() );
534 ///////////////////////////////////////////////////////////////////
535 INT << "===[END]============================================" << endl << endl;
536 zypp::base::LogControl::instance().logNothing();