17#include <zypp-curl/parser/MetaLinkParser>
19#include <zypp/base/LogTools.h>
21#include <zypp/PathInfo.h>
41 struct RepoMirrorListTempProvider
43 RepoMirrorListTempProvider()
45 RepoMirrorListTempProvider(
const Pathname & localfile_r )
48 RepoMirrorListTempProvider(
const Url & url_r )
51 abs_url.setPathName(
"/" );
52 abs_url.setQueryParam(
"mediahandler",
"curl" );
53 _access.reset(
new MediaSetAccess( abs_url ) );
57 const Pathname & localfile()
const
66 inline std::vector<Url> RepoMirrorListParseXML(
const Pathname &tmpfile )
68 InputStream tmpfstream (tmpfile);
69 media::MetaLinkParser metalink;
70 metalink.parse(tmpfstream);
71 return metalink.getUrls();
74 inline std::vector<Url> RepoMirrorListParseTXT(
const Pathname &tmpfile )
76 InputStream tmpfstream (tmpfile);
77 std::vector<Url> my_urls;
79 while (
getline(tmpfstream.stream(), tmpurl))
81 if ( tmpurl[0] ==
'#' )
84 my_urls.push_back(
Url(tmpurl));
93 inline std::vector<Url> RepoMirrorListParse(
const Url & url_r,
const Pathname & listfile_r,
bool mirrorListForceMetalink_r )
95 USR << url_r <<
" " << listfile_r << endl;
97 std::vector<Url> mirrorurls;
98 if ( mirrorListForceMetalink_r || url_r.asString().find(
"/metalink" ) != std::string::npos )
99 mirrorurls = RepoMirrorListParseXML( listfile_r );
101 mirrorurls = RepoMirrorListParseTXT( listfile_r );
104 std::vector<Url> ret;
105 for (
auto & murl : mirrorurls )
107 if ( murl.getScheme() !=
"rsync" )
109 size_t delpos = murl.getPathName().find(
"repodata/repomd.xml");
110 if( delpos != std::string::npos )
112 murl.setPathName( murl.getPathName().erase(delpos) );
114 ret.push_back( murl );
116 if ( ret.size() >= 4 )
131 _urls = RepoMirrorListParse( url_r, url_r.
getPathName(), mirrorListForceMetalink_r );
133 else if ( !
PathInfo( metadatapath_r).isDir() )
136 RepoMirrorListTempProvider provider( url_r );
137 _urls = RepoMirrorListParse( url_r, provider.localfile(), mirrorListForceMetalink_r );
142 Pathname cachefile( metadatapath_r );
143 if ( mirrorListForceMetalink_r || url_r.
asString().find(
"/metalink" ) != std::string::npos )
144 cachefile /=
"mirrorlist.xml";
146 cachefile /=
"mirrorlist.txt";
151 DBG <<
"Getting MirrorList from URL: " << url_r << endl;
152 RepoMirrorListTempProvider provider( url_r );
155 DBG <<
"Copy MirrorList file to " << cachefile << endl;
160 _urls = RepoMirrorListParse( url_r, cachefile, mirrorListForceMetalink_r );
163 DBG <<
"Removing Cachefile as it contains no URLs" << endl;
shared_ptr< MediaSetAccess > _access
std::string getScheme() const
Returns the scheme name of the URL.
std::string asString() const
Returns a default string representation of the Url object.
std::string getPathName(EEncoding eflag=zypp::url::E_DECODED) const
Returns the path name from the URL.
static ZConfig & instance()
Singleton ctor.
Wrapper class for stat/lstat.
RepoMirrorList(const Url &url_r, const Pathname &metadatapath_r, bool mirrorListForceMetalink_r)
int unlink(const Pathname &path)
Like 'unlink'.
int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
int hardlinkCopy(const Pathname &oldpath, const Pathname &newpath)
Create newpath as hardlink or copy of oldpath.
std::string getline(std::istream &str)
Read one line from stream.
Easy-to use interface to the ZYPP dependency resolver.
constexpr std::string_view Url("url")