libzypp 17.34.1
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/base/Logger.h>
15#include <zypp/base/Exception.h>
16
20
21using std::endl;
22
26#include <zypp/ResPool.h>
27
29namespace zypp
30{
32 namespace target
33 {
34
36 namespace {
41 struct QueryInstalledEditionHelper
42 {
43 bool operator()( const std::string & name_r, const Edition & ed_r, const Arch & arch_r ) const
44 {
45 rpm::librpmDb::db_const_iterator it;
46 for ( it.findByName( name_r ); *it; ++it )
47 {
48 if ( arch_r == it->tag_arch()
49 && ( ed_r == Edition::noedition || ed_r == it->tag_edition() ) )
50 {
51 return true;
52 }
53 }
54 return false;
55 }
56 };
57 } // namespace
59
61 //
62 // class RepoProvidePackage
63 //
65
72
74 : _impl( new Impl )
75 {
76 const ResPool & pool( ResPool::instance() );
77 _impl->_repos.insert( _impl->_repos.begin(), pool.knownRepositoriesBegin(), pool.knownRepositoriesEnd() );
78 _impl->_packageProviderPolicy.queryInstalledCB( QueryInstalledEditionHelper() );
79 }
80
83
84 ManagedFile RepoProvidePackage::operator()( const PoolItem & pi_r, bool fromCache_r )
85 {
86 ManagedFile ret;
87 if ( fromCache_r )
88 {
90 ret = pkgProvider.providePackageFromCache();
91 }
92 else if ( pi_r.isKind<Package>() ) // may make use of deltas
93 {
94 repo::DeltaCandidates deltas( _impl->_repos, pi_r.name() );
95 repo::PackageProvider pkgProvider( _impl->_access, pi_r, deltas, _impl->_packageProviderPolicy );
96 return pkgProvider.providePackage();
97 }
98 else // SrcPackage or throws
99 {
101 return pkgProvider.providePackage();
102 }
103 return ret;
104 }
105
107 //
108 // CLASS NAME : CommitPackageCache
109 //
111
113 : _pimpl( pimpl_r )
114 {
115 assert( _pimpl );
116 }
117
119 {
120 if ( getenv("ZYPP_COMMIT_NO_PACKAGE_CACHE") )
121 {
122 MIL << "$ZYPP_COMMIT_NO_PACKAGE_CACHE is set." << endl;
123 _pimpl.reset( new Impl( std::move(packageProvider_r) ) ); // no cache
124 }
125 else
126 {
127 _pimpl.reset( new CommitPackageCacheReadAhead( std::move(packageProvider_r) ) );
128 }
129 assert( _pimpl );
130 }
131
133 const PackageProvider & packageProvider_r )
134 : CommitPackageCache( packageProvider_r )
135 {}
136
139
140 void CommitPackageCache::setCommitList( std::vector<sat::Solvable> commitList_r )
141 { _pimpl->setCommitList( std::move(commitList_r) ); }
142
144 { return _pimpl->get( citem_r ); }
145
147 { return _pimpl->preloaded(); }
148
149 void CommitPackageCache::preloaded( bool newval_r )
150 { _pimpl->preloaded( newval_r ); }
151
152 /******************************************************************
153 **
154 ** FUNCTION NAME : operator<<
155 ** FUNCTION TYPE : std::ostream &
156 */
157 std::ostream & operator<<( std::ostream & str, const CommitPackageCache & obj )
158 { return str << *obj._pimpl; }
159
161 } // namespace target
164} // namespace zypp
static const Edition noedition
Value representing noedition ("") This is in fact a valid Edition.
Definition Edition.h:73
Package interface.
Definition Package.h:34
Combining sat::Solvable and ResStatus.
Definition PoolItem.h:51
Global ResObject pool.
Definition ResPool.h:62
static ResPool instance()
Singleton ctor.
Definition ResPool.cc:38
repository_iterator knownRepositoriesBegin() const
Definition ResPool.cc:83
repository_iterator knownRepositoriesEnd() const
Definition ResPool.cc:86
Candidate delta and patches for a package.
Policies and options for PackageProvider.
PackageProviderPolicy & queryInstalledCB(QueryInstalledCB queryInstalledCB_r)
Set callback.
Provide a package from a Repo.
ManagedFile providePackage() const
Provide the package.
ManagedFile providePackageFromCache() const
Provide the package if it is cached.
Provides files from different repos.
Base for CommitPackageCache implementations (implements no chache).
virtual ManagedFile get(const PoolItem &citem_r)
Provide the package.
void setCommitList(std::vector< sat::Solvable > commitList_r)
Target::commit helper optimizing package provision.
CommitPackageCache(PackageProvider packageProvider_r=RepoProvidePackage())
Ctor.
void setCommitList(std::vector< sat::Solvable > commitList_r)
Download(commit) sequence of solvables to compute read ahead.
bool preloaded() const
Whether preloaded hint is set.
function< ManagedFile(const PoolItem &, bool)> PackageProvider
RW_pointer< Impl > _pimpl
Pointer to implementation.
ManagedFile get(const PoolItem &citem_r)
Provide a package.
ManagedFile operator()(const PoolItem &pi, bool fromCache_r)
Provide package optionally fron cache only.
String related utilities and Regular expression matching.
std::ostream & operator<<(std::ostream &str, const CommitPackageCache &obj)
Easy-to use interface to the ZYPP dependency resolver.
std::string name() const
bool isKind(const ResKind &kind_r) const
repo::PackageProviderPolicy _packageProviderPolicy
#define MIL
Definition Logger.h:98