Fix CommitPackageCache to be independent of outer package sequence repesentation.
authorMichael Andres <ma@suse.de>
Tue, 12 Apr 2011 14:02:09 +0000 (16:02 +0200)
committerMichael Andres <ma@suse.de>
Tue, 31 May 2011 10:42:08 +0000 (12:42 +0200)
zypp/target/CommitPackageCache.cc
zypp/target/CommitPackageCache.h
zypp/target/CommitPackageCacheImpl.h
zypp/target/CommitPackageCacheReadAhead.cc
zypp/target/CommitPackageCacheReadAhead.h

index 87eabc7..11425c0 100644 (file)
@@ -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<sat::Solvable> commitList_r )
+    {
+      _pimpl->setCommitList( commitList_r );
+    }
+
+    ManagedFile CommitPackageCache::get( const PoolItem & citem_r )
     { return _pimpl->get( citem_r ); }
 
     /******************************************************************
index 9193747..c1c5797 100644 (file)
@@ -13,7 +13,6 @@
 #define ZYPP_TARGET_COMMITPACKAGECACHE_H
 
 #include <iosfwd>
-#include <list>
 
 #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<PoolItem>::const_iterator          const_iterator;
       typedef function<ManagedFile( const PoolItem & pi )> 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<sat::Solvable> commitList_r );
+      /** \overload */
+      template <class _Iterator>
+      void setCommitList( _Iterator begin_r, _Iterator end_r )
+      { setCommitList( std::vector<sat::Solvable>( begin_r, end_r  ) ); }
+
       /** Provide a package. */
-      ManagedFile get( const_iterator citem_r );
+      ManagedFile get( const PoolItem & citem_r );
 
     public:
       /** Implementation. */
index 584607f..41f8c1e 100644 (file)
@@ -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<sat::Solvable> 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<sat::Solvable> _commitList;
+
     private:
       PackageProvider _packageProvider;
     };
index ba6bc06..e55c082 100644 (file)
@@ -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<Package>(it->resolvable())
-               && it->status().isToBeInstalled() )
+         PoolItem pi( *it );
+          if ( IMediaKey( pi ) == _lastInteractive
+               && isKind<Package>(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 );
     }
 
 
index d8ece82..007951b 100644 (file)
@@ -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<PoolItem,ManagedFile>     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<unsigned,0> _dbgChanges;
 
-      const_iterator       _commitListEnd;
-      IMediaKey            _lastInteractive;
+      IMediaKey                      _lastInteractive;
 
       Pathname                       _rootDir;
       shared_ptr<filesystem::TmpDir> _cacheDir;