From 834fe6ee4b7ed4595158a59c2c272d9def936f1b Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Mon, 18 Jun 2007 13:13:54 +0000 Subject: [PATCH] fix exception add filepath to repoinfo --- zypp/RepoInfo.cc | 11 ++++++++++- zypp/RepoInfo.h | 14 ++++++++++++++ zypp/RepoManager.cc | 29 ++++++++++++++++++++++++++++- zypp/RepoManager.h | 10 ++++++++++ zypp/cache/CacheStore.cc | 16 +++++++++++----- 5 files changed, 73 insertions(+), 7 deletions(-) diff --git a/zypp/RepoInfo.cc b/zypp/RepoInfo.cc index 06fe878..13b41d8 100644 --- a/zypp/RepoInfo.cc +++ b/zypp/RepoInfo.cc @@ -47,7 +47,7 @@ namespace zypp std::set baseUrls; std::string alias; std::string name; - + Pathname filepath; public: private: @@ -133,6 +133,12 @@ namespace zypp return *this; } + RepoInfo & RepoInfo::setFilepath( const Pathname &filepath ) + { + _pimpl->filepath = filepath; + return *this; + } + tribool RepoInfo::enabled() const { return _pimpl->enabled; } @@ -145,6 +151,9 @@ namespace zypp std::string RepoInfo::name() const { return _pimpl->name; } + Pathname RepoInfo::filepath() const + { return _pimpl->filepath; } + repo::RepoType RepoInfo::type() const { return _pimpl->type; } diff --git a/zypp/RepoInfo.h b/zypp/RepoInfo.h index 8763df0..3623f30 100644 --- a/zypp/RepoInfo.h +++ b/zypp/RepoInfo.h @@ -133,6 +133,14 @@ namespace zypp std::string name() const; /** + * \short File where this repo was read from + * + * \note could be an empty pathname for repo + * infos created in memory. + */ + Pathname filepath() const; + + /** * Add a base url. \see baseUrls * \param url The base url for the repository. * @@ -176,6 +184,12 @@ namespace zypp */ RepoInfo & setName( const std::string &name ); + /** + * \short set the repository filepath + * \param path File path + */ + RepoInfo & setFilepath( const Pathname &filename ); + std::ostream & dumpOn( std::ostream & str ) const; std::ostream & dumpRepoOn( std::ostream & str ) const; diff --git a/zypp/RepoManager.cc b/zypp/RepoManager.cc index 7c90b82..d121ebd 100644 --- a/zypp/RepoManager.cc +++ b/zypp/RepoManager.cc @@ -450,7 +450,34 @@ namespace zypp void RepoManager::addRepositories( const Url &url, const ProgressData::ReceiverFnc & progressrcv ) { - + std::list knownrepos = knownRepositories(); + std::list repos = readRepoFile(url); + for ( std::list::const_iterator it = repos.begin(); + it != repos.end(); + ++it ) + { + // look if the alias is in the known repos. + for ( std::list::const_iterator kit = knownrepos.begin(); + kit != repos.end(); + ++kit ) + { + if ( (*it).alias() == (*kit).alias() ) + ZYPP_THROW(RepoAlreadyExistsException((*it).alias())); + } + } + + Pathname filename = Pathname(url.getPathName()).basename(); + + if ( filename == Pathname() ) + ZYPP_THROW(RepoException("Invalid repo file name at " + url.asString() )); + + // FIXME move this code to a separate function + Pathname final_filename = filename; + int counter = 1; + while ( PathInfo(_pimpl->options.knownReposPath + filename).isExist() ) + { + filename = Pathname( filename.asString() ); + } } //////////////////////////////////////////////////////////////////////////// diff --git a/zypp/RepoManager.h b/zypp/RepoManager.h index 4e6c0f8..9056482 100644 --- a/zypp/RepoManager.h +++ b/zypp/RepoManager.h @@ -73,6 +73,16 @@ namespace zypp /** Dtor */ ~RepoManager(); + enum RepoRefreshPolicy + { + RefreshIfChanged, + RefreshForced + }; + + enum RepoAddPolicy + { + }; + /** * \short List known repositories. * diff --git a/zypp/cache/CacheStore.cc b/zypp/cache/CacheStore.cc index 71b8235..60dcad9 100644 --- a/zypp/cache/CacheStore.cc +++ b/zypp/cache/CacheStore.cc @@ -802,16 +802,22 @@ RepoStatus CacheStore::repositoryStatus( const string &alias ) bool CacheStore::isCached( const string &alias ) { + sqlite3_command cmd(_pimpl->con, "select id from repositories where alias=:alias;"); + cmd.bind(":alias", alias); try { - lookupRepository(alias); + sqlite3_reader reader= cmd.executereader(); + if (!reader.read()) + { + return false; + } + return true; } - catch( const CacheRecordNotFoundException &e ) + catch ( const sqlite3x::database_error &e ) { - return false; + ZYPP_RETHROW(e); } - - return true; + return false; } RecordId CacheStore::lookupRepository( const string &alias ) -- 2.7.4