libzypp  17.35.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/base/Logger.h>
15 #include <zypp/base/Exception.h>
16 
20 
21 using std::endl;
22 
26 #include <zypp/ResPool.h>
27 
29 namespace zypp
30 {
31  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  {
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 
70  {
72  std::list<Repository> _repos;
74  };
75 
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 
85  {}
86 
87  ManagedFile RepoProvidePackage::operator()( const PoolItem & pi_r, bool fromCache_r )
88  {
89  ManagedFile ret;
90  if ( fromCache_r )
91  {
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  {
104  return pkgProvider.providePackage();
105  }
106  return ret;
107  }
108 
110  //
111  // CLASS NAME : CommitPackageCache
112  //
114 
116  : _pimpl( pimpl_r )
117  {
118  assert( _pimpl );
119  }
120 
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 
136  const PackageProvider & packageProvider_r )
137  : CommitPackageCache( packageProvider_r )
138  {}
139 
141  {}
142 
143  void CommitPackageCache::setCommitList( std::vector<sat::Solvable> commitList_r )
144  { _pimpl->setCommitList( std::move(commitList_r) ); }
145 
147  { return _pimpl->get( citem_r ); }
148 
150  { return _pimpl->preloaded(); }
151 
152  void CommitPackageCache::preloaded( bool newval_r )
153  { _pimpl->preloaded( newval_r ); }
154 
155  /******************************************************************
156  **
157  ** FUNCTION NAME : operator<<
158  ** FUNCTION TYPE : std::ostream &
159  */
160  std::ostream & operator<<( std::ostream & str, const CommitPackageCache & obj )
161  { return str << *obj._pimpl; }
162 
164  } // namespace target
167 } // namespace zypp
Candidate delta and patches for a package.
#define MIL
Definition: Logger.h:100
PackageProviderPolicy & queryInstalledCB(QueryInstalledCB queryInstalledCB_r)
Set callback.
Target::commit helper optimizing package provision.
repository_iterator knownRepositoriesBegin() const
Definition: ResPool.cc:83
Policies and options for PackageProvider.
String related utilities and Regular expression matching.
RW_pointer< Impl > _pimpl
Pointer to implementation.
ManagedFile providePackageFromCache() const
Provide the package if it is cached.
repository_iterator knownRepositoriesEnd() const
Definition: ResPool.cc:86
ManagedFile providePackage() const
Provide the package.
virtual ManagedFile get(const PoolItem &citem_r)
Provide the package.
std::string name() const
Definition: SolvableType.h:70
ManagedFile operator()(const PoolItem &pi, bool fromCache_r)
Provide package optionally fron cache only.
db_const_iterator() ZYPP_DEPRECATED
Open the default rpmdb below the host system (at /).
Package interface.
Definition: Package.h:33
void setCommitList(std::vector< sat::Solvable > commitList_r)
std::ostream & operator<<(std::ostream &str, const CommitPackageCache &obj)
CommitPackageCache(PackageProvider packageProvider_r=RepoProvidePackage())
Ctor.
Base for CommitPackageCache implementations (implements no chache).
ManagedFile get(const PoolItem &citem_r)
Provide a package.
Provides files from different repos.
Global ResObject pool.
Definition: ResPool.h:61
bool preloaded() const
Whether preloaded hint is set.
Provide a package from a Repo.
Combining sat::Solvable and ResStatus.
Definition: PoolItem.h:50
bool isKind(const ResKind &kind_r) const
Definition: SolvableType.h:64
function< ManagedFile(const PoolItem &, bool)> PackageProvider
Easy-to use interface to the ZYPP dependency resolver.
Definition: Application.cc:19
void setCommitList(std::vector< sat::Solvable > commitList_r)
Download(commit) sequence of solvables to compute read ahead.
repo::PackageProviderPolicy _packageProviderPolicy
static const Edition noedition
Value representing noedition ("") This is in fact a valid Edition.
Definition: Edition.h:73
static ResPool instance()
Singleton ctor.
Definition: ResPool.cc:38