libzypp: zypp/target/CommitPackageCache.cc Source File

libzypp 17.38.14

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