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"
49 using namespace zypp::functor;
50 using namespace zypp::ui;
51 using zypp::parser::TagParser;
53 ///////////////////////////////////////////////////////////////////
55 static const Pathname sysRoot( "/Local/ROOT" );
57 ///////////////////////////////////////////////////////////////////
58 ///////////////////////////////////////////////////////////////////
60 { /////////////////////////////////////////////////////////////////
62 bool queryInstalledEditionHelper( const std::string & name_r,
66 if ( ed_r == Edition::noedition )
68 if ( name_r == "kernel-default" && ed_r == Edition("2.6.22.5-10") )
70 if ( name_r == "update-test-affects-package-manager" && ed_r == Edition("1.1-6") )
77 ManagedFile repoProvidePackage( const PoolItem & pi )
79 ResPool _pool( getZYpp()->pool() );
80 repo::RepoMediaAccess _access;
82 // Redirect PackageProvider queries for installed editions
83 // (in case of patch/delta rpm processing) to rpmDb.
84 repo::PackageProviderPolicy packageProviderPolicy;
85 packageProviderPolicy.queryInstalledCB( queryInstalledEditionHelper );
87 Package::constPtr p = asKind<Package>(pi.resolvable());
89 // Build a repository list for repos
90 // contributing to the pool
91 repo::DeltaCandidates deltas( repo::makeDeltaCandidates( _pool.knownRepositoriesBegin(),
92 _pool.knownRepositoriesEnd() ) );
93 repo::PackageProvider pkgProvider( _access, p, deltas, packageProviderPolicy );
94 return pkgProvider.providePackage();
97 /////////////////////////////////////////////////////////////////
99 ///////////////////////////////////////////////////////////////////
100 ///////////////////////////////////////////////////////////////////
104 template <class _LIterator, class _RIterator, class _Function>
105 inline int invokeOnEach( _LIterator lbegin_r, _LIterator lend_r,
106 _RIterator rbegin_r, _RIterator rend_r,
110 for ( _LIterator lit = lbegin_r; lit != lend_r; ++lit )
112 for ( _RIterator rit = rbegin_r; rit != rend_r; ++rit )
115 if ( ! fnc_r( *lit, *rit ) )
124 void dbgDu( Selectable::Ptr sel )
126 if ( sel->installedPoolItem() )
128 DBG << "i: " << sel->installedPoolItem() << endl
129 << sel->installedPoolItem()->diskusage() << endl;
131 if ( sel->candidatePoolItem() )
133 DBG << "c: " << sel->candidatePoolItem() << endl
134 << sel->candidatePoolItem()->diskusage() << endl;
137 << getZYpp()->diskUsage() << endl;
140 ///////////////////////////////////////////////////////////////////
144 bool operator()( const PoolItem & obj_r )
146 if ( obj_r.status().isLocked() )
147 SEC << obj_r << endl;
149 // handle( asKind<Package>( obj_r ) );
150 // handle( asKind<Patch>( obj_r ) );
151 // handle( asKind<Pattern>( obj_r ) );
152 // handle( asKind<Product>( obj_r ) );
156 void handle( const Package_constPtr & p )
161 WAR << p->size() << endl;
162 MIL << p->diskusage() << endl;
165 void handle( const Patch_constPtr & p )
171 void handle( const Pattern_constPtr & p )
176 if ( p->vendor().empty() )
178 else if ( p->vendor() == "SUSE (assumed)" )
182 void handle( const Product_constPtr & p )
188 USR << p->vendor() << endl;
189 USR << p->type() << endl;
193 bool operator()( const _C & obj_r )
199 ///////////////////////////////////////////////////////////////////
200 struct SetTransactValue
202 SetTransactValue( ResStatus::TransactValue newVal_r, ResStatus::TransactByValue causer_r )
203 : _newVal( newVal_r )
204 , _causer( causer_r )
207 ResStatus::TransactValue _newVal;
208 ResStatus::TransactByValue _causer;
210 bool operator()( const PoolItem & pi ) const
212 bool ret = pi.status().setTransactValue( _newVal, _causer );
214 ERR << _newVal << _causer << " " << pi << endl;
219 struct StatusReset : public SetTransactValue
222 : SetTransactValue( ResStatus::KEEP_STATE, ResStatus::USER )
226 struct StatusInstall : public SetTransactValue
229 : SetTransactValue( ResStatus::TRANSACT, ResStatus::USER )
233 inline bool g( const NameKindProxy & nkp, Arch arch = Arch() )
235 if ( nkp.availableEmpty() )
237 ERR << "No Item to select: " << nkp << endl;
239 ZYPP_THROW( Exception("No Item to select") );
242 if ( arch != Arch() )
244 typeof( nkp.availableBegin() ) it = nkp.availableBegin();
245 for ( ; it != nkp.availableEnd(); ++it )
247 if ( (*it)->arch() == arch )
248 return (*it).status().setTransact( true, ResStatus::USER );
252 return nkp.availableBegin()->status().setTransact( true, ResStatus::USER );
255 ///////////////////////////////////////////////////////////////////
257 bool solve( bool establish = false )
263 zypp::base::LogControl::TmpLineWriter shutUp;
264 eres = getZYpp()->resolver()->establishPool();
268 ERR << "establish " << eres << endl;
271 MIL << "establish " << eres << endl;
276 zypp::base::LogControl::TmpLineWriter shutUp;
277 rres = getZYpp()->resolver()->resolvePool();
281 ERR << "resolve " << rres << endl;
284 MIL << "resolve " << rres << endl;
290 SEC << getZYpp()->commit( ZYppCommitPolicy() ) << endl;
294 ///////////////////////////////////////////////////////////////////
296 struct ConvertDbReceive : public callback::ReceiveReport<target::ScriptResolvableReport>
298 virtual void start( const Resolvable::constPtr & script_r,
299 const Pathname & path_r,
302 SEC << __FUNCTION__ << endl
303 << " " << script_r << endl
304 << " " << path_r << endl
305 << " " << task_r << endl;
308 virtual bool progress( Notify notify_r, const std::string & text_r )
310 SEC << __FUNCTION__ << endl
311 << " " << notify_r << endl
312 << " " << text_r << endl;
316 virtual void problem( const std::string & description_r )
318 SEC << __FUNCTION__ << endl
319 << " " << description_r << endl;
322 virtual void finish()
324 SEC << __FUNCTION__ << endl;
328 ///////////////////////////////////////////////////////////////////
330 struct DigestReceive : public callback::ReceiveReport<DigestReport>
337 virtual bool askUserToAcceptNoDigest( const zypp::Pathname &file )
342 virtual bool askUserToAccepUnknownDigest( const Pathname &file, const std::string &name )
347 virtual bool askUserToAcceptWrongDigest( const Pathname &file, const std::string &requested, const std::string &found )
349 USR << "fle " << PathInfo(file) << endl;
350 USR << "req " << requested << endl;
351 USR << "fnd " << found << endl;
356 struct KeyRingSignalsReceive : public callback::ReceiveReport<KeyRingSignals>
358 KeyRingSignalsReceive()
362 virtual void trustedKeyAdded( const PublicKey &/*key*/ )
366 virtual void trustedKeyRemoved( const PublicKey &/*key*/ )
372 ///////////////////////////////////////////////////////////////////
374 struct MediaChangeReceive : public callback::ReceiveReport<media::MediaChangeReport>
376 virtual Action requestMedia( Url & source
379 , const std::string & description )
381 SEC << __FUNCTION__ << endl
382 << " " << source << endl
383 << " " << mediumNr << endl
384 << " " << error << endl
385 << " " << description << endl;
390 ///////////////////////////////////////////////////////////////////
395 bool isIn( const std::set<_Tp> & cont, const typename std::set<_Tp>::value_type & val )
396 { return cont.find( val ) != cont.end(); }
398 ///////////////////////////////////////////////////////////////////
404 RW_pointer<AI> _impl;
406 /******************************************************************
408 ** FUNCTION NAME : main
409 ** FUNCTION TYPE : int
411 int main( int argc, char * argv[] )
413 //zypp::base::LogControl::instance().logfile( "log.restrict" );
414 INT << "===[START]==========================================" << endl;
416 zypp::sat::Pool satpool;
417 MIL << satpool << endl;
418 std::for_each( satpool.solvablesBegin(), satpool.solvablesEnd(), Print() );
420 satpool.addRepoSolv( "sl10.1-beta7-packages.solv" );
421 satpool.addRepoSolv( "sl10.1-beta7-selections.solv" );
422 MIL << satpool << endl;
424 for_( it, satpool.reposBegin(), satpool.reposEnd() )
427 for_( sit, it->solvablesBegin(), it->solvablesEnd() )
431 ///////////////////////////////////////////////////////////////////
432 INT << "===[END]============================================" << endl << endl;
433 zypp::base::LogControl::instance().logNothing();
436 setenv( "ZYPP_CONF", (sysRoot/"zypp.conf").c_str(), 1 );
438 RepoManager repoManager( makeRepoManager( sysRoot ) );
439 RepoInfoList repos = repoManager.knownRepositories();
440 // SEC << "/Local/ROOT " << repos << endl;
443 for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
445 RepoInfo & nrepo( *it );
446 SEC << nrepo << endl;
448 if ( ! nrepo.enabled() )
451 if ( ! repoManager.isCached( nrepo ) || 0 )
453 if ( repoManager.isCached( nrepo ) )
455 SEC << "cleanCache" << endl;
456 repoManager.cleanCache( nrepo );
458 SEC << "refreshMetadata" << endl;
459 repoManager.refreshMetadata( nrepo, RepoManager::RefreshForced );
460 SEC << "buildCache" << endl;
461 repoManager.buildCache( nrepo );
465 // create from cache:
466 std::list<Repository> repositories;
469 Measure x( "CREATE FROM CACHE" );
470 for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
472 RepoInfo & nrepo( *it );
473 if ( ! nrepo.enabled() )
476 Measure x( "CREATE FROM CACHE "+nrepo.alias() );
477 Repository nrep( repoManager.createFromCache( nrepo ) );
478 const zypp::ResStore & store( nrep.resolvables() );
479 repositories.push_back( nrep );
485 Measure x( "LOAD POOL" );
486 for_( it, repositories.begin(), repositories.end() )
488 Measure x( "LOAD POOL "+(*it).info().alias() );
489 const zypp::ResStore & store( (*it).resolvables() );
490 getZYpp()->addResolvables( store );
497 Measure x( "INIT TARGET" );
499 zypp::base::LogControl::TmpLineWriter shutUp;
500 getZYpp()->initTarget( sysRoot );
501 //getZYpp()->initTarget( "/" );
503 dumpPoolStats( SEC << "TargetStore: " << endl,
504 getZYpp()->target()->resolvables().begin(),
505 getZYpp()->target()->resolvables().end() ) << endl;
508 ResPool pool( getZYpp()->pool() );
509 USR << "pool: " << pool << endl;
511 //std::for_each( pool.begin(), pool.end(), Xprint() );
513 //sat::detail::PoolImpl satpool;
515 //MIL << satpool << endl;
517 ///////////////////////////////////////////////////////////////////
518 INT << "===[END]============================================" << endl << endl;
519 zypp::base::LogControl::instance().logNothing();