adapt to changed satsolver api
authorMichael Andres <ma@suse.de>
Wed, 14 Nov 2007 07:47:19 +0000 (07:47 +0000)
committerMichael Andres <ma@suse.de>
Wed, 14 Nov 2007 07:47:19 +0000 (07:47 +0000)
zypp/sat/Pool.cc
zypp/sat/Pool.h
zypp/sat/Repo.cc
zypp/sat/Repo.h

index 0114cf0..3c5d465 100644 (file)
 
 extern "C"
 {
-#include <stdio.h>
-#include <satsolver/repo_solv.h>
 #include <satsolver/pool.h>
 }
-#include <cstdio>
 #include <iostream>
-#include <set>
 
 #include "zypp/base/Logger.h"
 #include "zypp/base/Gettext.h"
@@ -36,12 +32,6 @@ namespace zypp
 
     ///////////////////////////////////////////////////////////////////
     //
-    // CLASS NAME : Pool
-    //
-    ///////////////////////////////////////////////////////////////////
-
-    ///////////////////////////////////////////////////////////////////
-    //
     // METHOD NAME : Pool::Pool
     // METHOD TYPE : Ctor
     //
@@ -84,32 +74,26 @@ namespace zypp
     { return SolvableIterator( _pool.solvables+_pool.nsolvables ); }
 
 
-    void Pool::t() const
+    Repo Pool::addRepo( const std::string & name_r )
     {
-      if ( _pool.nrepos )
-      {
-        SEC << (void*)(*_pool.repos)<< Repo( *_pool.repos ) << " " << (*_pool.repos)->name << std::endl;
-      }
-      else
-      {
-        SEC << "NOREPO" << std::endl;
-      }
-
+#warning Implement name check
+      return ::repo_create( &_pool, name_r.c_str() );
     }
 
-    Repo Pool::addRepoSolv( const Pathname & file_r )
+    Repo Pool::addRepoSolv( const Pathname & file_r, const std::string & name_r )
     {
-      AutoDispose<FILE*> file( ::fopen( file_r.c_str(), "r" ), ::fclose );
-      if ( file == NULL )
+      Repo repo( addRepo( name_r.empty() ? file_r.basename() : name_r ) );
+      try
       {
-        file.resetDispose();
-        return Repo();
+        repo.addSolv( file_r );
       }
-
-#warning Workaround sat-repo not doing strdup on name.
-      // simply spend a static array of reponames
-      static std::set<std::string> _reponames;
-      return ::pool_addrepo_solv( &_pool, file, _reponames.insert( file_r.asString() ).first->c_str() );
+      catch ( ... )
+      {
+#warning use RAII to avoid cleanup catch
+        ::repo_free( repo.get() );
+        throw;
+      }
+      return repo;
     }
 
     /******************************************************************
@@ -122,7 +106,6 @@ namespace zypp
       return str << "sat::pool(){"
           << obj.reposSize() << "repos|"
           << obj.solvablesSize() << "slov}";
-
     }
 
     /////////////////////////////////////////////////////////////////
index c8a5e36..93b222a 100644 (file)
@@ -18,7 +18,6 @@
 #include "zypp/base/Iterator.h"
 
 #include "zypp/AutoDispose.h"
-#include "zypp/Pathname.h"
 
 #include "zypp/sat/Repo.h"
 
@@ -56,12 +55,19 @@ namespace zypp
         SolvableIterator solvablesBegin() const;
         SolvableIterator solvablesEnd() const;
 
-        void t() const;
-
       public:
-        Repo addRepoSolv( const Pathname & file_r );
+        /** Add new empty \ref Repo named \c name_r.
+         * \throws Exception if \ref Repo with named \c name_r exists.
+         */
+        Repo addRepo( const std::string & name_r );
 
-      private:
+        /** Add new \ref Repo from solv-file.
+         * \c name_r defaults to the solvfiles basename.
+         * \throws Exception from \ref Pool::addRepo or \ref Repo::addSolv
+         */
+        Repo addRepoSolv( const Pathname & file_r, const std::string & name_r = std::string() );
+
+     private:
         /** Explicitly shared sat-pool. */
         AutoDispose< ::_Pool *> _raii;
         /** Convenient access. */
@@ -71,7 +77,50 @@ namespace zypp
 
     /** \relates Pool Stream output */
     std::ostream & operator<<( std::ostream & str, const Pool & obj );
+#if 0
+    ///////////////////////////////////////////////////////////////////
+    //
+    // CLASS NAME : TempRepo
+    //
+    /** Maintain a temporary \ref Repo.
+     * Any included temporary \ref Repo is removed from the \ref Prool
+     * upon destruction. This may ease convenient and exception safe
+     * creation of repos.
+     * \code
+     * {
+     *   TempRepo tmp( pool.addRepo( "newrepo" ) );
+     *
+     *   // Exceptions when loading Solvables into "newrepo"
+     *   // may bypass, and "newrepo" will be removed from
+     *   // the pool.
+     *
+     *   if ( keep )
+     *   {
+     *     // If you decide to keep "newrepo", simply
+     *     // clear TempRepo to prevent removal.
+     *     tmp.reset();
+     *   }
+     * }
+     * \endcode
+    */
+    class TempRepo : private base::NonCopyable
+    {
+      public:
+        TempRepo( const Repo & repo_r )
+        : _repo( repo_r )
+        {}
+
+        ~TempRepo()
+        {
+          if ( _repo )
+            _repo.
+        }
 
+      private:
+        Repo _repo;
+    };
+    ///////////////////////////////////////////////////////////////////
+#endif
     /////////////////////////////////////////////////////////////////
   } // namespace sat
   ///////////////////////////////////////////////////////////////////
index bb7b680..fde8db0 100644 (file)
@@ -13,6 +13,7 @@ extern "C"
 {
 #include <satsolver/pool.h>
 #include <satsolver/repo.h>
+#include <satsolver/repo_solv.h>
 }
 #include <iostream>
 
@@ -20,6 +21,8 @@ extern "C"
 #include "zypp/base/Gettext.h"
 #include "zypp/base/Exception.h"
 
+#include "zypp/AutoDispose.h"
+
 #include "zypp/sat/Repo.h"
 
 using std::endl;
@@ -57,6 +60,20 @@ namespace zypp
       return SolvableIterator( _repo->pool->solvables+_repo->start+_repo->nsolvables );
     }
 
+    void Repo::addSolv( const Pathname & file_r )
+    {
+#warning add ecxception in repo_add_solv
+      AutoDispose<FILE*> file( ::fopen( file_r.c_str(), "r" ), ::fclose );
+      if ( file == NULL )
+      {
+        file.resetDispose();
+        throw;
+        //return Repo();
+      }
+
+      ::repo_add_solv( _repo, file );
+    }
+
     /******************************************************************
     **
     ** FUNCTION NAME : operator<<
index e3a20e8..0597572 100644 (file)
@@ -16,6 +16,8 @@
 
 #include "zypp/base/SafeBool.h"
 
+#include "zypp/Pathname.h"
+
 #include "zypp/sat/Solvable.h"
 
 ///////////////////////////////////////////////////////////////////
@@ -59,6 +61,12 @@ namespace zypp
         SolvableIterator solvablesEnd() const;
 
       public:
+        /** Load Solvables from a solv-file.
+         * \throws Exception if loading the solv-file fails.
+         */
+        void addSolv( const Pathname & file_r );
+
+      public:
         /** Expert backdoor. */
         ::_Repo * get() const { return _repo; }
       private: