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"
51 using namespace zypp::functor;
52 using namespace zypp::ui;
53 using zypp::parser::TagParser;
55 ///////////////////////////////////////////////////////////////////
57 static const Pathname sysRoot( "/Local/ROOT" );
59 ///////////////////////////////////////////////////////////////////
60 ///////////////////////////////////////////////////////////////////
62 { /////////////////////////////////////////////////////////////////
64 bool queryInstalledEditionHelper( const std::string & name_r,
68 if ( ed_r == Edition::noedition )
70 if ( name_r == "kernel-default" && ed_r == Edition("2.6.22.5-10") )
72 if ( name_r == "update-test-affects-package-manager" && ed_r == Edition("1.1-6") )
79 ManagedFile repoProvidePackage( const PoolItem & pi )
81 ResPool _pool( getZYpp()->pool() );
82 repo::RepoMediaAccess _access;
84 // Redirect PackageProvider queries for installed editions
85 // (in case of patch/delta rpm processing) to rpmDb.
86 repo::PackageProviderPolicy packageProviderPolicy;
87 packageProviderPolicy.queryInstalledCB( queryInstalledEditionHelper );
89 Package::constPtr p = asKind<Package>(pi.resolvable());
91 // Build a repository list for repos
92 // contributing to the pool
93 repo::DeltaCandidates deltas( repo::makeDeltaCandidates( _pool.knownRepositoriesBegin(),
94 _pool.knownRepositoriesEnd() ) );
95 repo::PackageProvider pkgProvider( _access, p, deltas, packageProviderPolicy );
96 return pkgProvider.providePackage();
99 /////////////////////////////////////////////////////////////////
101 ///////////////////////////////////////////////////////////////////
102 ///////////////////////////////////////////////////////////////////
106 template <class _LIterator, class _RIterator, class _Function>
107 inline int invokeOnEach( _LIterator lbegin_r, _LIterator lend_r,
108 _RIterator rbegin_r, _RIterator rend_r,
112 for ( _LIterator lit = lbegin_r; lit != lend_r; ++lit )
114 for ( _RIterator rit = rbegin_r; rit != rend_r; ++rit )
117 if ( ! fnc_r( *lit, *rit ) )
126 void dbgDu( Selectable::Ptr sel )
128 if ( sel->installedPoolItem() )
130 DBG << "i: " << sel->installedPoolItem() << endl
131 << sel->installedPoolItem()->diskusage() << endl;
133 if ( sel->candidatePoolItem() )
135 DBG << "c: " << sel->candidatePoolItem() << endl
136 << sel->candidatePoolItem()->diskusage() << endl;
139 << getZYpp()->diskUsage() << endl;
142 ///////////////////////////////////////////////////////////////////
146 bool operator()( const PoolItem & obj_r )
148 if ( obj_r.status().isLocked() )
149 SEC << obj_r << endl;
151 // handle( asKind<Package>( obj_r ) );
152 // handle( asKind<Patch>( obj_r ) );
153 // handle( asKind<Pattern>( obj_r ) );
154 // handle( asKind<Product>( obj_r ) );
158 void handle( const Package_constPtr & p )
163 WAR << p->size() << endl;
164 MIL << p->diskusage() << endl;
167 void handle( const Patch_constPtr & p )
173 void handle( const Pattern_constPtr & p )
178 if ( p->vendor().empty() )
180 else if ( p->vendor() == "SUSE (assumed)" )
184 void handle( const Product_constPtr & p )
190 USR << p->vendor() << endl;
191 USR << p->type() << endl;
195 bool operator()( const _C & obj_r )
201 ///////////////////////////////////////////////////////////////////
202 struct SetTransactValue
204 SetTransactValue( ResStatus::TransactValue newVal_r, ResStatus::TransactByValue causer_r )
205 : _newVal( newVal_r )
206 , _causer( causer_r )
209 ResStatus::TransactValue _newVal;
210 ResStatus::TransactByValue _causer;
212 bool operator()( const PoolItem & pi ) const
214 bool ret = pi.status().setTransactValue( _newVal, _causer );
216 ERR << _newVal << _causer << " " << pi << endl;
221 struct StatusReset : public SetTransactValue
224 : SetTransactValue( ResStatus::KEEP_STATE, ResStatus::USER )
228 struct StatusInstall : public SetTransactValue
231 : SetTransactValue( ResStatus::TRANSACT, ResStatus::USER )
235 inline bool g( const NameKindProxy & nkp, Arch arch = Arch() )
237 if ( nkp.availableEmpty() )
239 ERR << "No Item to select: " << nkp << endl;
241 ZYPP_THROW( Exception("No Item to select") );
244 if ( arch != Arch() )
246 typeof( nkp.availableBegin() ) it = nkp.availableBegin();
247 for ( ; it != nkp.availableEnd(); ++it )
249 if ( (*it)->arch() == arch )
250 return (*it).status().setTransact( true, ResStatus::USER );
254 return nkp.availableBegin()->status().setTransact( true, ResStatus::USER );
257 ///////////////////////////////////////////////////////////////////
259 bool solve( bool establish = false )
265 zypp::base::LogControl::TmpLineWriter shutUp;
266 eres = getZYpp()->resolver()->establishPool();
270 ERR << "establish " << eres << endl;
273 MIL << "establish " << eres << endl;
278 zypp::base::LogControl::TmpLineWriter shutUp;
279 rres = getZYpp()->resolver()->resolvePool();
283 ERR << "resolve " << rres << endl;
286 MIL << "resolve " << rres << endl;
292 SEC << getZYpp()->commit( ZYppCommitPolicy() ) << endl;
296 ///////////////////////////////////////////////////////////////////
298 struct ConvertDbReceive : public callback::ReceiveReport<target::ScriptResolvableReport>
300 virtual void start( const Resolvable::constPtr & script_r,
301 const Pathname & path_r,
304 SEC << __FUNCTION__ << endl
305 << " " << script_r << endl
306 << " " << path_r << endl
307 << " " << task_r << endl;
310 virtual bool progress( Notify notify_r, const std::string & text_r )
312 SEC << __FUNCTION__ << endl
313 << " " << notify_r << endl
314 << " " << text_r << endl;
318 virtual void problem( const std::string & description_r )
320 SEC << __FUNCTION__ << endl
321 << " " << description_r << endl;
324 virtual void finish()
326 SEC << __FUNCTION__ << endl;
330 ///////////////////////////////////////////////////////////////////
332 struct DigestReceive : public callback::ReceiveReport<DigestReport>
339 virtual bool askUserToAcceptNoDigest( const zypp::Pathname &file )
344 virtual bool askUserToAccepUnknownDigest( const Pathname &file, const std::string &name )
349 virtual bool askUserToAcceptWrongDigest( const Pathname &file, const std::string &requested, const std::string &found )
351 USR << "fle " << PathInfo(file) << endl;
352 USR << "req " << requested << endl;
353 USR << "fnd " << found << endl;
358 struct KeyRingSignalsReceive : public callback::ReceiveReport<KeyRingSignals>
360 KeyRingSignalsReceive()
364 virtual void trustedKeyAdded( const PublicKey &/*key*/ )
368 virtual void trustedKeyRemoved( const PublicKey &/*key*/ )
374 ///////////////////////////////////////////////////////////////////
376 struct MediaChangeReceive : public callback::ReceiveReport<media::MediaChangeReport>
378 virtual Action requestMedia( Url & source
381 , const std::string & description )
383 SEC << __FUNCTION__ << endl
384 << " " << source << endl
385 << " " << mediumNr << endl
386 << " " << error << endl
387 << " " << description << endl;
392 ///////////////////////////////////////////////////////////////////
397 bool isIn( const std::set<_Tp> & cont, const typename std::set<_Tp>::value_type & val )
398 { return cont.find( val ) != cont.end(); }
400 ///////////////////////////////////////////////////////////////////
402 void itCmp( const sat::Pool::SolvableIterator & l, const sat::Pool::SolvableIterator & r )
404 SEC << *l << " - " << *r << endl;
405 INT << "== " << (l==r) << endl;
406 INT << "!= " << (l!=r) << endl;
409 bool isTrue() { return true; }
410 bool isFalse() { return false; }
413 /******************************************************************
415 ** FUNCTION NAME : main
416 ** FUNCTION TYPE : int
418 int main( int argc, char * argv[] )
420 //zypp::base::LogControl::instance().logfile( "log.restrict" );
421 INT << "===[START]==========================================" << endl;
424 sat::Pool satpool( sat::Pool::instance() );
427 ///////////////////////////////////////////////////////////////////
428 INT << "===[END]============================================" << endl << endl;
429 zypp::base::LogControl::instance().logNothing();
433 setenv( "ZYPP_CONF", (sysRoot/"zypp.conf").c_str(), 1 );
435 ResPool pool( getZYpp()->pool() );
436 USR << "pool: " << pool << endl;
439 RepoManager repoManager( makeRepoManager( sysRoot ) );
440 RepoInfoList repos = repoManager.knownRepositories();
441 // SEC << "/Local/ROOT " << repos << endl;
444 for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
446 RepoInfo & nrepo( *it );
447 SEC << nrepo << endl;
449 if ( ! nrepo.enabled() )
452 if ( ! repoManager.isCached( nrepo ) || 0 )
454 if ( repoManager.isCached( nrepo ) )
456 SEC << "cleanCache" << endl;
457 repoManager.cleanCache( nrepo );
459 SEC << "refreshMetadata" << endl;
460 repoManager.refreshMetadata( nrepo, RepoManager::RefreshForced );
461 SEC << "buildCache" << endl;
462 repoManager.buildCache( nrepo );
466 // create from cache:
467 std::list<Repository> repositories;
470 Measure x( "CREATE FROM CACHE" );
471 for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
473 RepoInfo & nrepo( *it );
474 if ( ! nrepo.enabled() )
477 Measure x( "CREATE FROM CACHE "+nrepo.alias() );
478 Repository nrep( repoManager.createFromCache( nrepo ) );
479 const zypp::ResStore & store( nrep.resolvables() );
480 repositories.push_back( nrep );
486 Measure x( "LOAD POOL" );
487 for_( it, repositories.begin(), repositories.end() )
489 Measure x( "LOAD POOL "+(*it).info().alias() );
490 const zypp::ResStore & store( (*it).resolvables() );
491 getZYpp()->addResolvables( store );
498 Measure x( "INIT TARGET" );
500 zypp::base::LogControl::TmpLineWriter shutUp;
501 getZYpp()->initTarget( sysRoot );
502 //getZYpp()->initTarget( "/" );
504 dumpPoolStats( SEC << "TargetStore: " << endl,
505 getZYpp()->target()->resolvables().begin(),
506 getZYpp()->target()->resolvables().end() ) << endl;
509 USR << "pool: " << pool << endl;
512 //std::for_each( pool.begin(), pool.end(), Xprint() );
514 //sat::detail::PoolImpl satpool;
516 //MIL << satpool << endl;
518 ///////////////////////////////////////////////////////////////////
519 INT << "===[END]============================================" << endl << endl;
520 zypp::base::LogControl::instance().logNothing();