- Enhance class LookupAttr and add convenience class LookupRepoAttr to
authorMichael Andres <ma@suse.de>
Thu, 20 Nov 2008 18:34:39 +0000 (18:34 +0000)
committerMichael Andres <ma@suse.de>
Thu, 20 Nov 2008 18:34:39 +0000 (18:34 +0000)
  iterate those solv file attributes which are not acssociated with a
  solvable. E.g. product or deltarpm info.

devel/devel.ma/Iorder.cc
devel/devel.ma/Test.cc
package/libzypp.changes
zypp/sat/LookupAttr.cc
zypp/sat/LookupAttr.h
zypp/sat/SolvAttr.cc
zypp/sat/SolvAttr.h

index a310fca..960ef82 100644 (file)
@@ -14,6 +14,7 @@ bool upgrade()
   if ( ! rres )
   {
     ERR << "upgrade " << rres << endl;
+    getZYpp()->resolver()->problems();
     return false;
   }
   MIL << "upgrade " << rres << endl;
@@ -30,6 +31,7 @@ bool solve()
   if ( ! rres )
   {
     ERR << "resolve " << rres << endl;
+    getZYpp()->resolver()->problems();
     return false;
   }
   MIL << "resolve " << rres << endl;
index 3cc44a6..73d8fb7 100644 (file)
@@ -1,40 +1,7 @@
 #include "Tools.h"
 #include <zypp/ResObjects.h>
 
-#include "zypp/pool/GetResolvablesToInsDel.h"
-
-bool upgrade()
-{
-  bool rres = false;
-  {
-    zypp::base::LogControl::TmpLineWriter shutUp;
-    UpgradeStatistics u;
-    rres = getZYpp()->resolver()->doUpgrade( u );
-  }
-  if ( ! rres )
-  {
-    ERR << "upgrade " << rres << endl;
-    return false;
-  }
-  MIL << "upgrade " << rres << endl;
-  return true;
-}
-
-bool solve()
-{
-  bool rres = false;
-  {
-    //zypp::base::LogControl::TmpLineWriter shutUp;
-    rres = getZYpp()->resolver()->resolvePool();
-  }
-  if ( ! rres )
-  {
-    ERR << "resolve " << rres << endl;
-    return false;
-  }
-  MIL << "resolve " << rres << endl;
-  return true;
-}
+#include <zypp/sat/LookupAttr.h>
 
 /******************************************************************
 **
@@ -46,60 +13,16 @@ int main( int argc, char * argv[] )
   INT << "===[START]==========================================" << endl;
 
   Pathname mroot( "/tmp/Bb" );
-  TestSetup test( mroot, Arch_ppc64 );
-  test.loadTarget();
-  test.loadTestcaseRepos( "/suse/ma/BUGS/439802/bug439802/YaST2/solverTestcase" );
-
-  //getPi<>( "", "", Edition(""), Arch("") );
-  getPi<Product>( "SUSE_SLES", Edition("11"), Arch("ppc64") ).status().setTransact( true, ResStatus::USER );
-  getPi<Package>( "sles-release", Edition("11-54.3"), Arch("ppc64") ).status().setTransact( true, ResStatus::USER );
-
-  ResPool pool( test.pool() );
-  vdumpPoolStats( USR << "Transacting:"<< endl,
-                  make_filter_begin<resfilter::ByTransact>(pool),
-                  make_filter_end<resfilter::ByTransact>(pool) ) << endl;
-  upgrade();
-  vdumpPoolStats( USR << "Transacting:"<< endl,
-                  make_filter_begin<resfilter::ByTransact>(pool),
-                  make_filter_end<resfilter::ByTransact>(pool) ) << endl;
-
-  pool::GetResolvablesToInsDel collect( pool, pool::GetResolvablesToInsDel::ORDER_BY_MEDIANR );
-  MIL << "GetResolvablesToInsDel:" << endl << collect << endl;
-  if ( 1 )
-  {
-    // Collect until the 1st package from an unwanted media occurs.
-    // Further collection could violate install order.
-    bool hitUnwantedMedia = false;
-    typedef pool::GetResolvablesToInsDel::PoolItemList PoolItemList;
-    PoolItemList::iterator fst=collect._toInstall.end();
-    for ( PoolItemList::iterator it = collect._toInstall.begin(); it != collect._toInstall.end(); ++it)
-    {
-      ResObject::constPtr res( it->resolvable() );
-
-      if ( hitUnwantedMedia
-           || ( res->mediaNr() && res->mediaNr() != 1 ) )
-      {
-        if ( !hitUnwantedMedia )
-          fst=it;
-        hitUnwantedMedia = true;
-      }
-      else
-      {
-      }
-    }
-    dumpRange( WAR << "toInstall1: " << endl,
-               collect._toInstall.begin(), fst ) << endl;
-    dumpRange( WAR << "toInstall2: " << endl,
-               fst, collect._toInstall.end() ) << endl;
-    dumpRange( ERR << "toDelete: " << endl,
-               collect._toDelete.begin(), collect._toDelete.end() ) << endl;
-  }
-  else
+  TestSetup test( mroot, Arch_x86_64 );
+  test.loadRepo( "/Local/ROOT/cache/raw/11.1-update" );
+  test.loadRepo( "/Local/ROOT/cache/raw/11.0-update" );
+
+  sat::LookupRepoAttr q( sat::SolvAttr::repositoryAddedFileProvides );
+  USR << q << endl;
+  USR << dump(q) << endl;
+  for_( it, q.begin(), q.end() )
   {
-    dumpRange( WAR << "toInstall: " << endl,
-               collect._toInstall.begin(), collect._toInstall.end() ) << endl;
-    dumpRange( ERR << "toDelete: " << endl,
-               collect._toDelete.begin(), collect._toDelete.end() ) << endl;
+    MIL << it << endl;
   }
 
   INT << "===[END]============================================" << endl << endl;
index fa07dd3..9cdd7e2 100644 (file)
@@ -1,4 +1,12 @@
 -------------------------------------------------------------------
+Thu Nov 20 19:30:05 CET 2008 - ma@suse.de
+
+- Enhance class LookupAttr and add convenience class LookupRepoAttr to
+  iterate those solv file attributes which are not acssociated with a 
+  solvable. E.g. product or deltarpm info.
+- revision 11754
+
+-------------------------------------------------------------------
 Wed Nov 19 15:49:38 CET 2008 - jkupec@suse.cz
 
 - encode user-supplied URL strings before using them in the Url object
index de7151b..1b43889 100644 (file)
@@ -30,22 +30,36 @@ namespace zypp
   namespace sat
   { /////////////////////////////////////////////////////////////////
 
+    using detail::noSolvableId;
+
     ///////////////////////////////////////////////////////////////////
     //
     // CLASS NAME : LookupAttr::Impl
     //
     ///////////////////////////////////////////////////////////////////
-
+    /**
+     * LookupAttr implememtation.
+     *
+     * Repository and Solvable must not be set at the same time!
+     *
+     * \note When looking in pool or repo, \ref Solvable \c _solv is
+     * somewhat abused to store eiter \c Id \c 0 or \c SOLVID_META, which
+     * indicates whether the dataiterator should look into solvable or
+     * repository metadata. Remember that all \ref Solvables with an
+     * \e invalid \c Id, are treated as <tt>== Solvable::noSolvable</tt>,
+     * and in a boolean context evaluate to \c false. Thus \c noSolvable
+     * may have different \c Ids.
+     */
     class LookupAttr::Impl
     {
       public:
         Impl()
         {}
-        Impl( SolvAttr attr_r )
-        : _attr( attr_r )
+        Impl( SolvAttr attr_r, Location loc_r )
+        : _attr( attr_r ), _solv( loc_r == REPO_ATTR ? SOLVID_META : noSolvableId )
         {}
-        Impl( SolvAttr attr_r, Repository repo_r )
-        : _attr( attr_r ), _repo( repo_r )
+        Impl( SolvAttr attr_r, Repository repo_r, Location loc_r )
+        : _attr( attr_r ), _repo( repo_r ), _solv( loc_r == REPO_ATTR ? SOLVID_META : noSolvableId )
         {}
         Impl( SolvAttr attr_r, Solvable solv_r )
         : _attr( attr_r ), _solv( solv_r )
@@ -62,19 +76,19 @@ namespace zypp
         bool pool() const
         { return ! (_repo || _solv); }
 
-        void setPool()
+        void setPool( Location loc_r )
         {
           _repo = Repository::noRepository;
-          _solv = Solvable::noSolvable;
+          _solv = Solvable( loc_r == REPO_ATTR ? SOLVID_META : noSolvableId );
         }
 
         Repository repo() const
         { return _repo; }
 
-        void setRepo( Repository repo_r )
+        void setRepo( Repository repo_r, Location loc_r  )
         {
           _repo = repo_r;
-          _solv = Solvable::noSolvable;
+          _solv = Solvable( loc_r == REPO_ATTR ? SOLVID_META : noSolvableId );
         }
 
         Solvable solvable() const
@@ -102,11 +116,11 @@ namespace zypp
           }
           else if ( _repo )
           {
-            ::dataiterator_init( dip.get(), sat::Pool::instance().get(),              _repo.id(),          0, _attr.id(), 0, 0 );
+            ::dataiterator_init( dip.get(), sat::Pool::instance().get(),              _repo.id(), _solv.id(), _attr.id(), 0, 0 );
           }
           else if ( ! sat::Pool::instance().reposEmpty() )
           {
-            ::dataiterator_init( dip.get(), sat::Pool::instance().get(),                       0,          0, _attr.id(), 0, 0 );
+            ::dataiterator_init( dip.get(), sat::Pool::instance().get(),                       0, _solv.id(), _attr.id(), 0, 0 );
           }
           else
             return end();
@@ -139,12 +153,12 @@ namespace zypp
       : _pimpl( new Impl )
     {}
 
-    LookupAttr::LookupAttr( SolvAttr attr_r )
-      : _pimpl( new Impl( attr_r ) )
+    LookupAttr::LookupAttr( SolvAttr attr_r, Location loc_r )
+      : _pimpl( new Impl( attr_r, loc_r ) )
     {}
 
-    LookupAttr::LookupAttr( SolvAttr attr_r, Repository repo_r )
-      : _pimpl( new Impl( attr_r, repo_r ) )
+    LookupAttr::LookupAttr( SolvAttr attr_r, Repository repo_r, Location loc_r )
+      : _pimpl( new Impl( attr_r, repo_r, loc_r ) )
     {}
 
     LookupAttr::LookupAttr( SolvAttr attr_r, Solvable solv_r )
@@ -164,14 +178,14 @@ namespace zypp
     bool LookupAttr::pool() const
     { return _pimpl->pool(); }
 
-    void LookupAttr::setPool()
-    { _pimpl->setPool(); }
+    void LookupAttr::setPool( Location loc_r )
+    { _pimpl->setPool( loc_r ); }
 
     Repository LookupAttr::repo() const
     { return _pimpl->repo(); }
 
-    void LookupAttr::setRepo( Repository repo_r )
-    { _pimpl->setRepo( repo_r ); }
+    void LookupAttr::setRepo( Repository repo_r, Location loc_r )
+    { _pimpl->setRepo( repo_r, loc_r ); }
 
     Solvable LookupAttr::solvable() const
     { return _pimpl->solvable(); }
@@ -224,6 +238,19 @@ namespace zypp
 
     ///////////////////////////////////////////////////////////////////
     //
+    // CLASS NAME : LookupRepoAttr
+    //
+    ///////////////////////////////////////////////////////////////////
+
+    LookupRepoAttr::LookupRepoAttr( SolvAttr attr_r, Repository repo_r )
+      : LookupAttr( attr_r, repo_r, REPO_ATTR )
+    {}
+
+    void LookupRepoAttr::setRepo( Repository repo_r )
+    { LookupAttr::setRepo( repo_r, REPO_ATTR ); }
+
+    ///////////////////////////////////////////////////////////////////
+    //
     // CLASS NAME : LookupAttr::iterator
     //
     ///////////////////////////////////////////////////////////////////
index c6d41d7..1d052e8 100644 (file)
@@ -44,6 +44,13 @@ namespace zypp
      * or one \ref Solvable. \ref LookupAttr builds the query,
      * \ref LookupAttr::iterator iterates over the result.
      *
+     * Per default \ref LookupAttr looks for attributes associated with
+     * a \ref Solvable. But you may also pass \ref REPO_ATTR as
+     * \ref Location argument, to lookup attributes associated with
+     * the \ref Repository (e.g. DeltaRpm information).
+     *
+     * For convenience \see \ref LookupRepoAttr.
+     *
      * Modifying the query will not affect any running
      * iterator.
      *
@@ -71,21 +78,37 @@ namespace zypp
      *    MIL << "    " << it << endl;
      *  }
      * \endcode
+     *
+     * \code
+     *  // look for a repo attribute in the pool.
+     *  sat::LookupRepoAttr q( sat::SolvAttr::repositoryAddedFileProvides );
+     *  MIL << q << ": " << endl;
+     *  for_( it, q.begin(), q.end() )
+     *  {
+     *    MIL << "    " << it << endl;
+     *  }
+     * \endcode
      */
     class LookupAttr
     {
       public:
         typedef unsigned size_type;
 
+        /** Specify the where to look for the attribule. */
+        enum Location {
+          SOLV_ATTR = 0,  //!< Search for solvable attributes (default)
+          REPO_ATTR = -1  //!< Search for repository attributes
+        };
+
       public:
         /** Default ctor finds nothing. */
         LookupAttr();
 
         /** Lookup \ref SolvAttr in \ref Pool (all repositories). */
-        explicit LookupAttr( SolvAttr attr_r );
+        explicit LookupAttr( SolvAttr attr_r, Location = SOLV_ATTR );
 
         /** Lookup \ref SolvAttr in one\ref Repository. */
-        explicit LookupAttr( SolvAttr attr_r, Repository repo_r );
+        explicit LookupAttr( SolvAttr attr_r, Repository repo_r, Location = SOLV_ATTR );
 
         /** Lookup \ref SolvAttr in one \ref Solvable. */
         LookupAttr( SolvAttr attr_r, Solvable solv_r );
@@ -131,13 +154,13 @@ namespace zypp
         bool pool() const;
 
         /** Set search in \ref Pool (all repositories). */
-        void setPool();
+        void setPool( Location = SOLV_ATTR );
 
         /** Wheter to search in one \ref Repository. */
         Repository repo() const;
 
         /** Set search in one \ref Repository. */
-        void setRepo( Repository repo_r );
+        void setRepo( Repository repo_r, Location = SOLV_ATTR );
 
         /** Wheter to search in one \ref Solvable. */
         Solvable solvable() const;
@@ -160,6 +183,52 @@ namespace zypp
 
     ///////////////////////////////////////////////////////////////////
     //
+    // CLASS NAME : LookupRepoAttr
+    //
+    /** Lightweight repositor attribute value lookup.
+     *
+     * This is just a convenience class that overloads all
+     * \ref LookupAttr methods which take a \ref LookupAttr::Location
+     * argument and sets it to \ref REPO_ATTR.
+     *
+     * \code
+     * // look for a repo attribute in the pool:
+     * sat::LookupAttr     p( sat::SolvAttr::repositoryAddedFileProvides, sat::LookupAttr::REPO_ATTR );
+     *
+     * // Equivalent but using LookupRepoAttr:
+     * sat::LookupRepoAttr q( sat::SolvAttr::repositoryAddedFileProvides );
+     * \endcode
+     *
+     * \see \ref LookupAttr
+     */
+    class LookupRepoAttr : public LookupAttr
+    {
+      public:
+        /** \copydoc LookupAttr::LookupAttr() */
+        LookupRepoAttr()
+        {}
+        /** \copydoc LookupAttr::LookupAttr(SolvAttr) */
+        explicit LookupRepoAttr( SolvAttr attr_r )
+        : LookupAttr( attr_r, REPO_ATTR )
+        {}
+        /** \copydoc LookupAttr::LookupAttr(SolvAttr,Repository) */
+        explicit LookupRepoAttr( SolvAttr attr_r, Repository repo_r );
+
+      public:
+        /** \copydoc LookupAttr::setPool */
+        void setPool()
+        { LookupAttr::setPool( REPO_ATTR ); }
+        /** \copydoc LookupAttr::setRepo */
+        void setRepo( Repository repo_r );
+      private:
+        // Hide. You can't look inside and outside Solvables at the same time.
+        using LookupAttr::solvable;
+        using LookupAttr::setSolvable;
+    };
+    ///////////////////////////////////////////////////////////////////
+
+    ///////////////////////////////////////////////////////////////////
+    //
     // CLASS NAME : LookupAttr::iterator
     //
     /** Result iterator.
index 0b6c2b9..dd8a776 100644 (file)
@@ -124,6 +124,10 @@ namespace sat
   const SolvAttr SolvAttr::repositoryProductCpeid( REPOSITORY_PRODUCT_CPEID );
   const SolvAttr SolvAttr::repositoryKeywords    ( REPOSITORY_KEYWORDS );
 
+  const SolvAttr SolvAttr::repositoryAddedFileProvides( REPOSITORY_ADDEDFILEPROVIDES );
+  const SolvAttr SolvAttr::repositoryRpmDbCookie      ( REPOSITORY_RPMDBCOOKIE );
+
+
 } // namespace sat
   /////////////////////////////////////////////////////////////////
 } // namespace zypp
index 093b023..01f0949 100644 (file)
@@ -154,6 +154,8 @@ namespace sat
       static const SolvAttr repositoryProductLabel;
       static const SolvAttr repositoryProductCpeid;
       static const SolvAttr repositoryRevision;
+      static const SolvAttr repositoryAddedFileProvides;
+      static const SolvAttr repositoryRpmDbCookie;
       //@}
 
       //@}