- Support loading helix files.
authorMichael Andres <ma@suse.de>
Wed, 19 Nov 2008 14:24:43 +0000 (14:24 +0000)
committerMichael Andres <ma@suse.de>
Wed, 19 Nov 2008 14:24:43 +0000 (14:24 +0000)
devel/devel.ma/Test.cc
devel/devel.ma/Tools.h
package/libzypp.changes
tests/lib/TestSetup.h
zypp/Repository.cc
zypp/Repository.h
zypp/sat/Pool.cc
zypp/sat/Pool.h
zypp/sat/detail/PoolImpl.cc
zypp/sat/detail/PoolImpl.h

index cd11d52..38513ec 100644 (file)
@@ -1,6 +1,11 @@
 #include "Tools.h"
 #include <zypp/ResObjects.h>
 
+#include "zypp/IdString.h"
+#include "zypp/Glob.h"
+
+using filesystem::Glob;
+
 /******************************************************************
 **
 **      FUNCTION NAME : main
@@ -10,22 +15,26 @@ int main( int argc, char * argv[] )
 {
   INT << "===[START]==========================================" << endl;
 
-  // https://bugzilla.novell.com/show_bug.cgi?id=442200
   Pathname mroot( "/tmp/Bb" );
   TestSetup test( mroot, Arch_x86_64 );
-  test.loadRepos();
 
-  ResPool pool( test.pool() );
-  for_( it, pool.byKindBegin<Patch>(), pool.byKindEnd<Patch>() )
+  //test.loadRepos();
+  test.loadTestcaseRepos( "/suse/ma/BUGS/153548/YaST2/solverTestcase" );
+
+  sat::Pool satpool( test.satpool() );
+  for_( it, satpool.reposBegin(), satpool.reposEnd() )
   {
-    Patch::constPtr p( (*it)->asKind<Patch>() );
-    MIL << p << endl;
-    for_( i, p->referencesBegin(), p->referencesEnd() )
-    {
-      DBG << i.href() << endl;
-    }
+    MIL << *it << endl;
   }
 
+  INT << "===[END]============================================" << endl << endl;
+  return 0;
+
+  ResPool pool( test.pool() );
+  for_( it, pool.byKindBegin<Product>(), pool.byKindEnd<Product>() )
+  {
+    MIL << *it << endl;
+  }
 
   INT << "===[END]============================================" << endl << endl;
   return 0;
index 17d734e..cb4833a 100644 (file)
@@ -42,6 +42,13 @@ using std::endl;
 
 ///////////////////////////////////////////////////////////////////
 
+template<typename T>
+void whichType( T )
+{ INT << __PRETTY_FUNCTION__ << endl; }
+template<typename T>
+void whichType()
+{ INT << __PRETTY_FUNCTION__ << endl; }
+
 void waitForInput()
 {
   int i;
index 6a6e292..9263d10 100644 (file)
@@ -1,4 +1,10 @@
 -------------------------------------------------------------------
+Wed Nov 19 15:15:14 CET 2008 - ma@suse.de
+
+- Support loading helix files.
+- revision 11719
+
+-------------------------------------------------------------------
 Tue Nov 18 18:37:30 CET 2008 - ma@suse.de
 
 - Add class filesystem::Glob to find pathnames matching a pattern
index ecae96b..8c45375 100644 (file)
@@ -12,6 +12,7 @@ using boost::unit_test::test_case;
 #include "zypp/ZYppFactory.h"
 #include "zypp/ZYpp.h"
 #include "zypp/TmpPath.h"
+#include "zypp/Glob.h"
 #include "zypp/PathInfo.h"
 #include "zypp/RepoManager.h"
 #include "zypp/Target.h"
@@ -38,6 +39,9 @@ using namespace zypp;
  *
  * BOOST_AUTO_TEST_CASE(WhatProvides)
  * {
+ *   // enabls loging fot the scope of this block:
+ *   // base::LogControl::TmpLineWriter shutUp( new log::FileLineWriter( "/tmp/YLOG" ) );
+ *
  *   TestSetup test( Arch_x86_64 );
  *   // test.loadTarget(); // initialize and load target
  *   test.loadRepo( TESTS_SRC_DIR"/data/openSUSE-11.1" );
@@ -79,7 +83,11 @@ class TestSetup
     /** Fake @System repo from Path. */
     void loadTargetRepo( const Pathname & path_r )
     { loadRepo( path_r, sat::Pool::systemRepoAlias() ); }
+    /** Fake @System repo from helix repo. */
+    void loadTargetHelix( const Pathname & path_r )
+    { loadHelix( path_r, sat::Pool::systemRepoAlias() ); }
 
+  public:
     /** Directly load repoinfo to pool. */
     void loadRepo( RepoInfo nrepo )
     {
@@ -136,6 +144,39 @@ class TestSetup
     { loadRepo( std::string( loc_r ? loc_r : "" ), alias_r ); }
 
   public:
+    /** Directly load a helix repo from some testcase.
+     * An empty alias is guessed.
+    */
+    void loadHelix( const Pathname & path_r, const std::string & alias_r = std::string() )
+    {
+      // .solv file is loaded directly using a faked RepoInfo
+      RepoInfo nrepo;
+      nrepo.setAlias( alias_r.empty() ? path_r.basename() : alias_r );
+      satpool().addRepoHelix( path_r, nrepo );
+    }
+
+    // Load repos included in a solver testcase.
+    void loadTestcaseRepos( const Pathname & path_r )
+    {
+      if ( ! filesystem::PathInfo( path_r ).isDir() )
+      {
+        ERR << "No dir " << filesystem::PathInfo( path_r ) << endl;
+        return;
+      }
+      filesystem::Glob files( path_r/"*{.xml,.xml.gz}", filesystem::Glob::_BRACE );
+      for_( it, files.begin(), files.end() )
+      {
+        std::string basename( Pathname::basename( *it ) );
+        if ( str::hasPrefix( basename, "solver-test.xml" ) )
+          continue; // master index currently unevaluated
+        if ( str::hasPrefix( basename, "solver-system.xml" ) )
+          loadTargetHelix( *it );
+        else
+          loadHelix( *it );
+      }
+    }
+
+  public:
     /** Load all enabled repos in repos.d to pool. */
     void loadRepos()
     {
index 4fafd59..93ba962 100644 (file)
@@ -258,6 +258,28 @@ namespace zypp
       MIL << *this << " after adding " << file_r << endl;
     }
 
+    void Repository::addHelix( const Pathname & file_r )
+    {
+      NO_REPOSITORY_THROW( Exception( "Can't add solvables to norepo." ) );
+
+      std::string command( file_r.extension() == ".gz" ? "zcat " : "cat " );
+      command += file_r.asString();
+
+      AutoDispose<FILE*> file( ::popen( command.c_str(), "r" ), ::pclose );
+      if ( file == NULL )
+      {
+        file.resetDispose();
+        ZYPP_THROW( Exception( "Can't open helix-file: "+file_r.asString() ) );
+      }
+
+      if ( myPool()._addHelix( _repo, file ) != 0 )
+      {
+        ZYPP_THROW( Exception( "Error reading helix-file: "+file_r.asString() ) );
+      }
+
+      MIL << *this << " after adding " << file_r << endl;
+    }
+
     sat::detail::SolvableIdType Repository::addSolvables( unsigned count_r )
     {
        NO_REPOSITORY_THROW( Exception( "Can't add solvables to norepo.") );
index 0bbaec0..ba59269 100644 (file)
@@ -211,7 +211,16 @@ namespace zypp
          */
         void addSolv( const Pathname & file_r );
 
-        /** Add \c count_r new empty \ref Solvable to this \ref Repository. */
+         /** Load \ref Solvables from a helix-file.
+         * Supports loading of gzip compressed files (.gz). In case of an exception
+         * the repository remains in the \ref Pool.
+         * \throws Exception if this is \ref noRepository
+         * \throws Exception if loading the helix-file fails.
+         * \see \ref Pool::addRepoHelix and \ref Repository::EraseFromPool
+         */
+        void addHelix( const Pathname & file_r );
+
+       /** Add \c count_r new empty \ref Solvable to this \ref Repository. */
         sat::Solvable::IdType addSolvables( unsigned count_r );
         /** \overload Add only one new \ref Solvable. */
         sat::Solvable::IdType addSolvable()
index cd8ec4c..a710aae 100644 (file)
@@ -160,6 +160,30 @@ namespace zypp
 
     /////////////////////////////////////////////////////////////////
 
+    Repository Pool::addRepoHelix( const Pathname & file_r, const std::string & alias_r )
+    {
+      // Using a temporay repo! (The additional parenthesis are required.)
+      AutoDispose<Repository> tmprepo( (Repository::EraseFromPool()) );
+      *tmprepo = reposInsert( alias_r );
+      tmprepo->addHelix( file_r );
+
+      // no exceptions so we keep it:
+      tmprepo.resetDispose();
+      return tmprepo;
+    }
+
+    Repository Pool::addRepoHelix( const Pathname & file_r )
+    { return addRepoHelix( file_r, file_r.basename() ); }
+
+    Repository Pool::addRepoHelix( const Pathname & file_r, const RepoInfo & info_r )
+    {
+      Repository ret( addRepoHelix( file_r, info_r.alias() ) );
+      ret.setInfo( info_r );
+      return ret;
+    }
+
+   /////////////////////////////////////////////////////////////////
+
     void Pool::setRequestedLocales( const LocaleSet & locales_r )
     { myPool().setRequestedLocales( locales_r ); }
 
index b6f14d2..a1bd62a 100644 (file)
@@ -120,6 +120,21 @@ namespace zypp
         Repository addRepoSolv( const Pathname & file_r, const RepoInfo & info_r );
 
       public:
+        /** Load \ref Solvables from a helix-file into a \ref Repository named \c name_r.
+         * Supports loading of gzip compressed files (.gz). In case of an exception
+         * the \ref Repository is removed from the \ref Pool.
+         * \throws Exception if loading the helix-file fails.
+         * \see \ref Repository::EraseFromPool
+        */
+        Repository addRepoHelix( const Pathname & file_r, const std::string & name_r );
+        /** \overload Using the files basename as \ref Repository name. */
+        Repository addRepoHelix( const Pathname & file_r );
+        /** \overload Using the \ref RepoInfo::alias \ref Repo name.
+         * Additionally stores the \ref RepoInfo. \See \ref Prool::setInfo.
+        */
+        Repository addRepoHelix( const Pathname & file_r, const RepoInfo & info_r );
+
+      public:
         /** Whether \ref Pool contains solvables. */
         bool solvablesEmpty() const;
 
index 967a096..7edee32 100644 (file)
@@ -260,17 +260,32 @@ namespace zypp
       int PoolImpl::_addSolv( ::_Repo * repo_r, FILE * file_r )
       {
         setDirty(__FUNCTION__, repo_r->name );
-        int ret = ::repo_add_solv( repo_r , file_r  );
-        if ( ret == 0 && ! isSystemRepo( repo_r ) )
+        int ret = ::repo_add_solv( repo_r , file_r );
+        if ( ret == 0 )
+          _postRepoAdd( repo_r );
+        return ret;
+      }
+
+      int PoolImpl::_addHelix( ::_Repo * repo_r, FILE * file_r )
+      {
+        setDirty(__FUNCTION__, repo_r->name );
+        ::repo_add_helix( repo_r , file_r, 0 ); // unfortunately void
+        _postRepoAdd( repo_r );
+        return 0;
+      }
+
+      void PoolImpl::_postRepoAdd( ::_Repo * repo_r )
+      {
+        if ( ! isSystemRepo( repo_r ) )
         {
-          // Filter out unwanted archs
+            // Filter out unwanted archs
           std::set<detail::IdType> sysids;
           {
             Arch::CompatSet sysarchs( Arch::compatSet( ZConfig::instance().systemArchitecture() ) );
             for_( it, sysarchs.begin(), sysarchs.end() )
-              sysids.insert( it->id() );
+              sysids.insert( it->id() );
 
-            // unfortunately satsolver treats src/nosrc as architecture:
+              // unfortunately satsolver treats src/nosrc as architecture:
             sysids.insert( ARCH_SRC );
             sysids.insert( ARCH_NOSRC );
           }
@@ -279,29 +294,28 @@ namespace zypp
           unsigned       blockSize  = 0;
           for ( detail::IdType i = repo_r->start; i < repo_r->end; ++i )
           {
-            ::_Solvable * s( _pool->solvables + i );
-            if ( s->repo == repo_r && sysids.find( s->arch ) == sysids.end() )
-            {
-              // Remember an unwanted arch entry:
-              if ( ! blockBegin )
-                blockBegin = i;
-              ++blockSize;
-            }
-            else if ( blockSize )
-            {
-              // Free remembered entries
-              ::repo_free_solvable_block( repo_r, blockBegin, blockSize, /*reuseids*/false );
-              blockBegin = blockSize = 0;
-            }
+              ::_Solvable * s( _pool->solvables + i );
+              if ( s->repo == repo_r && sysids.find( s->arch ) == sysids.end() )
+              {
+                // Remember an unwanted arch entry:
+                if ( ! blockBegin )
+                  blockBegin = i;
+                ++blockSize;
+              }
+              else if ( blockSize )
+              {
+                // Free remembered entries
+                  ::repo_free_solvable_block( repo_r, blockBegin, blockSize, /*reuseids*/false );
+                  blockBegin = blockSize = 0;
+              }
           }
           if ( blockSize )
           {
-            // Free remembered entries
-            ::repo_free_solvable_block( repo_r, blockBegin, blockSize, /*reuseids*/false );
-            blockBegin = blockSize = 0;
+              // Free remembered entries
+              ::repo_free_solvable_block( repo_r, blockBegin, blockSize, /*reuseids*/false );
+              blockBegin = blockSize = 0;
           }
         }
-        return ret;
       }
 
       detail::SolvableIdType PoolImpl::_addSolvables( ::_Repo * repo_r, unsigned count_r )
index 2bbd6d1..da83ecd 100644 (file)
@@ -18,6 +18,7 @@ extern "C"
 #include <satsolver/solvable.h>
 #include <satsolver/poolarch.h>
 #include <satsolver/repo_solv.h>
+#include <satsolver/repo_helix.h>
 }
 #include <iosfwd>
 
@@ -109,10 +110,19 @@ namespace zypp
           */
           int _addSolv( ::_Repo * repo_r, FILE * file_r );
 
+          /** Adding helix file to a repo.
+           * Except for \c isSystemRepo_r, solvables of incompatible architecture
+           * are filtered out.
+          */
+          int _addHelix( ::_Repo * repo_r, FILE * file_r );
+
           /** Adding Solvables to a repo. */
           detail::SolvableIdType _addSolvables( ::_Repo * repo_r, unsigned count_r );
           //@}
 
+          /** Helper postprocessing the repo aftr adding solv or helix files. */
+          void _postRepoAdd( ::_Repo * repo_r );
+
         public:
           /** a \c valid \ref Solvable has a non NULL repo pointer. */
           bool validSolvable( const ::_Solvable & slv_r ) const