- Implementation of infrastructure for
authorDuncan Mac-Vicar P <dmacvicar@suse.de>
Fri, 11 Jul 2008 16:45:47 +0000 (16:45 +0000)
committerDuncan Mac-Vicar P <dmacvicar@suse.de>
Fri, 11 Jul 2008 16:45:47 +0000 (16:45 +0000)
  feature #301904 Whole software management stack should warn about oudated update repo
  TODO: repo2solv.sh should use repomdxml2solv to insert the expire attributes
  Testcase for zypp::Repository new API.
  Use it in any application

zypp/Repository.cc
zypp/Repository.h
zypp/sat/SolvAttr.cc
zypp/sat/SolvAttr.h

index 088ed70..46470b6 100644 (file)
@@ -58,6 +58,59 @@ namespace zypp
        return _repo->name;
     }
 
+    zypp::Date Repository::generatedTimestamp() const
+    {
+        ::Dataiterator di;
+        ::dataiterator_init(&di, get(), -1, 0, 0, SEARCH_EXTRA | SEARCH_NO_STORAGE_SOLVABLE);
+        if (::dataiterator_step(&di))
+        {
+            do
+            {
+                switch (di.key->name)
+                {
+                    case REPOSITORY_TIMESTAMP:
+                    {
+                        return di.kv.num;
+                        break;
+                    }
+                }
+            }
+            while (::dataiterator_step(&di));
+      }
+      else
+        ERR << "the extra does not exist in the repo" << endl;
+    }
+    
+
+    zypp::Date Repository::expirationTimestamp() const
+    {
+        ::Dataiterator di;
+        ::dataiterator_init(&di, get(), -1, 0, 0, SEARCH_EXTRA | SEARCH_NO_STORAGE_SOLVABLE);
+        if (::dataiterator_step(&di))
+        {
+            do
+            {
+                switch (di.key->name)
+                {
+                    case REPOSITORY_EXPIRE:
+                    {
+                        return generatedTimestamp() + di.kv.num;
+                        break;
+                    }
+                }
+            }
+            while (::dataiterator_step(&di));
+      }
+      else
+        ERR << "the extra does not exist in the repo" << endl;
+    }
+
+    
+    bool Repository::maybeOutdated() const
+    {
+        return expirationTimestamp() < Date::now();
+    }
+    
     bool Repository::solvablesEmpty() const
     {
        NO_REPOSITORY_RETURN( true );
index f69baaa..ce50621 100644 (file)
 #include "zypp/sat/detail/PoolMember.h"
 #include "zypp/sat/Solvable.h"
 #include "zypp/RepoInfo.h"
+#include "zypp/Date.h"
+extern "C"
+{
+#include "satsolver/repo.h"
+}
 
 ///////////////////////////////////////////////////////////////////
 namespace zypp
@@ -83,6 +88,21 @@ namespace zypp
         ZYPP_DEPRECATED std::string name() const
         { return alias(); }
         
+        /**
+         * Timestamp when this repository was generated
+         */
+        zypp::Date generatedTimestamp() const;
+
+        /**
+         * Expiration date
+         */
+        zypp::Date expirationTimestamp() const;
+
+        /**
+         * The expiration date of this repository
+         * already passed
+         */
+        bool maybeOutdated() const;
 
         /** Whether \ref Repository contains solvables. */
         bool solvablesEmpty() const;
index 7188d57..069fad2 100644 (file)
@@ -106,6 +106,11 @@ namespace sat
   const SolvAttr SolvAttr::productOptionalurls ( PRODUCT_OPTIONALURLS );
   const SolvAttr SolvAttr::productFlags        ( PRODUCT_FLAGS );
 
+  // repository
+  const SolvAttr SolvAttr::repositoryTimestamp ( REPOSITORY_TIMESTAMP );
+  const SolvAttr SolvAttr::repositoryExpire ( REPOSITORY_EXPIRE );
+
+
 } // namespace sat
   /////////////////////////////////////////////////////////////////
 } // namespace zypp
index 2b3f94e..e338666 100644 (file)
@@ -132,6 +132,12 @@ namespace sat
       static const SolvAttr productFlags;
       //@}
 
+      /** \name repository */
+      //@{
+      static const SolvAttr repositoryTimestamp;
+      static const SolvAttr repositoryExpire;
+      //@}
+
       //@}
     public:
       /** Default ctor: \ref noAttr */