repo/dummy.cc
repo/RepoException.cc
repo/RepoType.cc
+ repo/ServiceType.cc
repo/PackageProvider.cc
repo/SrcPackageProvider.cc
repo/RepoProvideFile.cc
SET( zypp_repo_HEADERS
repo/RepoException.h
repo/RepoType.h
+ repo/ServiceType.h
repo/PackageProvider.h
repo/SrcPackageProvider.h
repo/RepoProvideFile.h
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;
void RepoManager::refreshServices()
{
- //cannot user for_, because it uses const version
- for (std::set<ServiceInfo>::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() )
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())
}
}
}
+
+ 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;
+ }
////////////////////////////////////////////////////////////////////////////
#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"
/** Implementation */
class Impl;
- /** service typedefs */
+ /** ServiceInfo typedefs */
typedef std::set<ServiceInfo> ServiceSet;
typedef ServiceSet::const_iterator ServiceConstIterator;
typedef ServiceSet::size_type ServiceSizeType;
*/
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;
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
public:
Url url;
+ repo::ServiceType type;
CatalogsToEnable catalogsToEnable;
CatalogsToDisable catalogsToDisable;
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<Impl*>(this)->type = t;
+ }
+ }
private:
friend Impl * rwcowClone<Impl>( const Impl * rhs );
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(); }
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() )
<< " name=\"" << escape(name()) << "\""
<< " enabled=\"" << enabled() << "\""
<< " autorefresh=\"" << autorefresh() << "\""
- << " url=\"" << escape(url().asString()) << "\"";
+ << " url=\"" << escape(url().asString()) << "\""
+ << " type=\"" << type().asString() << "\"";
if (content.empty())
str << "/>" << endl;
#include "zypp/Url.h"
+#include "zypp/repo/ServiceType.h"
#include "zypp/repo/RepoInfoBase.h"
*/
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.
*
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<std::string> aliases;
}
}
else
- ERR << "Unknown attribute " << it->second << " ignored" << endl;
+ ERR << "Unknown attribute " << it->first << " ignored" << endl;
}
MIL << "Linking ServiceInfo with file " << file << endl;
--- /dev/null
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+
+#include <iostream>
+#include <map>
+#include "zypp/repo/RepoException.h"
+#include "ServiceType.h"
+
+namespace zypp
+{
+ namespace repo
+ {
+
+
+ static std::map<std::string,ServiceType::Type> _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<std::string,ServiceType::Type>::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<Type, std::string> _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:
--- /dev/null
+/*---------------------------------------------------------------------\
+| ____ _ __ __ ___ |
+| |__ / \ / / . \ . \ |
+| / / \ V /| _/ _/ |
+| / /__ | | | | | | |
+| /_____||_| |_| |_| |
+| |
+\---------------------------------------------------------------------*/
+
+#ifndef ZYPP_SERVICE_TYPE_H_
+#define ZYPP_SERVICE_TYPE_H_
+
+#include <iosfwd>
+#include <string>
+
+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: