libzypp  13.10.6
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 
19 
20 using std::endl;
21 
25 #include "zypp/ResPool.h"
26 
28 namespace zypp
29 {
30  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 
66  {
68  std::list<Repository> _repos;
70  };
71 
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 
81  {}
82 
83  ManagedFile RepoProvidePackage::operator()( const PoolItem & pi, bool fromCache_r )
84  {
85  Package::constPtr p = asKind<Package>(pi.resolvable());
86  if ( fromCache_r )
87  {
88  repo::PackageProvider pkgProvider( _impl->_access, p, repo::DeltaCandidates(), _impl->_packageProviderPolicy );
89  return pkgProvider.providePackageFromCache();
90  }
91  else
92  {
93  repo::DeltaCandidates deltas( _impl->_repos, p->name() );
94  repo::PackageProvider pkgProvider( _impl->_access, p, deltas, _impl->_packageProviderPolicy );
95  return pkgProvider.providePackage();
96  }
97  }
98 
100  //
101  // CLASS NAME : CommitPackageCache
102  //
104 
106  : _pimpl( pimpl_r )
107  {
108  assert( _pimpl );
109  }
110 
111  CommitPackageCache::CommitPackageCache( const Pathname & rootDir_r,
112  const PackageProvider & packageProvider_r )
113  {
114  if ( getenv("ZYPP_COMMIT_NO_PACKAGE_CACHE") )
115  {
116  MIL << "$ZYPP_COMMIT_NO_PACKAGE_CACHE is set." << endl;
117  _pimpl.reset( new Impl( packageProvider_r ) ); // no cache
118  }
119  else
120  {
121  _pimpl.reset( new CommitPackageCacheReadAhead( rootDir_r, packageProvider_r ) );
122  }
123  assert( _pimpl );
124  }
125 
127  {}
128 
129  void CommitPackageCache::setCommitList( std::vector<sat::Solvable> commitList_r )
130  {
131  _pimpl->setCommitList( commitList_r );
132  }
133 
135  { return _pimpl->get( citem_r ); }
136 
137  /******************************************************************
138  **
139  ** FUNCTION NAME : operator<<
140  ** FUNCTION TYPE : std::ostream &
141  */
142  std::ostream & operator<<( std::ostream & str, const CommitPackageCache & obj )
143  { return str << *obj._pimpl; }
144 
146  } // namespace target
149 } // namespace zypp
Candidate delta and patches for a package.
#define MIL
Definition: Logger.h:47
CommitPackageCache(const Pathname &rootDir_r, const PackageProvider &packageProvider_r=RepoProvidePackage())
Ctor.
function< ManagedFile(const PoolItem &pi, bool fromCache_r)> PackageProvider
Target::commit helper optimizing package provision.
Policies and options for PackageProvider.
RW_pointer< Impl > _pimpl
Pointer to implementation.
ResObject::constPtr resolvable() const
Returns the ResObject::constPtr.
Definition: PoolItem.cc:280
ManagedFile operator()(const PoolItem &pi, bool fromCache_r)
Provide package optionally fron cache only.
repository_iterator knownRepositoriesEnd() const
Definition: ResPool.cc:80
ManagedFile providePackageFromCache() const
Provide the package if it is cached.
std::ostream & operator<<(std::ostream &str, const CommitPackageCache &obj)
Base for CommitPackageCache implementations (implements no chache).
ManagedFile get(const PoolItem &citem_r)
Provide a package.
Provides files from different repos.
repository_iterator knownRepositoriesBegin() const
Definition: ResPool.cc:77
Global ResObject pool.
Definition: ResPool.h:48
Provide a package from a Repo.
Reference counted access to a _Tp object calling a custom Dispose function when the last AutoDispose ...
Definition: AutoDispose.h:92
Reference to a PoolItem connecting ResObject and ResStatus.
Definition: PoolItem.h:50
void setCommitList(std::vector< sat::Solvable > commitList_r)
Download(commit) sequence of solvables to compute read ahead.
repo::PackageProviderPolicy _packageProviderPolicy
TraitsType::constPtrType constPtr
Definition: Package.h:38
static const Edition noedition
Value representing noedition (&quot;&quot;) This is in fact a valid Edition.
Definition: Edition.h:73
static ResPool instance()
Singleton ctor.
Definition: ResPool.cc:33