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();
158 WAR <<
"Ignoring invalid authority in constructor: " <<
authority << std::endl;
160 for(
auto &m :
mirrors ) { addMirror ( std::move(m) ); }
167 WAR <<
"Ignoring invalid authority: " << newAuthority << std::endl;
171 const auto &newScheme = newAuthority.
scheme();
174 _pimpl->_authority = std::move(newAuthority);
176 if ( !
_pimpl->_authority.isValid() || !
_pimpl->_origins.size () )
180 for (
auto i =
_pimpl->_origins.begin (); i !=
_pimpl->_origins.end(); ) {
181 if ( ( newAuthIsDl && !i->schemeIsDownloading() )
182 && ( i->scheme () != newScheme )
184 MIL <<
"Dropping mirror " << *i <<
" scheme is not compatible to new authority URL ( " << i->scheme() <<
" vs " << newScheme <<
")" << std::endl;
185 i =
_pimpl->_origins.erase(i);
194 return _pimpl->_authority;
204 return _pimpl->_authority.isValid();
211 WAR <<
"Ignoring invalid mirror: " << newMirror << std::endl;
215 if (
_pimpl->_authority.isValid()
217 && (
_pimpl->_authority.scheme () != newMirror.
scheme () )
220 MIL <<
"Ignoring mirror " << newMirror <<
" scheme is not compatible to new authority URL ( " << newMirror.
scheme() <<
" vs " <<
_pimpl->_authority.scheme() <<
")" << std::endl;
223 _pimpl->_origins.push_back( std::move(newMirror) );
241 return _pimpl->_authority.url().getScheme();
246 return _pimpl->_authority.schemeIsDownloading();
252 return _pimpl->_origins.size() + 1;
258 throw std::out_of_range(
"OriginEndpoint index out of range." );
261 return _pimpl->_authority;
264 return _pimpl->_origins.at( index - 1 );
270 throw std::out_of_range(
"OriginEndpoint index out of range." );
273 return _pimpl->_authority;
276 return _pimpl->_origins.at( index - 1 );
307 for(
auto &
url: urls )
314 for(
auto &
url: urls )
320 return _pimpl->_origins.at(idx);
325 return _pimpl->_origins.at(idx);
331 origin.
mirrors().begin(), origin.
mirrors().end(),
"mirrors: [",
"\"",
"\",\"",
"\"",
"]" )
337 for (
auto i =
begin(); i!=
end(); i++ ) {
338 auto epI = std::find_if( i->begin (), i->end(), [&](
const OriginEndpoint &ep){ return ep.url () == url; } );
339 if ( epI != i->end() )
347 for (
auto i =
begin(); i!=
end(); i++ ) {
348 auto epI = std::find_if( i->begin (), i->end(), [&](
const OriginEndpoint &ep){ return ep.url () == url; } );
349 if ( epI != i->end() )
363 _pimpl->_origins.at(*
_pimpl->_dlIndex).addMirror( std::move(endpoint) );
375 for (
auto &ep : endpoints )
381 return _pimpl->_origins.empty ();
392 return _pimpl->_origins.begin ();
398 return _pimpl->_origins.end ();
404 return _pimpl->_origins.begin ();
410 return _pimpl->_origins.end ();
415 return _pimpl->_origins.size ();
420 return (
size() == 1 &&
at( 0 ).endpointCount() > 1 ) ||
size() > 1;
425 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 > _origins
std::optional< std::size_t > _dlIndex
OriginEndpoint _authority
std::vector< OriginEndpoint > _origins
std::unordered_map< std::string, std::any > _settings
Private(Url &&u, OriginEndpoint::SettingsMap &&m)