From d09071b68d70a2a18ca5465a678ae47eb3dfec88 Mon Sep 17 00:00:00 2001 From: Jan Kupec Date: Thu, 11 Sep 2008 16:22:05 +0000 Subject: [PATCH] - ServiceType introduced - FIXME service probing upon refresh --- zypp/CMakeLists.txt | 2 ++ zypp/RepoManager.cc | 57 +++++++++++++++++++++++++++++-- zypp/RepoManager.h | 11 ++++-- zypp/ServiceInfo.cc | 26 ++++++++++++-- zypp/ServiceInfo.h | 15 +++++++++ zypp/parser/ServiceFileReader.cc | 4 ++- zypp/repo/ServiceType.cc | 69 +++++++++++++++++++++++++++++++++++++ zypp/repo/ServiceType.h | 73 ++++++++++++++++++++++++++++++++++++++++ 8 files changed, 248 insertions(+), 9 deletions(-) create mode 100644 zypp/repo/ServiceType.cc create mode 100644 zypp/repo/ServiceType.h diff --git a/zypp/CMakeLists.txt b/zypp/CMakeLists.txt index c5dd5b1..e18c878 100644 --- a/zypp/CMakeLists.txt +++ b/zypp/CMakeLists.txt @@ -682,6 +682,7 @@ SET( zypp_repo_SRCS repo/dummy.cc repo/RepoException.cc repo/RepoType.cc + repo/ServiceType.cc repo/PackageProvider.cc repo/SrcPackageProvider.cc repo/RepoProvideFile.cc @@ -698,6 +699,7 @@ SET( zypp_repo_SRCS SET( zypp_repo_HEADERS repo/RepoException.h repo/RepoType.h + repo/ServiceType.h repo/PackageProvider.h repo/SrcPackageProvider.h repo/RepoProvideFile.h diff --git a/zypp/RepoManager.cc b/zypp/RepoManager.cc index 671ce48..38b1db5 100644 --- a/zypp/RepoManager.cc +++ b/zypp/RepoManager.cc @@ -1354,7 +1354,7 @@ namespace zypp if( _pimpl->services.find(service) != _pimpl->services.end() ) return; //FIXME ZYPP_THROW(RepoAlreadyExistsException(service.name())); - //this is need to save location to correct service + // this is need to save location to correct service const ServiceInfo & savedService = *(_pimpl->services.insert( service )).first; @@ -1470,8 +1470,8 @@ namespace zypp void RepoManager::refreshServices() { - //cannot user for_, because it uses const version - for (std::set::iterator it = _pimpl->services.begin(); + // cannot user for_, because it uses const version + for (ServiceConstIterator it = _pimpl->services.begin(); it != _pimpl->services.end(); ++it) { if ( !it->enabled() ) @@ -1485,7 +1485,32 @@ namespace zypp void RepoManager::refreshService( const ServiceInfo & service ) { //! \todo add callbacks for apps (start, end, repo removed, repo added, repo changed) +/* + repo::ServiceType type = service.type(); + // if the type is unknown, try probing. + if ( type == repo::ServiceType::NONE ) + { + // unknown, probe it + type = probeService(service.url()); + if (type != ServiceType::NONE) + { + // Adjust the probed type in ServiceInfo + service.setProbedType( type ); // lazy init! + // save probed type only for repos in system + for_( sit, serviceBegin(), serviceEnd() ) + { + if ( service.alias() == sit->alias() ) + { + ServiceInfo modifiedservice = service; + modifiedservice.setType(type); + modifyService(service.alias(), modifiedservice); // FIXME this causes a segfault, whe the same code from repos doesn't? + break; + } + } + } + } +*/ // download the repo index file media::MediaManager mediamanager; //if (service.url().empty()) @@ -1626,6 +1651,32 @@ namespace zypp } } } + + repo::ServiceType RepoManager::probeService( const Url &url ) const + { + try + { + MediaSetAccess access(url); + if ( access.doesFileExist("/repo/repoindex.xml") ) + return repo::ServiceType::RIS; + } + catch ( const media::MediaException &e ) + { + ZYPP_CAUGHT(e); + RepoException enew("Error trying to read from " + url.asString()); + enew.remember(e); + ZYPP_THROW(enew); + } + catch ( const Exception &e ) + { + ZYPP_CAUGHT(e); + Exception enew("Unknown error reading from " + url.asString()); + enew.remember(e); + ZYPP_THROW(enew); + } + + return repo::ServiceType::NONE; + } //////////////////////////////////////////////////////////////////////////// diff --git a/zypp/RepoManager.h b/zypp/RepoManager.h index 53ca2bb..8f9e5a7 100644 --- a/zypp/RepoManager.h +++ b/zypp/RepoManager.h @@ -23,6 +23,7 @@ #include "zypp/RepoInfo.h" #include "zypp/repo/RepoException.h" #include "zypp/repo/RepoType.h" +#include "zypp/repo/ServiceType.h" #include "zypp/RepoStatus.h" #include "zypp/ProgressData.h" @@ -108,7 +109,7 @@ namespace zypp /** Implementation */ class Impl; - /** service typedefs */ + /** ServiceInfo typedefs */ typedef std::set ServiceSet; typedef ServiceSet::const_iterator ServiceConstIterator; typedef ServiceSet::size_type ServiceSizeType; @@ -356,10 +357,9 @@ namespace zypp */ void loadFromCache( const RepoInfo &info, const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() ); + /** * \short Probe repo metadata type. - * - * \todo FIXME Should this be private? */ repo::RepoType probe( const Url &url ) const; @@ -456,6 +456,11 @@ namespace zypp const ProgressData::ReceiverFnc & progressrcv = ProgressData::ReceiverFnc() ); /** + * \short Probe the type or the service. + */ + repo::ServiceType probeService( const Url &url ) const; + + /** * Adds new service by it's alias and url * * \param alias unique identifier of the service diff --git a/zypp/ServiceInfo.cc b/zypp/ServiceInfo.cc index 1d5cb47..acd0f7a 100644 --- a/zypp/ServiceInfo.cc +++ b/zypp/ServiceInfo.cc @@ -50,6 +50,7 @@ namespace zypp public: Url url; + repo::ServiceType type; CatalogsToEnable catalogsToEnable; CatalogsToDisable catalogsToDisable; @@ -57,6 +58,16 @@ namespace zypp Impl() : repo::RepoInfoBase::Impl() {} Impl(const Url & url_) : url(url_) {} + + void setProbedType( const repo::ServiceType & t ) const + { + if ( type == repo::ServiceType::NONE + && t != repo::ServiceType::NONE ) + { + // lazy init! + const_cast(this)->type = t; + } + } private: friend Impl * rwcowClone( const Impl * rhs ); @@ -89,6 +100,13 @@ namespace zypp Url ServiceInfo::url() const { return _pimpl->url; } void ServiceInfo::setUrl( const Url& url ) { _pimpl->url = url; } + repo::ServiceType ServiceInfo::type() const + { return _pimpl->type; } + void ServiceInfo::setType( const repo::ServiceType & type ) + { _pimpl->type = type; } + + void ServiceInfo::setProbedType( const repo::ServiceType &t ) const + { _pimpl->setProbedType( t ); } bool ServiceInfo::catalogsToEnableEmpty() const { return _pimpl->catalogsToEnable.empty(); } @@ -136,7 +154,10 @@ namespace zypp std::ostream & ServiceInfo::dumpAsIniOn( std::ostream & str ) const { - RepoInfoBase::dumpAsIniOn(str) << "url = " << url() << endl; + RepoInfoBase::dumpAsIniOn(str) + << "url = " << url() << endl + << "type = " << type() << endl; + if ( ! catalogsToEnableEmpty() ) str << "catalogstoenable = " << str::joinEscaped( catalogsToEnableBegin(), catalogsToEnableEnd() ) << endl; if ( ! catalogsToDisableEmpty() ) @@ -155,7 +176,8 @@ namespace zypp << " name=\"" << escape(name()) << "\"" << " enabled=\"" << enabled() << "\"" << " autorefresh=\"" << autorefresh() << "\"" - << " url=\"" << escape(url().asString()) << "\""; + << " url=\"" << escape(url().asString()) << "\"" + << " type=\"" << type().asString() << "\""; if (content.empty()) str << "/>" << endl; diff --git a/zypp/ServiceInfo.h b/zypp/ServiceInfo.h index ba40818..ebf825b 100644 --- a/zypp/ServiceInfo.h +++ b/zypp/ServiceInfo.h @@ -17,6 +17,7 @@ #include "zypp/Url.h" +#include "zypp/repo/ServiceType.h" #include "zypp/repo/RepoInfoBase.h" @@ -70,6 +71,20 @@ namespace zypp */ void setUrl( const Url& url ); + /** + * + */ + repo::ServiceType type() const; + + /** + * Set service type. + * + * \param type the new type + */ + void setType( const repo::ServiceType & type ); + + void setProbedType( const repo::ServiceType & t ) const; + /** \name Set of catalogs (repository aliases) to enable on next refresh. * diff --git a/zypp/parser/ServiceFileReader.cc b/zypp/parser/ServiceFileReader.cc index 4fe2f00..e9c2ac3 100644 --- a/zypp/parser/ServiceFileReader.cc +++ b/zypp/parser/ServiceFileReader.cc @@ -68,6 +68,8 @@ namespace zypp service.setEnabled( str::strToTrue( it->second ) ); else if ( it->first == "autorefresh" ) service.setAutorefresh( str::strToTrue( it->second ) ); + else if ( it->first == "type" ) + service.setType( repo::ServiceType(it->second) ); else if ( it->first == "catalogstoenable" ) { std::vector aliases; @@ -78,7 +80,7 @@ namespace zypp } } else - ERR << "Unknown attribute " << it->second << " ignored" << endl; + ERR << "Unknown attribute " << it->first << " ignored" << endl; } MIL << "Linking ServiceInfo with file " << file << endl; diff --git a/zypp/repo/ServiceType.cc b/zypp/repo/ServiceType.cc new file mode 100644 index 0000000..80a217b --- /dev/null +++ b/zypp/repo/ServiceType.cc @@ -0,0 +1,69 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ + +#include +#include +#include "zypp/repo/RepoException.h" +#include "ServiceType.h" + +namespace zypp +{ + namespace repo + { + + + static std::map _table; + + const ServiceType ServiceType::RIS(ServiceType::RIS_e); + const ServiceType ServiceType::NONE(ServiceType::NONE_e); + + ServiceType::ServiceType(const std::string & strval_r) + : _type(parse(strval_r)) + {} + + ServiceType::Type ServiceType::parse(const std::string & strval_r) + { + if (_table.empty()) + { + // initialize it + _table["ris"] = ServiceType::RIS_e; + _table["RIS"] = ServiceType::RIS_e; + _table["nu"] = ServiceType::RIS_e; + _table["NU"] = ServiceType::RIS_e; + _table["NONE"] = _table["none"] = ServiceType::NONE_e; + } + + std::map::const_iterator it + = _table.find(strval_r); + if (it == _table.end()) + { + ZYPP_THROW(RepoUnknownTypeException( + "Unknown service type '" + strval_r + "'")); + } + return it->second; + } + + + const std::string & ServiceType::asString() const + { + static std::map _table; + if ( _table.empty() ) + { + // initialize it + _table[RIS_e] = "ris"; + _table[NONE_e] = "NONE"; + } + return _table[_type]; + } + + + } // ns repo +} // ns zypp + +// vim: set ts=2 sts=2 sw=2 et ai: diff --git a/zypp/repo/ServiceType.h b/zypp/repo/ServiceType.h new file mode 100644 index 0000000..ad347c4 --- /dev/null +++ b/zypp/repo/ServiceType.h @@ -0,0 +1,73 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ + +#ifndef ZYPP_SERVICE_TYPE_H_ +#define ZYPP_SERVICE_TYPE_H_ + +#include +#include + +namespace zypp +{ + namespace repo + { + + /** + * \short Service type enumeration + * + * Currently we have only RIS service, but more can come later. + */ + struct ServiceType + { + /** + * Repository Index Service (RIS) + * (formerly known as 'Novell Update' (NU) service) + */ + static const ServiceType RIS; + /** No service set. */ + static const ServiceType NONE; + + enum Type + { + NONE_e, + RIS_e, + }; + + ServiceType() : _type(NONE_e) {} + + ServiceType(Type type) : _type(type) {} + + explicit ServiceType(const std::string & strval_r); + + Type toEnum() const { return _type; } + + ServiceType::Type parse(const std::string & strval_r); + + const std::string & asString() const; + + Type _type; + }; + + + inline std::ostream & operator<<( std::ostream & str, const ServiceType & obj ) + { return str << obj.asString(); } + + inline bool operator==(const ServiceType & obj1, const ServiceType & obj2) + { return obj1._type == obj2._type; } + + inline bool operator!=(const ServiceType & obj1, const ServiceType & obj2) + { return ! (obj1 == obj2); } + + + } // ns repo +} // ns zypp + +#endif /* ZYPP_SERVICE_TYPE_H_ */ + +// vim: set ts=2 sts=2 sw=2 et ai: -- 2.7.4