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() );
426 //sat::Repo r( satpool.addRepoSolv( "sl10.1-beta7-packages.solv" ) );
427 sat::Repo s( satpool.addRepoSolv( "sl10.1-beta7-selections.solv" ) );
428 MIL << satpool << endl;
429 std::for_each( s.solvablesBegin(), s.solvablesEnd(), Print() );
431 // r.eraseFromPool();
432 // MIL << satpool << endl;
434 //std::for_each( s.solvablesBegin(), s.solvablesEnd(), Print() );
438 satpool.addRepoSolv( "sl10.1-beta7-packages.solv" );
439 satpool.addRepoSolv( "sl10.1-beta7-selections.solv" );
440 MIL << satpool << endl;
442 sat::Repo outdated( satpool.reposFind( "sl10.1-beta7-packages.solv" ) );
443 satpool.reposErase( "sl10.1-beta7-packages.solv" );
445 WAR << outdated << endl;
446 for_( sit, outdated.solvablesBegin(), outdated.solvablesEnd() )
450 for_( it, satpool.reposBegin(), satpool.reposEnd() )
453 for_( sit, it->solvablesBegin(), it->solvablesEnd() )
457 ///////////////////////////////////////////////////////////////////
458 INT << "===[END]============================================" << endl << endl;
459 zypp::base::LogControl::instance().logNothing();
462 setenv( "ZYPP_CONF", (sysRoot/"zypp.conf").c_str(), 1 );
464 RepoManager repoManager( makeRepoManager( sysRoot ) );
465 RepoInfoList repos = repoManager.knownRepositories();
466 // SEC << "/Local/ROOT " << repos << endl;
469 for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
471 RepoInfo & nrepo( *it );
472 SEC << nrepo << endl;
474 if ( ! nrepo.enabled() )
477 if ( ! repoManager.isCached( nrepo ) || 0 )
479 if ( repoManager.isCached( nrepo ) )
481 SEC << "cleanCache" << endl;
482 repoManager.cleanCache( nrepo );
484 SEC << "refreshMetadata" << endl;
485 repoManager.refreshMetadata( nrepo, RepoManager::RefreshForced );
486 SEC << "buildCache" << endl;
487 repoManager.buildCache( nrepo );
491 // create from cache:
492 std::list<Repository> repositories;
495 Measure x( "CREATE FROM CACHE" );
496 for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
498 RepoInfo & nrepo( *it );
499 if ( ! nrepo.enabled() )
502 Measure x( "CREATE FROM CACHE "+nrepo.alias() );
503 Repository nrep( repoManager.createFromCache( nrepo ) );
504 const zypp::ResStore & store( nrep.resolvables() );
505 repositories.push_back( nrep );
511 Measure x( "LOAD POOL" );
512 for_( it, repositories.begin(), repositories.end() )
514 Measure x( "LOAD POOL "+(*it).info().alias() );
515 const zypp::ResStore & store( (*it).resolvables() );
516 getZYpp()->addResolvables( store );
523 Measure x( "INIT TARGET" );
525 zypp::base::LogControl::TmpLineWriter shutUp;
526 getZYpp()->initTarget( sysRoot );
527 //getZYpp()->initTarget( "/" );
529 dumpPoolStats( SEC << "TargetStore: " << endl,
530 getZYpp()->target()->resolvables().begin(),
531 getZYpp()->target()->resolvables().end() ) << endl;
534 ResPool pool( getZYpp()->pool() );
535 USR << "pool: " << pool << endl;
537 //std::for_each( pool.begin(), pool.end(), Xprint() );
539 //sat::detail::PoolImpl satpool;
541 //MIL << satpool << endl;
543 ///////////////////////////////////////////////////////////////////
544 INT << "===[END]============================================" << endl << endl;
545 zypp::base::LogControl::instance().logNothing();