- support for configurable refresh delay (first part) (FATE #301991)
authorJan Kupec <jkupec@suse.cz>
Wed, 15 Aug 2007 08:02:11 +0000 (08:02 +0000)
committerJan Kupec <jkupec@suse.cz>
Wed, 15 Aug 2007 08:02:11 +0000 (08:02 +0000)
- repo.refresh.delay=<minutes> added to ZConfig, main section

zypp/RepoManager.cc
zypp/ZConfig.cc
zypp/ZConfig.h

index 1fcd695..e17a726 100644 (file)
@@ -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 ) );
 
index f83c88f..928f1fe 100644 (file)
@@ -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;
index 533b7de..98cd3f5 100644 (file)
@@ -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