- smart refresh works both for metadata and cache.
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Mon, 18 Jun 2007 23:00:40 +0000 (23:00 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Mon, 18 Jun 2007 23:00:40 +0000 (23:00 +0000)
zypp/RepoManager.cc
zypp/RepoManager.h
zypp/cache/CacheStore.cc
zypp/cache/CacheStore.h

index 9cace8c..d7534b2 100644 (file)
@@ -257,6 +257,7 @@ namespace zypp
   {
     Pathname rawpath = rawcache_path_for_repoinfo( _pimpl->options, info );
     RepoType repokind = info.type();
+    RepoStatus status;
     switch ( repokind.toEnum() )
     {
       case RepoType::NONE_e:
@@ -271,27 +272,23 @@ namespace zypp
     {
       case RepoType::RPMMD_e :
       {
-        return RepoStatus( rawpath + "/repodata/repomd.xml");
+        status = RepoStatus( rawpath + "/repodata/repomd.xml");
       }
       break;
       case RepoType::YAST2_e :
       {
-        return RepoStatus( rawpath + "/content");
+        status = RepoStatus( rawpath + "/content");
       }
       break;
       default:
         ZYPP_THROW(RepoUnknownTypeException());
     }
-  }
-  
-  RepoStatus RepoManager::cacheStatus( const RepoInfo &info )
-  {
-    return RepoStatus();
+    return status;
   }
     
   
   void RepoManager::refreshMetadata( const RepoInfo &info,
-                                     RepoRefreshPolicy policy,
+                                     RawMetadataRefreshPolicy policy,
                                      const ProgressData::ReceiverFnc & progress )
   {
     assert_alias(info);
@@ -405,22 +402,38 @@ namespace zypp
   
   void RepoManager::buildCache( const RepoInfo &info,
                                 CacheBuildPolicy policy,
-                                const ProgressData::ReceiverFnc & progress )
+                                const ProgressData::ReceiverFnc & progressrcv )
   {
+    ProgressData progress;
+    progress.sendTo(progressrcv);
+    progress.toMin();
     assert_alias(info);
     Pathname rawpath = rawcache_path_for_repoinfo(_pimpl->options, info);
     
     cache::CacheStore store(_pimpl->options.repoCachePath);
     
+    RepoStatus raw_metadata_status = rawMetadataStatus(info);
     if ( store.isCached( info.alias() ) )
     {
-      MIL << info.alias() << " is already cached, cleaning..." << endl;
+      MIL << info.alias() << " is already cached." << endl;
       data::RecordId id = store.lookupRepository(info.alias());
+      RepoStatus cache_status = store.repositoryStatus(id);
+
+      if ( cache_status.checksum() == raw_metadata_status.checksum() )
+      {
+        MIL << info.alias() << " cache is up to date with metadata." << endl;
+        if ( policy == BuildIfNeeded ) {
+          progress.toMax();
+          return;
+        }
+        else {
+          MIL << "Build cache is forced" << endl;
+        }
+      }
       store.cleanRepository(id);
     }
     
     data::RecordId id = store.lookupOrAppendRepository(info.alias());
-    
     // do we have type?
     repo::RepoType repokind = info.type();
       
@@ -456,10 +469,11 @@ namespace zypp
       }
       
       // update timestamp and checksum
-      //store.updateRepository(id, )
+      store.updateRepositoryStatus(id, raw_metadata_status);
       
       MIL << "Commit cache.." << endl;
       store.commit();
+      progress.toMax();
   }
   
   ////////////////////////////////////////////////////////////////////////////
index 9512a4c..3f0ceae 100644 (file)
@@ -74,7 +74,7 @@ namespace zypp
    /** Dtor */
     ~RepoManager();
     
-    enum RepoRefreshPolicy
+    enum RawMetadataRefreshPolicy
     {
       RefreshIfNeeded,
       RefreshForced
@@ -114,7 +114,7 @@ namespace zypp
     * \throws Exception on unknown error.
     */
    void refreshMetadata( const RepoInfo &info,
-                         RepoRefreshPolicy policy = RefreshIfNeeded,
+                         RawMetadataRefreshPolicy policy = RefreshIfNeeded,
                          const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() );
    
    /**
index 5d6c609..b1ec784 100644 (file)
@@ -57,8 +57,6 @@ struct CacheStore::Impl
 
     insert_resolvable_in_repository_cmd.reset( new sqlite3_command( con, "insert into resolvables_repositories (resolvable_id, repository_id) values (:resolvable_id, :repository_id);" ));
 
-    update_repository_cmd.reset( new sqlite3_command( con, "update repositories set checksum=:checksum, timestamp=:timestamp where id=:repository_id;" ));
-
     select_repository_cmd.reset( new sqlite3_command( con, "select id from repositories where alias=:alias;" ));
     insert_repository_cmd.reset( new sqlite3_command( con, "insert into repositories (alias,timestamp) values (:alias, :timestamp);" ));
 
@@ -131,7 +129,6 @@ struct CacheStore::Impl
   */
   sqlite3_connection con;
 
-  sqlite3_command_ptr update_repository_cmd;
   sqlite3_command_ptr insert_resolvable_in_repository_cmd;
 
   sqlite3_command_ptr select_name_cmd;
@@ -718,14 +715,21 @@ RecordId CacheStore::lookupOrAppendFile( const Pathname &path )
   return id;
 }
 
-void CacheStore::updateRepository( const RecordId &id,
-                                   const string &checksum,
-                                   const Date &timestamp )
+void CacheStore::updateRepositoryStatus( const RecordId &id,
+                                         const RepoStatus &status )
 {
-  _pimpl->update_repository_cmd->bind(":repository_id", id);
-  _pimpl->update_repository_cmd->bind(":checksum", checksum);
-  _pimpl->update_repository_cmd->bind(":timestamp", static_cast<int>((Date::ValueType) timestamp) );
-  _pimpl->insert_repository_cmd->executenonquery();
+  sqlite3_command cmd( _pimpl->con, "update repositories set checksum=:checksum, timestamp=:timestamp where id=:repository_id;");
+  cmd.bind(":repository_id", id);
+  cmd.bind(":checksum", status.checksum());
+  cmd.bind(":timestamp", static_cast<int>((Date::ValueType) status.timestamp()) );
+  try
+  {
+    cmd.executenonquery();
+  }
+  catch ( const sqlite3x::database_error &e )
+  {
+    ZYPP_RETHROW(e);
+  }
 }
 
 RecordId CacheStore::lookupOrAppendRepository( const string &alias )
@@ -788,12 +792,14 @@ RepoStatus CacheStore::repositoryStatus( const data::RecordId &id )
     {
       status.setChecksum( reader.getstring(2) );
       status.setTimestamp( reader.getstring(3) );
+      return status;
     }
-    return status;
+    else
+      ZYPP_THROW(CacheRecordNotFoundException());
   }
   catch ( const sqlite3x::database_error &e )
   {
-    ZYPP_THROW(CacheRecordNotFoundException());
+    ZYPP_RETHROW(e);
   }
 }
 
index aeee7fe..2108d2b 100644 (file)
@@ -529,9 +529,8 @@ namespace zypp
        *
        * If the repository does not exists, nothing will happen
        */
-      void updateRepository( const data::RecordId &id,
-                             const std::string &checksum,
-                             const Date &timestamp = Date::now() );
+      void updateRepositoryStatus( const data::RecordId &id,
+                                   const RepoStatus &status );
 
       /**
        * \short Clean repository from cache