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/DeltaCandidates.h"
39 #include "zypp/repo/PackageProvider.h"
40 #include "zypp/repo/ScriptProvider.h"
41 #include "zypp/repo/SrcPackageProvider.h"
43 #include "zypp/ui/PatchContents.h"
44 #include "zypp/ResPoolProxy.h"
48 using namespace zypp::functor;
49 using namespace zypp::ui;
50 using zypp::parser::TagParser;
52 ///////////////////////////////////////////////////////////////////
54 static const Pathname sysRoot( "/Local/ROOT" );
56 ///////////////////////////////////////////////////////////////////
57 ///////////////////////////////////////////////////////////////////
59 { /////////////////////////////////////////////////////////////////
61 bool queryInstalledEditionHelper( const std::string & name_r,
65 if ( ed_r == Edition::noedition )
67 if ( name_r == "kernel-default" && ed_r == Edition("2.6.22.5-10") )
69 if ( name_r == "update-test-affects-package-manager" && ed_r == Edition("1.1-6") )
76 ManagedFile repoProvidePackage( const PoolItem & pi )
78 ResPool _pool( getZYpp()->pool() );
79 repo::RepoMediaAccess _access;
81 // Redirect PackageProvider queries for installed editions
82 // (in case of patch/delta rpm processing) to rpmDb.
83 repo::PackageProviderPolicy packageProviderPolicy;
84 packageProviderPolicy.queryInstalledCB( queryInstalledEditionHelper );
86 Package::constPtr p = asKind<Package>(pi.resolvable());
88 // Build a repository list for repos
89 // contributing to the pool
90 repo::DeltaCandidates deltas( repo::makeDeltaCandidates( _pool.knownRepositoriesBegin(),
91 _pool.knownRepositoriesEnd() ) );
92 repo::PackageProvider pkgProvider( _access, p, deltas, packageProviderPolicy );
93 return pkgProvider.providePackage();
96 /////////////////////////////////////////////////////////////////
98 ///////////////////////////////////////////////////////////////////
100 void dbgDu( Selectable::Ptr sel )
102 if ( sel->installedPoolItem() )
104 DBG << "i: " << sel->installedPoolItem() << endl
105 << sel->installedPoolItem()->diskusage() << endl;
107 if ( sel->candidatePoolItem() )
109 DBG << "c: " << sel->candidatePoolItem() << endl
110 << sel->candidatePoolItem()->diskusage() << endl;
113 << getZYpp()->diskUsage() << endl;
116 ///////////////////////////////////////////////////////////////////
120 bool operator()( const PoolItem & obj_r )
122 if ( obj_r.status().isLocked() )
123 SEC << obj_r << endl;
125 // handle( asKind<Package>( obj_r ) );
126 // handle( asKind<Patch>( obj_r ) );
127 // handle( asKind<Pattern>( obj_r ) );
128 // handle( asKind<Product>( obj_r ) );
132 void handle( const Package_constPtr & p )
137 WAR << p->size() << endl;
138 MIL << p->diskusage() << endl;
141 void handle( const Patch_constPtr & p )
147 void handle( const Pattern_constPtr & p )
152 if ( p->vendor().empty() )
154 else if ( p->vendor() == "SUSE (assumed)" )
158 void handle( const Product_constPtr & p )
164 USR << p->vendor() << endl;
165 USR << p->type() << endl;
169 bool operator()( const _C & obj_r )
175 ///////////////////////////////////////////////////////////////////
176 struct SetTransactValue
178 SetTransactValue( ResStatus::TransactValue newVal_r, ResStatus::TransactByValue causer_r )
179 : _newVal( newVal_r )
180 , _causer( causer_r )
183 ResStatus::TransactValue _newVal;
184 ResStatus::TransactByValue _causer;
186 bool operator()( const PoolItem & pi ) const
188 bool ret = pi.status().setTransactValue( _newVal, _causer );
190 ERR << _newVal << _causer << " " << pi << endl;
195 struct StatusReset : public SetTransactValue
198 : SetTransactValue( ResStatus::KEEP_STATE, ResStatus::USER )
202 struct StatusInstall : public SetTransactValue
205 : SetTransactValue( ResStatus::TRANSACT, ResStatus::USER )
209 inline bool g( const NameKindProxy & nkp, Arch arch = Arch() )
211 if ( nkp.availableEmpty() )
213 ERR << "No Item to select: " << nkp << endl;
215 ZYPP_THROW( Exception("No Item to select") );
218 if ( arch != Arch() )
220 typeof( nkp.availableBegin() ) it = nkp.availableBegin();
221 for ( ; it != nkp.availableEnd(); ++it )
223 if ( (*it)->arch() == arch )
224 return (*it).status().setTransact( true, ResStatus::USER );
228 return nkp.availableBegin()->status().setTransact( true, ResStatus::USER );
231 ///////////////////////////////////////////////////////////////////
233 bool solve( bool establish = false )
239 zypp::base::LogControl::TmpLineWriter shutUp;
240 eres = getZYpp()->resolver()->establishPool();
244 ERR << "establish " << eres << endl;
247 MIL << "establish " << eres << endl;
252 zypp::base::LogControl::TmpLineWriter shutUp;
253 rres = getZYpp()->resolver()->resolvePool();
257 ERR << "resolve " << rres << endl;
260 MIL << "resolve " << rres << endl;
266 SEC << getZYpp()->commit( ZYppCommitPolicy() ) << endl;
270 ///////////////////////////////////////////////////////////////////
272 struct ConvertDbReceive : public callback::ReceiveReport<target::ScriptResolvableReport>
274 virtual void start( const Resolvable::constPtr & script_r,
275 const Pathname & path_r,
278 SEC << __FUNCTION__ << endl
279 << " " << script_r << endl
280 << " " << path_r << endl
281 << " " << task_r << endl;
284 virtual bool progress( Notify notify_r, const std::string & text_r )
286 SEC << __FUNCTION__ << endl
287 << " " << notify_r << endl
288 << " " << text_r << endl;
292 virtual void problem( const std::string & description_r )
294 SEC << __FUNCTION__ << endl
295 << " " << description_r << endl;
298 virtual void finish()
300 SEC << __FUNCTION__ << endl;
304 ///////////////////////////////////////////////////////////////////
306 struct DigestReceive : public callback::ReceiveReport<DigestReport>
313 virtual bool askUserToAcceptNoDigest( const zypp::Pathname &file )
318 virtual bool askUserToAccepUnknownDigest( const Pathname &file, const std::string &name )
323 virtual bool askUserToAcceptWrongDigest( const Pathname &file, const std::string &requested, const std::string &found )
325 USR << "fle " << PathInfo(file) << endl;
326 USR << "req " << requested << endl;
327 USR << "fnd " << found << endl;
335 struct KeyRingSignalsReceive : public callback::ReceiveReport<KeyRingSignals>
337 KeyRingSignalsReceive()
341 virtual void trustedKeyAdded( const PublicKey &/*key*/ )
345 virtual void trustedKeyRemoved( const PublicKey &/*key*/ )
351 ///////////////////////////////////////////////////////////////////
353 struct MediaChangeReceive : public callback::ReceiveReport<media::MediaChangeReport>
355 virtual Action requestMedia( Url & source
358 , const std::string & description )
360 SEC << __FUNCTION__ << endl
361 << " " << source << endl
362 << " " << mediumNr << endl
363 << " " << error << endl
364 << " " << description << endl;
369 ///////////////////////////////////////////////////////////////////
374 bool isIn( const std::set<_Tp> & cont, const typename std::set<_Tp>::value_type & val )
375 { return cont.find( val ) != cont.end(); }
378 ///////////////////////////////////////////////////////////////////
380 struct AddResolvables
382 bool operator()( const Repository & src ) const
384 getZYpp()->addResolvables( src.resolvables() );
389 ///////////////////////////////////////////////////////////////////
392 std::ostream & operator<<( std::ostream & str, const iostr::EachLine & obj )
394 str << "(" << obj.valid() << ")[" << obj.lineNo() << "|" << obj.lineStart() << "]{" << *obj << "}";
399 ///////////////////////////////////////////////////////////////////
401 #define for_(IT,BEG,END) for ( typeof(BEG) IT = BEG; IT != END; ++IT )
403 ///////////////////////////////////////////////////////////////////
405 { /////////////////////////////////////////////////////////////////
408 void Vtst( const std::string & lhs, const std::string & rhs )
410 (VendorAttr::instance().equivalent( lhs, rhs )?MIL:ERR) << lhs << " <==> "<< rhs << endl;
414 /////////////////////////////////////////////////////////////////
416 ///////////////////////////////////////////////////////////////////
418 using namespace zypp;
420 void tt( std::string dd )
423 std::string::size_type pos = dd.find( "/" );
424 while ( --level && pos != std::string::npos )
426 pos = dd.find( "/", pos+1 );
428 if ( pos != std::string::npos )
430 DBG << dd << "\t" << level << " " << pos << endl;
433 /******************************************************************
435 ** FUNCTION NAME : main
436 ** FUNCTION TYPE : int
438 int main( int argc, char * argv[] )
440 //zypp::base::LogControl::instance().logfile( "log.restrict" );
441 INT << "===[START]==========================================" << endl;
442 setenv( "ZYPP_CONF", "/Local/ROOT/zypp.conf", 1 );
445 KeyRingSignalsReceive baa;
447 RepoManager repoManager( makeRepoManager( "/Local/ROOT" ) );
449 RepoInfoList repos = repoManager.knownRepositories();
450 SEC << "/Local/ROOT " << repos << endl;
452 for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
454 RepoInfo & nrepo( *it );
455 if ( ! nrepo.enabled() )
458 if ( ! repoManager.isCached( nrepo ) || 0 )
460 if ( repoManager.isCached( nrepo ) )
462 SEC << "cleanCache" << endl;
463 repoManager.cleanCache( nrepo );
465 SEC << "refreshMetadata" << endl;
466 //repoManager.refreshMetadata( nrepo, RepoManager::RefreshForced );
467 repoManager.refreshMetadata( nrepo );
468 SEC << "buildCache" << endl;
469 repoManager.buildCache( nrepo );
472 SEC << nrepo << endl;
473 Repository nrep( repoManager.createFromCache( nrepo ) );
474 const zypp::ResStore & store( nrep.resolvables() );
476 dumpPoolStats( SEC << "Store: " << endl,
477 store.begin(), store.end() ) << endl;
478 getZYpp()->addResolvables( store );
481 ResPool pool( getZYpp()->pool() );
482 USR << "pool: " << pool << endl;
483 SEC << pool.knownRepositoriesSize() << endl;
488 zypp::base::LogControl::TmpLineWriter shutUp;
489 //getZYpp()->initTarget( sysRoot );
490 getZYpp()->initTarget( "/" );
492 MIL << "Added target: " << pool << endl;
496 //std::for_each( pool.begin(), pool.end(), Xprint() );
498 PoolItem pi = getPi<Patch>( "fetchmsttfonts.sh" );
501 pi = getPi<Script>( "fetchmsttfonts.sh-4347-patch-fetchmsttfonts.sh-2" );
506 Script::constPtr script_r( asKind<Script>( pi.resolvable() ) );
507 MIL << script_r << endl;
510 repo::RepoMediaAccess access_r;
511 repo::ScriptProvider prov( access_r );
512 ManagedFile localfile = prov.provideScript( script_r, true );
513 MIL << localfile << endl;
517 //pi.status().setTransact( true, ResStatus::USER );
520 ///////////////////////////////////////////////////////////////////
521 INT << "===[END]============================================" << endl << endl;
522 zypp::base::LogControl::instance().logNothing();