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"
///////////////////////////////////////////////////////////////////
//
- // CLASS NAME : Pool
- //
- ///////////////////////////////////////////////////////////////////
-
- ///////////////////////////////////////////////////////////////////
- //
// METHOD NAME : Pool::Pool
// METHOD TYPE : Ctor
//
{ 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;
}
/******************************************************************
return str << "sat::pool(){"
<< obj.reposSize() << "repos|"
<< obj.solvablesSize() << "slov}";
-
}
/////////////////////////////////////////////////////////////////
#include "zypp/base/Iterator.h"
#include "zypp/AutoDispose.h"
-#include "zypp/Pathname.h"
#include "zypp/sat/Repo.h"
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. */
/** \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
///////////////////////////////////////////////////////////////////
{
#include <satsolver/pool.h>
#include <satsolver/repo.h>
+#include <satsolver/repo_solv.h>
}
#include <iostream>
#include "zypp/base/Gettext.h"
#include "zypp/base/Exception.h"
+#include "zypp/AutoDispose.h"
+
#include "zypp/sat/Repo.h"
using std::endl;
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<<
#include "zypp/base/SafeBool.h"
+#include "zypp/Pathname.h"
+
#include "zypp/sat/Solvable.h"
///////////////////////////////////////////////////////////////////
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: