From e72159d05f10e69c2d1142d0e3ceec7977b96b36 Mon Sep 17 00:00:00 2001 From: Jan Kupec Date: Wed, 15 Aug 2007 08:02:11 +0000 Subject: [PATCH] - support for configurable refresh delay (first part) (FATE #301991) - repo.refresh.delay= added to ZConfig, main section --- zypp/RepoManager.cc | 24 +++++++++++++++++++++++- zypp/ZConfig.cc | 19 +++++++++++++++---- zypp/ZConfig.h | 7 ++++++- 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/zypp/RepoManager.cc b/zypp/RepoManager.cc index 1fcd695..e17a726 100644 --- a/zypp/RepoManager.cc +++ b/zypp/RepoManager.cc @@ -376,7 +376,29 @@ namespace zypp Pathname rawpath = rawcache_path_for_repoinfo( _pimpl->options, info ); filesystem::assert_dir(rawpath); oldstatus = metadataStatus(info); - + + // now we've got the old (cached) status, we can decide repo.refresh.delay + if (policy != RefreshForced) + { + // difference in seconds + double diff = difftime( + (Date::ValueType)Date::now(), + (Date::ValueType)oldstatus.timestamp()) / 60; + + DBG << "oldstatus: " << (Date::ValueType)oldstatus.timestamp() << endl; + DBG << "current time: " << (Date::ValueType)Date::now() << endl; + DBG << "last refresh = " << diff << " minutes ago" << endl; + + if (diff < ZConfig::instance().repo_refresh_delay()) + { + MIL << "Repository '" << info.alias() + << "' has been refreshed less than repo.refresh.delay (" + << ZConfig::instance().repo_refresh_delay() + << ") minutes ago. Advising to skip refresh" << endl; + return false; + } + } + // create temp dir as sibling of rawpath filesystem::TmpDir tmpdir( filesystem::TmpDir::makeSibling( rawpath ) ); diff --git a/zypp/ZConfig.cc b/zypp/ZConfig.cc index f83c88f..928f1fe 100644 --- a/zypp/ZConfig.cc +++ b/zypp/ZConfig.cc @@ -36,8 +36,9 @@ namespace zypp { public: Impl() - : repo_add_probe(false) - , autolock_untrustedvendor(false) + : repo_add_probe(false), + repo_refresh_delay(0), + autolock_untrustedvendor(false) { MIL << "ZConfig singleton created." << endl; Pathname confpath("/etc/zypp/zypp.conf"); @@ -63,7 +64,7 @@ namespace zypp { string entry(it->first); string value(it->second); - //MIL << (*it).first << endl; + // DBG << (*it).first << "=" << (*it).second << endl; if ( section == "main" ) { if ( entry == "arch" ) @@ -86,6 +87,10 @@ namespace zypp { repo_add_probe = (value == "1"); } + else if ( entry == "repo.refresh.delay" ) + { + str::strtonum(value, repo_refresh_delay); + } } else if ( section == "locking" ) { @@ -110,6 +115,7 @@ namespace zypp Pathname cfg_known_repos_path; bool repo_add_probe; + unsigned repo_refresh_delay; // [locking] bool autolock_untrustedvendor; @@ -199,7 +205,12 @@ namespace zypp { return _pimpl->repo_add_probe; } - + + unsigned ZConfig::repo_refresh_delay() const + { + return _pimpl->repo_refresh_delay; + } + bool ZConfig::autolock_untrustedvendor() const { return _pimpl->autolock_untrustedvendor; diff --git a/zypp/ZConfig.h b/zypp/ZConfig.h index 533b7de..98cd3f5 100644 --- a/zypp/ZConfig.h +++ b/zypp/ZConfig.h @@ -79,7 +79,12 @@ namespace zypp * repo.add.probe */ bool repo_add_probe() const; - + + /** + * Amount of time in minutes that must pass before another refresh. + */ + unsigned repo_refresh_delay() const; + /** * Whether untrusted vendor should be autolocked / config option -- 2.7.4