Fix retrieval of Repository attributes like timestamps, keywords and product info.
authorMichael Andres <ma@suse.de>
Thu, 20 Nov 2008 21:20:26 +0000 (21:20 +0000)
committerMichael Andres <ma@suse.de>
Thu, 20 Nov 2008 21:20:26 +0000 (21:20 +0000)
package/libzypp.changes
zypp/Repository.cc
zypp/Repository.h

index 9cdd7e2..5254c5a 100644 (file)
@@ -1,4 +1,11 @@
 -------------------------------------------------------------------
+Thu Nov 20 22:15:28 CET 2008 - ma@suse.de
+
+- Fix retrieval of Repository attributes like timestamps, keywords
+  and product info.
+- revision 11760
+
+-------------------------------------------------------------------
 Thu Nov 20 19:30:05 CET 2008 - ma@suse.de
 
 - Enhance class LookupAttr and add convenience class LookupRepoAttr to
index 68f2dc6..9a1278a 100644 (file)
@@ -54,142 +54,125 @@ namespace zypp
 
     std::string Repository::alias() const
     {
-       NO_REPOSITORY_RETURN( std::string() );
-       if ( ! _repo->name )
-           return std::string();
-       return _repo->name;
+      NO_REPOSITORY_RETURN( std::string() );
+      if ( ! _repo->name )
+        return std::string();
+      return _repo->name;
     }
 
-#warning FIX to iterator
     zypp::Date Repository::generatedTimestamp() const
     {
-        ::Dataiterator di;
-        ::dataiterator_init(&di, sat::Pool::instance().get(), get(), SOLVID_META, REPOSITORY_TIMESTAMP, 0, 0);
-        if (::dataiterator_step(&di))
-        {
-            do
-            {
-                switch (di.key->name)
-                {
-                    case REPOSITORY_TIMESTAMP:
-                    {
-                        return di.kv.num;
-                        break;
-                    }
-                }
-            }
-            while (::dataiterator_step(&di));
-      }
-      else
-      {
-          if ( isSystemRepo() )
-            return 0;
-          ERR << "the attribute generated timestamp does not exist in the repo" << endl;
-      }
-
-      return Date();
+      NO_REPOSITORY_RETURN( 0 );
+      sat::LookupRepoAttr q( sat::SolvAttr::repositoryTimestamp, *this );
+      return( q.empty() ? 0 : q.begin().asUnsigned() );
     }
 
-
     zypp::Date Repository::suggestedExpirationTimestamp() const
     {
-        ::Dataiterator di;
-        ::dataiterator_init(&di, sat::Pool::instance().get(), get(), SOLVID_META, REPOSITORY_EXPIRE, 0, 0);
-        Date generated = generatedTimestamp();
-        // do not calculate over a missing generated
-        // timestamp
-        if ( generated == Date() )
-            return Date();
-
-        if (::dataiterator_step(&di))
-        {
-            do
-            {
-                switch (di.key->name)
-                {
-                    case REPOSITORY_EXPIRE:
-                    {
-                        return generated + di.kv.num;
-                        break;
-                    }
-                }
-            }
-            while (::dataiterator_step(&di));
-      }
-      else
-      {
-        if ( isSystemRepo() )
-            return 0;
-        ERR << "the attribute suggested expiration timestamp does not exist in the repo" << endl;
-      }
+      NO_REPOSITORY_RETURN( 0 );
+      Date generated = generatedTimestamp();
+      if ( ! generated )
+        return 0; // do not calculate over a missing generated timestamp
+
+      sat::LookupRepoAttr q( sat::SolvAttr::repositoryExpire, *this );
+      if ( q.empty() )
+        return 0;
 
-      return Date();
+      return generated + q.begin().asUnsigned();
     }
 
     Repository::Keywords Repository::keywords() const
-    { return Keywords(sat::SolvAttr::repositoryKeywords); }
+    {
+      NO_REPOSITORY_RETURN( Keywords() );
+      return Keywords( sat::SolvAttr::repositoryKeywords, *this, sat::LookupAttr::REPO_ATTR );
+    }
 
     bool Repository::maybeOutdated() const
     {
-        // system repo is not mirrored
-        if ( isSystemRepo() )
-            return false;
+      NO_REPOSITORY_RETURN( false );
+      // system repo is not mirrored
+      if ( isSystemRepo() )
+        return false;
 
-        Date suggested = suggestedExpirationTimestamp();
+      Date suggested = suggestedExpirationTimestamp();
 
-        // if no data, don't suggest
-        if ( suggested == Date() )
-            return false;
+      // if no data, don't suggest
+      if ( ! suggested )
+        return false;
 
-        return suggestedExpirationTimestamp() < Date::now();
+      return suggestedExpirationTimestamp() < Date::now();
     }
 
     bool Repository::providesUpdatesFor( const std::string &key ) const
     {
-        return false;
+      NO_REPOSITORY_RETURN( false );
+      return false;
     }
 
     bool Repository::isUpdateRepo() const
     {
-        return false;
+      NO_REPOSITORY_RETURN( false );
+      return false;
     }
 
     bool Repository::solvablesEmpty() const
     {
-       NO_REPOSITORY_RETURN( true );
-       return !_repo->nsolvables;
+      NO_REPOSITORY_RETURN( true );
+      return !_repo->nsolvables;
     }
 
     Repository::size_type Repository::solvablesSize() const
     {
-       NO_REPOSITORY_RETURN( 0 );
-       return _repo->nsolvables;
+      NO_REPOSITORY_RETURN( 0 );
+      return _repo->nsolvables;
     }
 
     Repository::SolvableIterator Repository::solvablesBegin() const
     {
-       NO_REPOSITORY_RETURN( make_filter_iterator( detail::ByRepository( *this ),
-                                             sat::detail::SolvableIterator(),
-                                             sat::detail::SolvableIterator() ) );
-       return make_filter_iterator( detail::ByRepository( *this ),
-                                    sat::detail::SolvableIterator(_repo->start),
-                                    sat::detail::SolvableIterator(_repo->end) );
+      NO_REPOSITORY_RETURN( make_filter_iterator( detail::ByRepository( *this ),
+                            sat::detail::SolvableIterator(),
+                            sat::detail::SolvableIterator() ) );
+      return make_filter_iterator( detail::ByRepository( *this ),
+                                   sat::detail::SolvableIterator(_repo->start),
+                                   sat::detail::SolvableIterator(_repo->end) );
     }
 
     Repository::SolvableIterator Repository::solvablesEnd() const
     {
-       NO_REPOSITORY_RETURN( make_filter_iterator( detail::ByRepository( *this ),
-                                             sat::detail::SolvableIterator(),
-                                             sat::detail::SolvableIterator() ) );
-       return make_filter_iterator(detail::ByRepository( *this ),
-                                   sat::detail::SolvableIterator(_repo->end),
-                                   sat::detail::SolvableIterator(_repo->end) );
+      NO_REPOSITORY_RETURN( make_filter_iterator( detail::ByRepository( *this ),
+                            sat::detail::SolvableIterator(),
+                            sat::detail::SolvableIterator() ) );
+      return make_filter_iterator(detail::ByRepository( *this ),
+                                  sat::detail::SolvableIterator(_repo->end),
+                                  sat::detail::SolvableIterator(_repo->end) );
+    }
+
+    Repository::ProductInfoIterator Repository::compatibleWithProductBegin() const
+    {
+      NO_REPOSITORY_RETURN( ProductInfoIterator() );
+      return ProductInfoIterator( sat::SolvAttr::repositoryDistros, *this );
+    }
+
+    Repository::ProductInfoIterator Repository::compatibleWithProductEnd() const
+    {
+      return ProductInfoIterator();
+    }
+
+    Repository::ProductInfoIterator Repository::updatesProductBegin() const
+    {
+      NO_REPOSITORY_RETURN( ProductInfoIterator() );
+      return ProductInfoIterator( sat::SolvAttr::repositoryUpdates, *this );
+    }
+
+    Repository::ProductInfoIterator Repository::updatesProductEnd() const
+    {
+      return ProductInfoIterator();
     }
 
     RepoInfo Repository::info() const
     {
-       NO_REPOSITORY_RETURN( RepoInfo() );
-       return myPool().repoInfo( _repo );
+      NO_REPOSITORY_RETURN( RepoInfo() );
+      return myPool().repoInfo( _repo );
     }
 
     void Repository::setInfo( const RepoInfo & info_r )
@@ -283,17 +266,6 @@ namespace zypp
        return myPool()._addSolvables( _repo, count_r );
     }
 
-#if 0
-    Repository::ProductInfoIterator::ProductInfoIterator( const sat::Solvable & val_r,
-                                                          const sat::SolvAttr & arrayid )
-    { base_reference() = sat::LookupAttr( arrayid, val_r ).begin(); }
-
-    std::string Repository::ProductInfoIterator::label() const
-    { return base_reference().subFind( sat::SolvAttr::repositoryProductLabel ).asString(); }
-    std::string Repository::ProductInfoIterator::cpeId() const
-    { return base_reference().subFind( sat::SolvAttr::repositoryProductCpeid ).asString(); }
-#endif
-
     /******************************************************************
      **
      **        FUNCTION NAME : operator<<
@@ -308,9 +280,23 @@ namespace zypp
                   << "{"
                    << "prio " << obj.get()->priority
                   << ", size " << obj.solvablesSize()
-                  <<"}";
+                  << "}";
     }
 
+    ///////////////////////////////////////////////////////////////////
+    //
+    // Repository::ProductInfoIterator
+    //
+    ///////////////////////////////////////////////////////////////////
+
+    Repository::ProductInfoIterator::ProductInfoIterator( sat::SolvAttr attr_r, Repository repo_r )
+    { base_reference() = sat::LookupRepoAttr( attr_r, repo_r ).begin(); }
+
+    std::string Repository::ProductInfoIterator::label() const
+    { return base_reference().subFind( sat::SolvAttr::repositoryProductLabel ).asString(); }
+
+    std::string Repository::ProductInfoIterator::cpeId() const
+    { return base_reference().subFind( sat::SolvAttr::repositoryProductCpeid ).asString(); }
 
     /////////////////////////////////////////////////////////////////
 } // namespace zypp
index bbda002..0fbf9e7 100644 (file)
@@ -42,9 +42,8 @@ namespace zypp
         typedef filter_iterator<detail::ByRepository, sat::detail::SolvableIterator> SolvableIterator;
         typedef sat::detail::size_type size_type;
         typedef sat::detail::RepoIdType IdType;
-        typedef sat::ArrayAttr<std::string,std::string> UpdateKeys;
+
         typedef sat::ArrayAttr<std::string,std::string> Keywords;
-        typedef sat::ArrayAttr<std::string,std::string> Products;
 
     public:
         /** Default ctor creates \ref noRepository.*/
@@ -97,7 +96,7 @@ namespace zypp
          * specify when it was generated.
          *
          */
-        zypp::Date generatedTimestamp() const;
+        Date generatedTimestamp() const;
 
         /**
          * Suggested expiration timestamp.
@@ -115,7 +114,7 @@ namespace zypp
          * an expiration date.
          *
          */
-        zypp::Date suggestedExpirationTimestamp() const;
+        Date suggestedExpirationTimestamp() const;
 
         /**
          * repository keywords (tags)
@@ -276,7 +275,7 @@ namespace zypp
     inline bool operator<( const Repository & lhs, const Repository & rhs )
     { return lhs.get() < rhs.get(); }
 
-
+    ///////////////////////////////////////////////////////////////////
     /**
      * Query class for Repository related products
      *
@@ -286,9 +285,7 @@ namespace zypp
      * directly from the iterator.
      *
      * \code
-     * for ( Repository::ProductInfoIterator it = repo->compatibleWithProductBegin();
-     *       it != repo->compatibleWithProductEnd();
-     *       ++it )
+     * for_( it, repo.compatibleWithProductBegin(), repo.compatibleWithProductEnd() )
      * {
      *   cout << it.cpeid() << endl;
      * }
@@ -300,12 +297,12 @@ namespace zypp
         , sat::LookupAttr::iterator        // Base
         , int                              // Value
         , boost::forward_traversal_tag     // CategoryOrTraversal
-        , int
+        , int                              // Reference
     >
     {
       public:
-        ProductInfoIterator() {}
-        explicit ProductInfoIterator( const sat::SolvAttr & arrayid );
+        ProductInfoIterator()
+        {}
 
         /**
          * Product label
@@ -318,24 +315,18 @@ namespace zypp
          *
          * See http://cpe.mitre.org
          */
-        std::string cpeid() const;
+        std::string cpeId() const;
+
+      private:
+        friend class Repository;
+        /** Hide ctor as just a limited set of attributes is valid. */
+        explicit ProductInfoIterator( sat::SolvAttr attr_r, Repository repo_r );
 
       private:
         friend class boost::iterator_core_access;
         int dereference() const { return 0; }
     };
-
-    inline Repository::ProductInfoIterator Repository::compatibleWithProductBegin() const
-    { return ProductInfoIterator( sat::SolvAttr::repositoryDistros ); }
-
-    inline Repository::ProductInfoIterator Repository::compatibleWithProductEnd() const
-    { return ProductInfoIterator(); }
-
-    inline Repository::ProductInfoIterator Repository::updatesProductBegin() const
-    { return ProductInfoIterator( sat::SolvAttr::repositoryUpdates ); }
-
-    inline Repository::ProductInfoIterator Repository::updatesProductEnd() const
-    { return ProductInfoIterator(); }
+    ///////////////////////////////////////////////////////////////////
 
     ///////////////////////////////////////////////////////////////////
     //