Author: dmacvicar
Date: Mon Jun 4 16:24:28 2007
New Revision: 5664
URL: http://svn.opensuse.org/viewcvs/zypp?rev=5664&view=rev
Log:
- Lot of RepoManager methods implemented. Workflow working
I am still getting 0 resolvables anyway... uh?
Modified:
trunk/libzypp/tests/cache/CacheStore_test.cc
trunk/libzypp/tests/zypp/RepoManager_test.cc
trunk/libzypp/zypp2/RepoInfo.cc
trunk/libzypp/zypp2/RepoInfo.h
trunk/libzypp/zypp2/RepoManager.cc
trunk/libzypp/zypp2/RepoManager.h
trunk/libzypp/zypp2/Repository.cc
trunk/libzypp/zypp2/Repository.h
trunk/libzypp/zypp2/cache/CacheStore.cpp
trunk/libzypp/zypp2/cache/CacheStore.h
trunk/libzypp/zypp2/repo/RepoException.cc
trunk/libzypp/zypp2/repo/RepoException.h
trunk/libzypp/zypp2/repo/cached/RepoImpl.cc
trunk/libzypp/zypp2/repo/cached/RepoImpl.h
Modified: trunk/libzypp/tests/cache/CacheStore_test.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/tests/cache/CacheStore_test.cc?rev=5664&r1=5663&r2=5664&view=diff
==============================================================================
--- trunk/libzypp/tests/cache/CacheStore_test.cc (original)
+++ trunk/libzypp/tests/cache/CacheStore_test.cc Mon Jun 4 16:24:28 2007
@@ -14,6 +14,7 @@
#include "zypp/capability/CapabilityImpl.h"
#include "zypp/data/ResolvableData.h"
#include "zypp2/cache/CacheStore.h"
+#include "zypp2/RepoInfo.h"
#include "zypp2/repo/cached/RepoImpl.h"
#include "zypp/Url.h"
#include "zypp/NVRA.h"
@@ -55,7 +56,7 @@
{
MIL << "now read resolvables" << endl;
- cached::RepoImpl *repositoryImpl = new cached::RepoImpl(tmpdir.path(), repository_id);
+ cached::RepoImpl *repositoryImpl = new cached::RepoImpl( RepoInfo(), tmpdir.path(), repository_id);
//RepositoryFactory factory;
//Repository_Ref repository = factory.createFrom(repositoryImpl);
repositoryImpl->createResolvables();
Modified: trunk/libzypp/tests/zypp/RepoManager_test.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/tests/zypp/RepoManager_test.cc?rev=5664&r1=5663&r2=5664&view=diff
==============================================================================
--- trunk/libzypp/tests/zypp/RepoManager_test.cc (original)
+++ trunk/libzypp/tests/zypp/RepoManager_test.cc Mon Jun 4 16:24:28 2007
@@ -9,6 +9,7 @@
#include "zypp/KeyRing.h"
#include "zypp/PublicKey.h"
#include "zypp/TmpPath.h"
+#include "zypp/ResStore.h"
#include "zypp2/RepoManager.h"
@@ -25,6 +26,7 @@
using namespace std;
using namespace zypp;
using namespace zypp::filesystem;
+using namespace zypp::repo;
void repomanager_test( const string &dir )
{
@@ -42,6 +44,24 @@
list<RepoInfo> repos = manager.knownRepositories();
BOOST_CHECK_EQUAL(repos.size(), (unsigned) 3);
+
+ RepoInfo repo(repos.front());
+ manager.refreshMetadata(repo);
+
+ Repository repository;
+ try {
+ repository = manager.createFromCache(repo);
+ }
+ catch ( const RepoNotCachedException &e )
+ {
+ ZYPP_CAUGHT(e);
+ MIL << "repo " << repo.alias() << " not cached yet. Caching..." << endl;
+ manager.buildCache(repo);
+ repository = manager.createFromCache(repo);
+ }
+
+ ResStore store = repository.resolvables();
+ MIL << store.size() << " resolvables" << endl;
}
test_suite*
Modified: trunk/libzypp/zypp2/RepoInfo.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp2/RepoInfo.cc?rev=5664&r1=5663&r2=5664&view=diff
==============================================================================
--- trunk/libzypp/zypp2/RepoInfo.cc (original)
+++ trunk/libzypp/zypp2/RepoInfo.cc Mon Jun 4 16:24:28 2007
@@ -31,12 +31,13 @@
Impl()
: enabled (indeterminate),
- autorefresh(indeterminate)
+ autorefresh(indeterminate),
+ type(repo::RepoType::NONE_e)
{}
public:
boost::tribool enabled;
boost::tribool autorefresh;
- std::string type;
+ repo::RepoType type;
Url mirrorlist_url;
std::set<Url> urls;
std::string alias;
@@ -119,7 +120,7 @@
return *this;
}
- RepoInfo & RepoInfo::setType( const std::string &t )
+ RepoInfo & RepoInfo::setType( const repo::RepoType &t )
{
_pimpl->type = t;
return *this;
@@ -143,7 +144,7 @@
std::string RepoInfo::name() const
{ return _pimpl->name; }
- std::string RepoInfo::type() const
+ repo::RepoType RepoInfo::type() const
{ return _pimpl->type; }
Url RepoInfo::mirrorListUrl() const
Modified: trunk/libzypp/zypp2/RepoInfo.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp2/RepoInfo.h?rev=5664&r1=5663&r2=5664&view=diff
==============================================================================
--- trunk/libzypp/zypp2/RepoInfo.h (original)
+++ trunk/libzypp/zypp2/RepoInfo.h Mon Jun 4 16:24:28 2007
@@ -20,6 +20,8 @@
#include
#include "zypp/Pathname.h"
#include "zypp/Url.h"
+#include "zypp2/repo/RepoType.h"
+
///////////////////////////////////////////////////////////////////
namespace zypp
@@ -122,9 +124,9 @@
/**
* Type of repository,
- * FIXME should be an enum?
+ *
*/
- std::string type() const;
+ repo::RepoType type() const;
/**
* \short Repository short label
@@ -169,7 +171,7 @@
* set the repository type \see type
* \param t
*/
- RepoInfo & setType( const std::string &t );
+ RepoInfo & setType( const repo::RepoType &t );
/**
* set the repository name \see name
Modified: trunk/libzypp/zypp2/RepoManager.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp2/RepoManager.cc?rev=5664&r1=5663&r2=5664&view=diff
==============================================================================
--- trunk/libzypp/zypp2/RepoManager.cc (original)
+++ trunk/libzypp/zypp2/RepoManager.cc Mon Jun 4 16:24:28 2007
@@ -16,17 +16,31 @@
#include "zypp/base/InputStream.h"
#include "zypp/base/Logger.h"
#include "zypp/PathInfo.h"
+#include "zypp/TmpPath.h"
#include "zypp/parser/IniDict.h"
#include "zypp2/repo/RepoException.h"
#include "zypp2/RepoManager.h"
+#include "zypp2/cache/CacheStore.h"
+#include "zypp2/repo/cached/RepoImpl.h"
+#include "zypp/MediaSetAccess.h"
+
+#include "zypp/source/yum/YUMDownloader.h"
+#include "zypp2/parser/yum/YUMParser.h"
+
+#include "zypp/source/susetags/SUSETagsDownloader.h"
+#include "zypp2/parser/susetags/RepoParser.h"
+
using namespace std;
using namespace zypp;
using namespace zypp::repo;
using namespace zypp::filesystem;
using parser::IniDict;
+using zypp::source::yum::YUMDownloader;
+using zypp::source::susetags::SUSETagsDownloader;
+
///////////////////////////////////////////////////////////////////
namespace zypp
{ /////////////////////////////////////////////////////////////////
@@ -71,7 +85,7 @@
else if ( it->first == "baseurl" )
info.addBaseUrl( Url(it->second) );
else if ( it->first == "type" )
- info.setType(it->second);
+ info.setType(repo::RepoType(it->second));
}
// add it to the list.
@@ -177,37 +191,166 @@
ZYPP_THROW(RepoNoAliasException());
}
- static Pathname rawcache_path_for_alias( const RepoManagerOptions &opt, const string &alias )
+ static void assert_urls( const RepoInfo &info )
{
- //repoRawCachePath
- return Pathname();
+ if (info.urls().empty())
+ ZYPP_THROW(RepoNoUrlException());
}
+ static Pathname rawcache_path_for_repoinfo( const RepoManagerOptions &opt, const RepoInfo &info )
+ {
+ assert_alias(info);
+ return opt.repoRawCachePath + info.alias();
+ }
+
void RepoManager::refreshMetadata( const RepoInfo &info )
{
assert_alias(info);
+ assert_urls(info);
-
+ // try urls one by one
+ for ( RepoInfo::urls_const_iterator it = info.urlsBegin(); it != info.urlsEnd(); ++it )
+ {
+ Url url(*it);
+ filesystem::TmpDir tmpdir;
+
+ repo::RepoType repokind = info.type();
+
+ // if the type is unknown, try probing.
+ switch ( repokind.toEnum() )
+ {
+ case RepoType::NONE_e:
+ // unknown, probe it
+ repokind = probe(*it);
+ break;
+ default:
+ break;
+ }
+
+ switch ( repokind.toEnum() )
+ {
+ case RepoType::RPMMD_e :
+ {
+ YUMDownloader downloader( url, "/" );
+ downloader.download(tmpdir.path());
+ // no error
+ }
+ break;
+ case RepoType::YAST2_e :
+ {
+ SUSETagsDownloader downloader( url, "/" );
+ downloader.download(tmpdir.path());
+ // no error
+ }
+ break;
+ default:
+ ZYPP_THROW(RepoUnknownTypeException());
+ }
+
+ // ok we have the metadata, now exchange
+ // the contents
+ Pathname rawpath = rawcache_path_for_repoinfo(_pimpl->options, info);
+ TmpDir oldmetadata;
+ filesystem::assert_dir(rawpath);
+ filesystem::rename( rawpath, oldmetadata.path() );
+ // move the just downloaded there
+ filesystem::rename( tmpdir.path(), rawpath );
+
+ // we are done.
+ }
}
void RepoManager::cleanMetadata( const RepoInfo &info )
{
-
+ filesystem::recursive_rmdir(rawcache_path_for_repoinfo(_pimpl->options, info));
}
void RepoManager::buildCache( const RepoInfo &info )
{
+ assert_alias(info);
+ Pathname rawpath = rawcache_path_for_repoinfo(_pimpl->options, info);
+
+ cache::CacheStore store(_pimpl->options.repoCachePath);
+
+ if ( store.isCached( info.alias() ) )
+ {
+ MIL << info.alias() << " is already cached, cleaning..." << endl;
+ data::RecordId id = store.lookupRepository(info.alias());
+ store.cleanRepository(id);
+ }
+
+ data::RecordId id = store.lookupOrAppendRepository(info.alias());
+
+ // do we have type?
+ repo::RepoType repokind = info.type();
+
+ // if the type is unknown, try probing.
+ switch ( repokind.toEnum() )
+ {
+ case RepoType::NONE_e:
+ // unknown, probe the local metadata
+ repokind = probe(Url(rawpath.asString()));
+ break;
+ default:
+ break;
+ }
+
+ switch ( repokind.toEnum() )
+ {
+ case RepoType::RPMMD_e :
+ {
+ parser::yum::YUMParser parser(id, store);
+ parser.parse(rawpath);
+ // no error
+ }
+ break;
+ case RepoType::YAST2_e :
+ {
+ parser::susetags::RepoParser parser(id, store);
+ parser.parse(rawpath);
+ // no error
+ }
+ break;
+ default:
+ ZYPP_THROW(RepoUnknownTypeException());
+ }
+
+ MIL << "Commit cache.." << endl;
+ store.commit();
+ }
+ repo::RepoType RepoManager::probe( const Url &url )
+ {
+ MediaSetAccess access(url);
+ if ( access.doesFileExist("/repodata/repomd.xml") )
+ return repo::RepoType::RPMMD;
+ if ( access.doesFileExist("/content") )
+ return repo::RepoType::YAST2;
+
+ return repo::RepoType("UNKNOWN");
}
void RepoManager::cleanCache( const RepoInfo &info )
{
-
+ cache::CacheStore store(_pimpl->options.repoCachePath);
+
+ data::RecordId id = store.lookupRepository(info.alias());
+ store.cleanRepository(id);
+ store.commit();
}
Repository RepoManager::createFromCache( const RepoInfo &info )
{
- return Repository::noRepository;
+ cache::CacheStore store(_pimpl->options.repoCachePath);
+
+ if ( ! store.isCached( info.alias() ) )
+ ZYPP_THROW(RepoNotCachedException());
+
+ MIL << "Repository " << info.alias() << " is cached" << endl;
+
+ data::RecordId id = store.lookupRepository(info.alias());
+ repo::cached::RepoImpl::Ptr repoimpl = new repo::cached::RepoImpl( info, _pimpl->options.repoCachePath, id );
+ return Repository(repoimpl);
}
/******************************************************************
Modified: trunk/libzypp/zypp2/RepoManager.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp2/RepoManager.h?rev=5664&r1=5663&r2=5664&view=diff
==============================================================================
--- trunk/libzypp/zypp2/RepoManager.h (original)
+++ trunk/libzypp/zypp2/RepoManager.h Mon Jun 4 16:24:28 2007
@@ -23,6 +23,7 @@
#include "zypp2/Repository.h"
#include "zypp2/RepoInfo.h"
#include "zypp2/repo/RepoException.h"
+#include "zypp2/repo/RepoType.h"
///////////////////////////////////////////////////////////////////
namespace zypp
@@ -73,8 +74,12 @@
*
* Will try to download the metadata
*
- * \throws RepoNoUrl if no urls are available.
- * \throws RepoNoAlias if can't figure an alias
+ * In case of falure the metadata remains
+ * as it was before.
+ *
+ * \throws RepoNoUrlException if no urls are available.
+ * \throws RepoNoAliasException if can't figure an alias
+ * \throws RepoUnknownTypeException if the metadata is unknown
* \throws Exception on unknown error.
*/
void refreshMetadata( const RepoInfo &info );
@@ -123,6 +128,14 @@
*/
Repository createFromCache( const RepoInfo &info );
+
+ /**
+ * \short Probe repo metadata type.
+ *
+ * \todo FIXME Should this be private?
+ */
+ repo::RepoType probe( const Url &url );
+
public:
private:
Modified: trunk/libzypp/zypp2/Repository.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp2/Repository.cc?rev=5664&r1=5663&r2=5664&view=diff
==============================================================================
--- trunk/libzypp/zypp2/Repository.cc (original)
+++ trunk/libzypp/zypp2/Repository.cc Mon Jun 4 16:24:28 2007
@@ -41,5 +41,10 @@
Repository::NumericId Repository::numericId() const
{ return _pimpl->numericId(); }
+ const ResStore & Repository::resolvables()
+ {
+ return _pimpl->resolvables();
+ }
+
}
Modified: trunk/libzypp/zypp2/Repository.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp2/Repository.h?rev=5664&r1=5663&r2=5664&view=diff
==============================================================================
--- trunk/libzypp/zypp2/Repository.h (original)
+++ trunk/libzypp/zypp2/Repository.h Mon Jun 4 16:24:28 2007
@@ -7,6 +7,7 @@
#include "zypp/base/PtrTypes.h"
#include "zypp/base/SafeBool.h"
+#include "zypp/ResStore.h"
namespace zypp
{
@@ -49,6 +50,9 @@
/** Runtime unique numeric Repository Id. */
NumericId numericId() const;
+
+ const ResStore & resolvables();
+
private:
friend base::SafeBool<Repository>::operator bool_type() const;
/** \ref SafeBool test. */
@@ -57,7 +61,7 @@
private:
/** Factory */
- friend class RepositoryFactory;
+ friend class RepoManager;
friend class repo::RepositoryImpl;
private:
Modified: trunk/libzypp/zypp2/cache/CacheStore.cpp
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp2/cache/CacheStore.cpp?rev=5664&r1=5663&r2=5664&view=diff
==============================================================================
--- trunk/libzypp/zypp2/cache/CacheStore.cpp (original)
+++ trunk/libzypp/zypp2/cache/CacheStore.cpp Mon Jun 4 16:24:28 2007
@@ -733,6 +733,26 @@
return static_cast<RecordId>(id);
}
+void CacheStore::cleanRepository( const data::RecordId &id )
+{
+ sqlite3_command cmd( _pimpl->con, "delete from repositories where id=:id");
+ cmd.bind(":id", id);
+
+ try
+ {
+ cmd.executenonquery();
+ }
+ catch ( const sqlite3x::database_error &e )
+ {
+ ZYPP_THROW(CacheRecordNotFoundException());
+ }
+}
+
+void CacheStore::cleanRepository( const std::string &alias )
+{
+ cleanRepository(lookupRepository(alias));
+}
+
RepoStatus CacheStore::repositoryStatus( const data::RecordId &id )
{
sqlite3_command cmd( _pimpl->con, "select id,alias,checksum,timestamp from repositories where id=:id");
@@ -770,6 +790,7 @@
{
return false;
}
+
return true;
}
Modified: trunk/libzypp/zypp2/cache/CacheStore.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp2/cache/CacheStore.h?rev=5664&r1=5663&r2=5664&view=diff
==============================================================================
--- trunk/libzypp/zypp2/cache/CacheStore.h (original)
+++ trunk/libzypp/zypp2/cache/CacheStore.h Mon Jun 4 16:24:28 2007
@@ -490,6 +490,30 @@
const Date ×tamp = Date::now() );
/**
+ * \short Clean repository from cache
+ *
+ * \param id repository identifier in cache
+ *
+ * You can check existence using \ref isCached
+ *
+ * \throws CacheRecordNotFoundException if the repository
+ * id does not refer to a valid repository.
+ */
+ void cleanRepository( const data::RecordId &id );
+
+ /**
+ * \short Clean repository from cache
+ *
+ * \param alias Repository unique alias
+ *
+ * You can check existence using \ref isCached
+ *
+ * \throws CacheRecordNotFoundException if the repository
+ * alias does not refer to a valid repository.
+ */
+ void cleanRepository( const std::string &alias );
+
+ /**
* get the status of a cached repository
*
* It is responsability of the caller to operate with
@@ -499,7 +523,7 @@
* You can check existence using \ref isCached
*
* \throws CacheRecordNotFoundException if the repository
- * id is invalid.
+ * id does not refer to a valid repository.
*/
RepoStatus repositoryStatus( const data::RecordId &id );
Modified: trunk/libzypp/zypp2/repo/RepoException.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp2/repo/RepoException.cc?rev=5664&r1=5663&r2=5664&view=diff
==============================================================================
--- trunk/libzypp/zypp2/repo/RepoException.cc (original)
+++ trunk/libzypp/zypp2/repo/RepoException.cc Mon Jun 4 16:24:28 2007
@@ -22,37 +22,29 @@
namespace repo
{ /////////////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////
- //
- // METHOD NAME : RepoException::RepoException
- // METHOD TYPE : Ctor
- //
RepoException::RepoException()
: Exception( "Repo exception" )
{}
- ///////////////////////////////////////////////////////////////////
- //
- // METHOD NAME : RepoException::RepoException
- // METHOD TYPE : Ctor
- //
RepoException::RepoException( const std::string & msg_r )
: Exception( msg_r )
{}
- ///////////////////////////////////////////////////////////////////
- //
- // METHOD NAME : RepoException::~RepoException
- // METHOD TYPE : Dtor
- //
RepoException::~RepoException() throw()
{}
+
+ RepoNotCachedException::RepoNotCachedException()
+ : RepoException( "Repository not Cached" )
+ {}
+
+ RepoNotCachedException::RepoNotCachedException( const std::string & msg_r )
+ : RepoException( msg_r )
+ {}
+
+ RepoNotCachedException::~RepoNotCachedException() throw()
+ {}
+
- ///////////////////////////////////////////////////////////////////
- //
- // METHOD NAME : RepoException::dumpOn
- // METHOD TYPE : std::ostream &
- //
std::ostream & RepoException::dumpOn( std::ostream & str ) const
{
return Exception::dumpOn( str );
Modified: trunk/libzypp/zypp2/repo/RepoException.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp2/repo/RepoException.h?rev=5664&r1=5663&r2=5664&view=diff
==============================================================================
--- trunk/libzypp/zypp2/repo/RepoException.h (original)
+++ trunk/libzypp/zypp2/repo/RepoException.h Mon Jun 4 16:24:28 2007
@@ -49,7 +49,10 @@
*/
class RepoNotCachedException : public RepoException
{
-
+ public:
+ RepoNotCachedException();
+ RepoNotCachedException( const std::string & msg_r );
+ virtual ~RepoNotCachedException() throw();
};
/**
@@ -70,6 +73,15 @@
};
+ /**
+ * thrown when it was impossible to
+ * determine an alias for this repo.
+ */
+ class RepoUnknownTypeException : public RepoException
+ {
+
+ };
+
/////////////////////////////////////////////////////////////////
} // namespace parser
///////////////////////////////////////////////////////////////////
Modified: trunk/libzypp/zypp2/repo/cached/RepoImpl.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp2/repo/cached/RepoImpl.cc?rev=5664&r1=5663&r2=5664&view=diff
==============================================================================
--- trunk/libzypp/zypp2/repo/cached/RepoImpl.cc (original)
+++ trunk/libzypp/zypp2/repo/cached/RepoImpl.cc Mon Jun 4 16:24:28 2007
@@ -37,8 +37,9 @@
namespace cached
{ /////////////////////////////////////////////////////////////////
-RepoImpl::RepoImpl( const Pathname &dbdir, const data::RecordId &repository_id )
- : _dbdir(dbdir),
+RepoImpl::RepoImpl( const RepoInfo &repoinfo, const Pathname &dbdir, const data::RecordId &repository_id )
+ : RepositoryImpl(repoinfo),
+ _dbdir(dbdir),
_type_cache(dbdir),
_repository_id(repository_id),
_rquery(dbdir)
Modified: trunk/libzypp/zypp2/repo/cached/RepoImpl.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp2/repo/cached/RepoImpl.h?rev=5664&r1=5663&r2=5664&view=diff
==============================================================================
--- trunk/libzypp/zypp2/repo/cached/RepoImpl.h (original)
+++ trunk/libzypp/zypp2/repo/cached/RepoImpl.h Mon Jun 4 16:24:28 2007
@@ -21,6 +21,7 @@
#include "zypp2/cache/sqlite3x/sqlite3x.hpp"
#include "zypp2/cache/CacheTypes.h"
#include "zypp2/cache/ResolvableQuery.h"
+#include "zypp2/RepoInfo.h"
///////////////////////////////////////////////////////////////////
namespace zypp
@@ -45,7 +46,7 @@
public:
/** Default ctor */
- RepoImpl( const zypp::Pathname &dbdir, const data::RecordId &repository_id );
+ RepoImpl( const RepoInfo &repoinfo, const Pathname &dbdir, const data::RecordId &repository_id );
/** Dtor */
~RepoImpl();
void factoryInit();
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org