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(); }
445 Xverscmp( ostream * outs_r = 0 )
449 bool operator()( const Edition & lhs, const Edition & rhs )
453 int res = lhs.compare( rhs );
454 (*_outs) << lhs << " <> " << rhs << " = " << res << endl;
462 /******************************************************************
464 ** FUNCTION NAME : main
465 ** FUNCTION TYPE : int
467 int main( int argc, char * argv[] )
469 //zypp::base::LogControl::instance().logfile( "log.restrict" );
470 INT << "===[START]==========================================" << endl;
472 setenv( "ZYPP_CONF", (sysRoot/"zypp.conf").c_str(), 1 );
474 RepoManager repoManager( makeRepoManager( sysRoot ) );
475 RepoInfoList repos = repoManager.knownRepositories();
476 // SEC << "/Local/ROOT " << repos << endl;
478 for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
480 RepoInfo & nrepo( *it );
481 SEC << nrepo << endl;
483 if ( ! nrepo.enabled() )
486 if ( ! repoManager.isCached( nrepo ) || 0 )
488 if ( repoManager.isCached( nrepo ) )
490 SEC << "cleanCache" << endl;
491 repoManager.cleanCache( nrepo );
493 SEC << "refreshMetadata" << endl;
494 repoManager.refreshMetadata( nrepo, RepoManager::RefreshForced );
495 SEC << "buildCache" << endl;
496 repoManager.buildCache( nrepo );
499 SEC << "createFromCache" << endl;
500 Repository nrep( repoManager.createFromCache( nrepo ) );
501 const zypp::ResStore & store( nrep.resolvables() );
502 dumpPoolStats( SEC << "Store: " << endl, store.begin(), store.end() ) << endl;
503 getZYpp()->addResolvables( store );
509 zypp::base::LogControl::TmpLineWriter shutUp;
510 getZYpp()->initTarget( sysRoot );
511 //getZYpp()->initTarget( "/" );
513 SEC << "Added target " << endl;
514 dumpPoolStats( SEC << "Store: " << endl,
515 getZYpp()->target()->resolvables().begin(),
516 getZYpp()->target()->resolvables().end() ) << endl;
519 ResPool pool( getZYpp()->pool() );
520 USR << "pool: " << pool << endl;
523 Measure x( "Cross pool edition compare" );
524 //ofstream out( "verscmp.new" );
526 std::set<Edition> editions;
527 for_( it, pool.begin(), pool.end() )
529 editions.insert( (*it)->edition() );
531 SEC << "Num Editions " << editions.size() << endl;
532 for ( unsigned i = 5; i; --i )
534 Measure x( "pass " );
535 invokeOnEach( editions.begin(), editions.end(),
536 editions.begin(), editions.end(),
541 //std::for_each( pool.begin(), pool.end(), Xprint() );
543 ///////////////////////////////////////////////////////////////////
544 INT << "===[END]============================================" << endl << endl;
545 zypp::base::LogControl::instance().logNothing();