12#undef ZYPP_BASE_LOGGER_LOGGROUP
13#define ZYPP_BASE_LOGGER_LOGGROUP "zypp::MirroredOrigin"
30 std::unordered_map<std::string, std::any>
_settings;
39 : _pimpl( new Private(
std::move(url),
std::move(settings) ) )
63 return (
_pimpl->_settings.count (key) > 0);
68 return _pimpl->_url.getScheme();
73 return _pimpl->_url.schemeIsDownloading ();
78 return _pimpl->_url.isValid();
81 void OriginEndpoint::setConfig(
const std::string &key, std::any value)
83 _pimpl->_settings.insert_or_assign ( key, std::move(value) );
86 const std::any &OriginEndpoint::getConfig(
const std::string &key)
const
88 return _pimpl->_settings.at(key);
91 std::any &OriginEndpoint::getConfig(
const std::string &key)
93 return _pimpl->_settings.at(key);
96 void OriginEndpoint::eraseConfigValue(
const std::string &key )
98 auto it =
_pimpl->_settings.find (key);
99 if ( it ==
_pimpl->_settings.end() )
101 _pimpl->_settings.erase(it);
104 const OriginEndpoint::SettingsMap &OriginEndpoint::config()
const
110 OriginEndpoint::SettingsMap &OriginEndpoint::config()
118 return str <<
url.url().asString();
163 const auto &newScheme = newAuthority.
scheme();
166 _pimpl->_authority = std::move(newAuthority);
168 if ( !
_pimpl->_authority.isValid() || !
_pimpl->_mirrors.size () )
172 for (
auto i =
_pimpl->_mirrors.begin (); i !=
_pimpl->_mirrors.end(); ) {
173 if ( ( newAuthIsDl && !i->schemeIsDownloading() )
174 && ( i->scheme () != newScheme )
176 MIL <<
"Dropping mirror " << *i <<
" scheme is not compatible to new authority URL ( " << i->scheme() <<
" vs " << newScheme <<
")" << std::endl;
177 i =
_pimpl->_mirrors.erase(i);
186 return _pimpl->_authority;
196 return _pimpl->_authority.isValid();
201 if (
_pimpl->_authority.isValid()
203 && (
_pimpl->_authority.scheme () != newMirror.
scheme () )
206 MIL <<
"Ignoring mirror " << newMirror <<
" scheme is not compatible to new authority URL ( " << newMirror.
scheme() <<
" vs " <<
_pimpl->_authority.scheme() <<
")" << std::endl;
209 _pimpl->_mirrors.push_back( std::move(newMirror) );
227 return _pimpl->_authority.url().getScheme();
232 return _pimpl->_authority.schemeIsDownloading();
238 return _pimpl->_mirrors.size() + 1;
244 throw std::out_of_range(
"OriginEndpoint index out of range." );
247 return _pimpl->_authority;
250 return _pimpl->_mirrors.at( index - 1 );
256 throw std::out_of_range(
"OriginEndpoint index out of range." );
259 return _pimpl->_authority;
262 return _pimpl->_mirrors.at( index - 1 );
293 for(
auto &
url: urls )
300 for(
auto &
url: urls )
306 return _pimpl->_mirrors.at(idx);
311 return _pimpl->_mirrors.at(idx);
317 origin.
mirrors().begin(), origin.
mirrors().end(),
"mirrors: [",
"\"",
"\",\"",
"\"",
"]" )
323 for (
auto i =
begin(); i!=
end(); i++ ) {
324 auto epI = std::find_if( i->begin (), i->end(), [&](
const OriginEndpoint &ep){ return ep.url () == url; } );
325 if ( epI != i->end() )
333 for (
auto i =
begin(); i!=
end(); i++ ) {
334 auto epI = std::find_if( i->begin (), i->end(), [&](
const OriginEndpoint &ep){ return ep.url () == url; } );
335 if ( epI != i->end() )
349 _pimpl->_mirrors.at(*
_pimpl->_dlIndex).addMirror( std::move(endpoint) );
361 for (
auto &ep : endpoints )
367 return _pimpl->_mirrors.empty ();
378 return _pimpl->_mirrors.begin ();
384 return _pimpl->_mirrors.end ();
390 return _pimpl->_mirrors.begin ();
396 return _pimpl->_mirrors.end ();
401 return _pimpl->_mirrors.size ();
406 return (
size() == 1 &&
at( 0 ).endpointCount() > 1 ) ||
size() > 1;
411 return dumpRange(
str, origin.
begin(), origin.
end(),
"MirroredOriginSet {",
" ",
", ",
" ",
"}" );
A smart container that manages a collection of MirroredOrigin objects, automatically grouping endpoin...
bool hasFallbackUrls() const
Whether this set contains more than one Url in total (authorities or mirrors).
const_iterator findByUrl(const zypp::Url &url) const
Finds the MirroredOrigin that contains a specific URL.
const MirroredOrigin & at(size_type idx) const
Accesses the MirroredOrigin at a specific index.
size_type size() const
Returns the number of MirroredOrigin objects in the set.
iterator end()
Returns an iterator to the element following the last MirroredOrigin.
std::vector< MirroredOrigin >::const_iterator const_iterator
RWCOW_pointer< Private > _pimpl
iterator begin()
Returns an iterator to the first MirroredOrigin in insertion order.
std::vector< MirroredOrigin >::iterator iterator
void addEndpoints(InputIterator first, InputIterator last)
A convenience method to add multiple endpoints from a range.
void addEndpoint(OriginEndpoint endpoint)
Adds a single endpoint, routing it to the correct MirroredOrigin.
Manages a data source characterized by an authoritative URL and a list of mirror URLs.
bool schemeIsDownloading() const
const std::vector< OriginEndpoint > & mirrors() const
const OriginEndpoint & at(uint index) const
void setAuthority(OriginEndpoint newAuthority)
RWCOW_pointer< Private > _pimpl
void setMirrors(std::vector< OriginEndpoint > mirrors)
bool addMirror(OriginEndpoint newMirror)
std::string scheme() const
const OriginEndpoint & authority() const
uint endpointCount() const
Represents a single, configurable network endpoint, combining a URL with specific access settings.
bool schemeIsDownloading() const
RWCOW_pointer< Private > _pimpl
std::string scheme() const
const zypp::Url & url() const
void setUrl(const zypp::Url &newUrl)
bool hasConfig(const std::string &key) const
std::string asCompleteString() const
Returns a complete string representation of the Url object.
static bool schemeIsDownloading(const std::string &scheme_r)
http https ftp sftp tftp
String related utilities and Regular expression matching.
Easy-to use interface to the ZYPP dependency resolver.
bool operator<(const StrMatcher &lhs, const StrMatcher &rhs)
std::ostream & dumpRange(std::ostream &str, TIterator begin, TIterator end, const std::string &intro="{", const std::string &pfx="\n ", const std::string &sep="\n ", const std::string &sfx="\n", const std::string &extro="}")
Print range defined by iterators (multiline style).
bool operator==(const SetRelation::Enum &lhs, const SetCompare &rhs)
This is an overloaded member function, provided for convenience. It differs from the above function o...
std::ostream & operator<<(std::ostream &str, const SerialNumber &obj)
bool operator!=(const SetRelation::Enum &lhs, const SetCompare &rhs)
This is an overloaded member function, provided for convenience. It differs from the above function o...
std::vector< MirroredOrigin > _mirrors
std::optional< std::size_t > _dlIndex
Private(OriginEndpoint &&authority={}, std::vector< OriginEndpoint > &&mirrors={})
OriginEndpoint _authority
std::vector< OriginEndpoint > _mirrors
std::unordered_map< std::string, std::any > _settings
Private(Url &&u, OriginEndpoint::SettingsMap &&m)