From 7ccbcd786274172a5c501159c6dc933a2dd5fcc0 Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Mon, 18 Jun 2007 23:00:40 +0000 Subject: [PATCH] - smart refresh works both for metadata and cache. --- zypp/RepoManager.cc | 38 ++++++++++++++++++++++++++------------ zypp/RepoManager.h | 4 ++-- zypp/cache/CacheStore.cc | 30 ++++++++++++++++++------------ zypp/cache/CacheStore.h | 5 ++--- 4 files changed, 48 insertions(+), 29 deletions(-) diff --git a/zypp/RepoManager.cc b/zypp/RepoManager.cc index 9cace8c..d7534b2 100644 --- a/zypp/RepoManager.cc +++ b/zypp/RepoManager.cc @@ -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(); } //////////////////////////////////////////////////////////////////////////// diff --git a/zypp/RepoManager.h b/zypp/RepoManager.h index 9512a4c..3f0ceae 100644 --- a/zypp/RepoManager.h +++ b/zypp/RepoManager.h @@ -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() ); /** diff --git a/zypp/cache/CacheStore.cc b/zypp/cache/CacheStore.cc index 5d6c609..b1ec784 100644 --- a/zypp/cache/CacheStore.cc +++ b/zypp/cache/CacheStore.cc @@ -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 ×tamp ) +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((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((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); } } diff --git a/zypp/cache/CacheStore.h b/zypp/cache/CacheStore.h index aeee7fe..2108d2b 100644 --- a/zypp/cache/CacheStore.h +++ b/zypp/cache/CacheStore.h @@ -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 ×tamp = Date::now() ); + void updateRepositoryStatus( const data::RecordId &id, + const RepoStatus &status ); /** * \short Clean repository from cache -- 2.7.4