From 2f452c46296368c1f502e88184f8990e6c827dbc Mon Sep 17 00:00:00 2001 From: Michael Andres Date: Tue, 12 Apr 2011 16:02:09 +0200 Subject: [PATCH] Fix CommitPackageCache to be independent of outer package sequence repesentation. --- zypp/target/CommitPackageCache.cc | 34 +++++++--------------------- zypp/target/CommitPackageCache.h | 15 ++++++++----- zypp/target/CommitPackageCacheImpl.h | 13 +++++++---- zypp/target/CommitPackageCacheReadAhead.cc | 36 ++++++++++++++---------------- zypp/target/CommitPackageCacheReadAhead.h | 19 +++++++++------- 5 files changed, 54 insertions(+), 63 deletions(-) diff --git a/zypp/target/CommitPackageCache.cc b/zypp/target/CommitPackageCache.cc index 87eabc7..11425c0 100644 --- a/zypp/target/CommitPackageCache.cc +++ b/zypp/target/CommitPackageCache.cc @@ -32,25 +32,13 @@ namespace zypp // /////////////////////////////////////////////////////////////////// - /////////////////////////////////////////////////////////////////// - // - // METHOD NAME : CommitPackageCache::CommitPackageCache - // METHOD TYPE : Ctor - // CommitPackageCache::CommitPackageCache( Impl * pimpl_r ) : _pimpl( pimpl_r ) { assert( _pimpl ); } - /////////////////////////////////////////////////////////////////// - // - // METHOD NAME : CommitPackageCache::CommitPackageCache - // METHOD TYPE : Ctor - // - CommitPackageCache::CommitPackageCache( const_iterator begin_r, - const_iterator end_r, - const Pathname & rootDir_r, + CommitPackageCache::CommitPackageCache( const Pathname & rootDir_r, const PackageProvider & packageProvider_r ) { if ( getenv("ZYPP_COMMIT_NO_PACKAGE_CACHE") ) @@ -60,26 +48,20 @@ namespace zypp } else { - _pimpl.reset( new CommitPackageCacheReadAhead( begin_r, end_r, - rootDir_r, packageProvider_r ) ); + _pimpl.reset( new CommitPackageCacheReadAhead( rootDir_r, packageProvider_r ) ); } assert( _pimpl ); } - /////////////////////////////////////////////////////////////////// - // - // METHOD NAME : CommitPackageCache::~CommitPackageCache - // METHOD TYPE : Dtor - // CommitPackageCache::~CommitPackageCache() {} - /////////////////////////////////////////////////////////////////// - // - // METHOD NAME : CommitPackageCache::~CommitPackageCache - // METHOD TYPE : Dtor - // - ManagedFile CommitPackageCache::get( const_iterator citem_r ) + void CommitPackageCache::setCommitList( std::vector commitList_r ) + { + _pimpl->setCommitList( commitList_r ); + } + + ManagedFile CommitPackageCache::get( const PoolItem & citem_r ) { return _pimpl->get( citem_r ); } /****************************************************************** diff --git a/zypp/target/CommitPackageCache.h b/zypp/target/CommitPackageCache.h index 9193747..c1c5797 100644 --- a/zypp/target/CommitPackageCache.h +++ b/zypp/target/CommitPackageCache.h @@ -13,7 +13,6 @@ #define ZYPP_TARGET_COMMITPACKAGECACHE_H #include -#include #include "zypp/base/PtrTypes.h" #include "zypp/base/Function.h" @@ -40,22 +39,26 @@ namespace zypp friend std::ostream & operator<<( std::ostream & str, const CommitPackageCache & obj ); public: - typedef std::list::const_iterator const_iterator; typedef function PackageProvider; public: /** Ctor */ - CommitPackageCache( const_iterator begin_r, - const_iterator end_r, - const Pathname & rootDir_r, + CommitPackageCache( const Pathname & rootDir_r, const PackageProvider & packageProvider_r ); /** Dtor */ ~CommitPackageCache(); public: + /** Download(commit) sequence of solvables to compute read ahead. */ + void setCommitList( std::vector commitList_r ); + /** \overload */ + template + void setCommitList( _Iterator begin_r, _Iterator end_r ) + { setCommitList( std::vector( begin_r, end_r ) ); } + /** Provide a package. */ - ManagedFile get( const_iterator citem_r ); + ManagedFile get( const PoolItem & citem_r ); public: /** Implementation. */ diff --git a/zypp/target/CommitPackageCacheImpl.h b/zypp/target/CommitPackageCacheImpl.h index 584607f..41f8c1e 100644 --- a/zypp/target/CommitPackageCacheImpl.h +++ b/zypp/target/CommitPackageCacheImpl.h @@ -39,7 +39,6 @@ namespace zypp class CommitPackageCache::Impl { public: - typedef CommitPackageCache::const_iterator const_iterator; typedef CommitPackageCache::PackageProvider PackageProvider; public: @@ -54,14 +53,17 @@ namespace zypp /** Provide the package. * Derived classes overload this. */ - virtual ManagedFile get( const_iterator citem_r ) + virtual ManagedFile get( const PoolItem & citem_r ) { - return sourceProvidePackage( *citem_r ); + return sourceProvidePackage( citem_r ); } + void setCommitList( std::vector commitList_r ) + { _commitList = commitList_r; } + protected: /** Let the Source provide the package. */ - ManagedFile sourceProvidePackage( const PoolItem & pi ) const + virtual ManagedFile sourceProvidePackage( const PoolItem & pi ) const { if ( ! _packageProvider ) { @@ -77,6 +79,9 @@ namespace zypp return ret; } + protected: + std::vector _commitList; + private: PackageProvider _packageProvider; }; diff --git a/zypp/target/CommitPackageCacheReadAhead.cc b/zypp/target/CommitPackageCacheReadAhead.cc index ba6bc06..e55c082 100644 --- a/zypp/target/CommitPackageCacheReadAhead.cc +++ b/zypp/target/CommitPackageCacheReadAhead.cc @@ -49,12 +49,9 @@ namespace zypp // METHOD NAME : CommitPackageCacheReadAhead::CommitPackageCacheReadAhead // METHOD TYPE : Ctor // - CommitPackageCacheReadAhead::CommitPackageCacheReadAhead( const_iterator begin_r, - const_iterator end_r, - const Pathname & rootDir_r, + CommitPackageCacheReadAhead::CommitPackageCacheReadAhead( const Pathname & rootDir_r, const PackageProvider & packageProvider_r ) : CommitPackageCache::Impl( packageProvider_r ) - , _commitListEnd( end_r ) , _rootDir( rootDir_r ) {} @@ -78,7 +75,7 @@ namespace zypp // METHOD NAME : CommitPackageCacheReadAhead::cacheLastInteractive // METHOD TYPE : void // - void CommitPackageCacheReadAhead::cacheLastInteractive( const_iterator citem_r ) + void CommitPackageCacheReadAhead::cacheLastInteractive( const PoolItem & citem_r ) { // Fill cache errors are never proagated. try @@ -97,23 +94,24 @@ namespace zypp // METHOD NAME : CommitPackageCacheReadAhead::doCacheLastInteractive // METHOD TYPE : void // - void CommitPackageCacheReadAhead::doCacheLastInteractive( const_iterator citem_r ) + void CommitPackageCacheReadAhead::doCacheLastInteractive( const PoolItem & citem_r ) { CacheMap addToCache; ByteCount addSize; // Collect all remaining packages to install from // _lastInteractive media. (just the PoolItem data) - for ( const_iterator it = citem_r; it != _commitListEnd; ++it ) + for_( it,_commitList.begin(), _commitList.end() ) { - if ( IMediaKey( *it ) == _lastInteractive - && isKind(it->resolvable()) - && it->status().isToBeInstalled() ) + PoolItem pi( *it ); + if ( IMediaKey( pi ) == _lastInteractive + && isKind(pi.resolvable()) + && pi.status().isToBeInstalled() ) { - if ( _cacheMap.find( *it ) == _cacheMap.end() ) + if ( _cacheMap.find( pi ) == _cacheMap.end() ) { - addToCache[*it]; - addSize += it->resolvable()->downloadSize(); + addToCache[pi]; + addSize += pi->downloadSize(); } } } @@ -190,16 +188,16 @@ namespace zypp // METHOD NAME : CommitPackageCacheReadAhead::get // METHOD TYPE : ManagedFile // - ManagedFile CommitPackageCacheReadAhead::get( const_iterator citem_r ) + ManagedFile CommitPackageCacheReadAhead::get( const PoolItem & citem_r ) { // Non CD/DVD media provide their packages without cache. - if ( ! onInteractiveMedia( *citem_r ) ) + if ( ! onInteractiveMedia( citem_r ) ) { - return sourceProvidePackage( *citem_r ); + return sourceProvidePackage( citem_r ); } // Check whether it's cached. - CacheMap::iterator it = _cacheMap.find( *citem_r ); + CacheMap::iterator it = _cacheMap.find( citem_r ); if ( it != _cacheMap.end() ) { // ManagedFile delivered to the application is removed @@ -223,7 +221,7 @@ namespace zypp // In case we have to change the media to provide the requested // file, try to cache files from the current media, that are // required later. - IMediaKey current( *citem_r ); + IMediaKey current( citem_r ); if ( current != _lastInteractive ) { if ( _lastInteractive != IMediaKey() ) @@ -237,7 +235,7 @@ namespace zypp } // Provide and return the file from media. - return sourceProvidePackage( *citem_r ); + return sourceProvidePackage( citem_r ); } diff --git a/zypp/target/CommitPackageCacheReadAhead.h b/zypp/target/CommitPackageCacheReadAhead.h index d8ece82..007951b 100644 --- a/zypp/target/CommitPackageCacheReadAhead.h +++ b/zypp/target/CommitPackageCacheReadAhead.h @@ -39,6 +39,12 @@ namespace zypp {} explicit + IMediaKey( const PoolItem & obj_r ) + : _repo( obj_r->repository() ) + , _mediaNr( obj_r->mediaNr() ) + {} + + explicit IMediaKey( const ResObject::constPtr & obj_r ) : _repo( obj_r->repository() ) , _mediaNr( obj_r->mediaNr() ) @@ -79,14 +85,12 @@ namespace zypp typedef std::map CacheMap; public: - CommitPackageCacheReadAhead( const_iterator begin_r, - const_iterator end_r, - const Pathname & rootDir_r, + CommitPackageCacheReadAhead( const Pathname & rootDir_r, const PackageProvider & packageProvider_r ); public: /** Provide the package. Either from Source or from cache. */ - virtual ManagedFile get( const_iterator citem_r ); + virtual ManagedFile get( const PoolItem & citem_r ); private: /** Return whether \a pi is located on a CD/DVD */ @@ -98,16 +102,15 @@ namespace zypp * Performs the read ahead of packages trying to avoid the necessity * of switching back to the current media later. */ - void cacheLastInteractive( const_iterator citem_r ); + void cacheLastInteractive( const PoolItem & citem_r ); /** cacheLastInteractive helper . */ - void doCacheLastInteractive( const_iterator citem_r ); + void doCacheLastInteractive( const PoolItem & citem_r ); private: DefaultIntegral _dbgChanges; - const_iterator _commitListEnd; - IMediaKey _lastInteractive; + IMediaKey _lastInteractive; Pathname _rootDir; shared_ptr _cacheDir; -- 2.7.4