libzypp: zypp/target/CommitPackageCache.cc Source File

libzypp 17.25.10

CommitPackageCache.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #include <iostream>
13 #include <zypp/base/Logger.h>
14 #include <zypp/base/Exception.h>
15
16 #include <zypp/target/CommitPackageCache.h>
17 #include <zypp/target/CommitPackageCacheImpl.h>
18 #include <zypp/target/CommitPackageCacheReadAhead.h>
19
20 using std::endl;
21
22 #include <zypp/target/rpm/librpmDb.h>
23 #include <zypp/repo/PackageProvider.h>
24 #include <zypp/repo/DeltaCandidates.h>
25 #include <zypp/ResPool.h>
26
28 namespace zypp
29 {
31 namespace target
32 {
33
35 namespace {
40 struct QueryInstalledEditionHelper
41 {
42 bool operator()( const std::string & name_r, const Edition & ed_r, const Arch & arch_r ) const
43 {
44 rpm::librpmDb::db_const_iterator it;
45 for ( it.findByName( name_r ); *it; ++it )
46 {
47 if ( arch_r == it->tag_arch()
48 && ( ed_r == Edition::noedition || ed_r == it->tag_edition() ) )
49 {
50 return true;
51 }
52 }
53 return false;
54 }
55 };
56 } // namespace
58
60 //
61 // class RepoProvidePackage
62 //
64
65 struct RepoProvidePackage::Impl
66 {
67 repo::RepoMediaAccess _access;
68 std::list<Repository> _repos;
69 repo::PackageProviderPolicy _packageProviderPolicy;
70 };
71
72 RepoProvidePackage::RepoProvidePackage()
73 : _impl( new Impl )
74 {
75 const ResPool & pool( ResPool::instance() );
76 _impl->_repos.insert( _impl->_repos.begin(), pool.knownRepositoriesBegin(), pool.knownRepositoriesEnd() );
77 _impl->_packageProviderPolicy.queryInstalledCB( QueryInstalledEditionHelper() );
78 }
79
80 RepoProvidePackage::~RepoProvidePackage()
81 {}
82
83 ManagedFile RepoProvidePackage::operator()( const PoolItem & pi_r, bool fromCache_r )
84 {
85 ManagedFile ret;
86 if ( fromCache_r )
87 {
88 repo::PackageProvider pkgProvider( _impl->_access, pi_r, _impl->_packageProviderPolicy );
89 ret = pkgProvider.providePackageFromCache();
90 }
91 else if ( pi_r.isKind<Package>() ) // may make use of deltas
92 {
93 repo::DeltaCandidates deltas( _impl->_repos, pi_r.name() );
94 repo::PackageProvider pkgProvider( _impl->_access, pi_r, deltas, _impl->_packageProviderPolicy );
95 return pkgProvider.providePackage();
96 }
97 else // SrcPackage or throws
98 {
99 repo::PackageProvider pkgProvider( _impl->_access, pi_r, _impl->_packageProviderPolicy );
100 return pkgProvider.providePackage();
101 }
102 return ret;
103 }
104
106 //
107 // CLASS NAME : CommitPackageCache
108 //
110
111 CommitPackageCache::CommitPackageCache( Impl * pimpl_r )
112 : _pimpl( pimpl_r )
113 {
114 assert( _pimpl );
115 }
116
117 CommitPackageCache::CommitPackageCache( const PackageProvider & packageProvider_r )
118 {
119 if ( getenv("ZYPP_COMMIT_NO_PACKAGE_CACHE") )
120 {
121 MIL << "$ZYPP_COMMIT_NO_PACKAGE_CACHE is set." << endl;
122 _pimpl.reset( new Impl( packageProvider_r ) ); // no cache
123 }
124 else
125 {
126 _pimpl.reset( new CommitPackageCacheReadAhead( packageProvider_r ) );
127 }
128 assert( _pimpl );
129 }
130
131 CommitPackageCache::CommitPackageCache( const Pathname & /*rootDir_r*/,
132 const PackageProvider & packageProvider_r )
133 : CommitPackageCache( packageProvider_r )
134 {}
135
136 CommitPackageCache::~CommitPackageCache()
137 {}
138
139 void CommitPackageCache::setCommitList( std::vector<sat::Solvable> commitList_r )
140 { _pimpl->setCommitList( commitList_r ); }
141
142 ManagedFile CommitPackageCache::get( const PoolItem & citem_r )
143 { return _pimpl->get( citem_r ); }
144
145 bool CommitPackageCache::preloaded() const
146 { return _pimpl->preloaded(); }
147
148 void CommitPackageCache::preloaded( bool newval_r )
149 { _pimpl->preloaded( newval_r ); }
150
151 /******************************************************************
152 **
153 ** FUNCTION NAME : operator<<
154 ** FUNCTION TYPE : std::ostream &
155 */
156 std::ostream & operator<<( std::ostream & str, const CommitPackageCache & obj )
157 { return str << *obj._pimpl; }
158
160 } // namespace target
163 } // namespace zypp
CommitPackageCacheImpl.h
CommitPackageCacheReadAhead.h
CommitPackageCache.h
DeltaCandidates.h
Exception.h
Logger.h
MIL
#define MIL
Definition: Logger.h:91
PackageProvider.h
ResPool.h
zypp::AutoDispose
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
Definition: AutoDispose.h:93
zypp::Edition::noedition
static const Edition noedition
Value representing noedition ("") This is in fact a valid Edition.
Definition: Edition.h:73
zypp::Package
Package interface.
Definition: Package.h:33
zypp::PoolItem
Combining sat::Solvable and ResStatus.
Definition: PoolItem.h:51
zypp::ResPool
Global ResObject pool.
Definition: ResPool.h:61
zypp::ResPool::instance
static ResPool instance()
Singleton ctor.
Definition: ResPool.cc:37
zypp::ResPool::knownRepositoriesBegin
repository_iterator knownRepositoriesBegin() const
Definition: ResPool.cc:82
zypp::ResPool::knownRepositoriesEnd
repository_iterator knownRepositoriesEnd() const
Definition: ResPool.cc:85
zypp::filesystem::Pathname
Pathname.
Definition: Pathname.h:45
zypp::repo::DeltaCandidates
Candidate delta and patches for a package.
Definition: DeltaCandidates.h:37
zypp::repo::PackageProviderPolicy
Policies and options for PackageProvider.
Definition: PackageProvider.h:35
zypp::repo::PackageProvider
Provide a package from a Repo.
Definition: PackageProvider.h:61
zypp::repo::PackageProvider::providePackage
ManagedFile providePackage() const
Provide the package.
Definition: PackageProvider.cc:695
zypp::repo::PackageProvider::providePackageFromCache
ManagedFile providePackageFromCache() const
Provide the package if it is cached.
Definition: PackageProvider.cc:698
zypp::repo::RepoMediaAccess
Provides files from different repos.
Definition: RepoProvideFile.h:61
zypp::target::CommitPackageCacheReadAhead
Definition: CommitPackageCacheReadAhead.h:84
zypp::target::CommitPackageCache::Impl
Base for CommitPackageCache implementations (implements no chache).
Definition: CommitPackageCacheImpl.h:40
zypp::target::CommitPackageCache
Target::commit helper optimizing package provision.
Definition: CommitPackageCache.h:59
zypp::target::CommitPackageCache::~CommitPackageCache
~CommitPackageCache()
Dtor.
Definition: CommitPackageCache.cc:136
zypp::target::CommitPackageCache::setCommitList
void setCommitList(std::vector< sat::Solvable > commitList_r)
Download(commit) sequence of solvables to compute read ahead.
Definition: CommitPackageCache.cc:139
zypp::target::CommitPackageCache::preloaded
bool preloaded() const
Whether preloaded hint is set.
Definition: CommitPackageCache.cc:145
zypp::target::CommitPackageCache::CommitPackageCache
CommitPackageCache(const PackageProvider &packageProvider_r=RepoProvidePackage())
Ctor.
Definition: CommitPackageCache.cc:117
zypp::target::CommitPackageCache::_pimpl
RW_pointer< Impl > _pimpl
Pointer to implementation.
Definition: CommitPackageCache.h:106
zypp::target::CommitPackageCache::get
ManagedFile get(const PoolItem &citem_r)
Provide a package.
Definition: CommitPackageCache.cc:142
zypp::target::CommitPackageCache::PackageProvider
function< ManagedFile(const PoolItem &pi, bool fromCache_r)> PackageProvider
Definition: CommitPackageCache.h:63
zypp::target::RepoProvidePackage::RepoProvidePackage
RepoProvidePackage()
Definition: CommitPackageCache.cc:72
zypp::target::RepoProvidePackage::~RepoProvidePackage
~RepoProvidePackage()
Definition: CommitPackageCache.cc:80
zypp::target::RepoProvidePackage::_impl
RW_pointer< Impl > _impl
Definition: CommitPackageCache.h:48
zypp::target::RepoProvidePackage::operator()
ManagedFile operator()(const PoolItem &pi, bool fromCache_r)
Provide package optionally fron cache only.
Definition: CommitPackageCache.cc:83
librpmDb.h
str
String related utilities and Regular expression matching.
zypp::target::operator<<
std::ostream & operator<<(std::ostream &str, const CommitPackageCache &obj)
Definition: CommitPackageCache.cc:156
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:2
zypp::sat::SolvableType::name
std::string name() const
Definition: SolvableType.h:70
zypp::sat::SolvableType::isKind
bool isKind(const ResKind &kind_r) const
Definition: SolvableType.h:64
zypp::target::RepoProvidePackage::Impl
Definition: CommitPackageCache.cc:66
zypp::target::RepoProvidePackage::Impl::_packageProviderPolicy
repo::PackageProviderPolicy _packageProviderPolicy
Definition: CommitPackageCache.cc:69
zypp::target::RepoProvidePackage::Impl::_access
repo::RepoMediaAccess _access
Definition: CommitPackageCache.cc:67
zypp::target::RepoProvidePackage::Impl::_repos
std::list< Repository > _repos
Definition: CommitPackageCache.cc:68