18#include <zypp-curl/parser/MetaLinkParser> 
   42      struct RepoMirrorListTempProvider
 
   44        RepoMirrorListTempProvider()
 
   46        RepoMirrorListTempProvider( Pathname  localfile_r )
 
   47        : _localfile(std::move( localfile_r ))
 
   49        RepoMirrorListTempProvider( 
const Url & url_r )
 
   52          abs_url.setPathName( 
"/" );
 
   53          abs_url.setQueryParam( 
"mediahandler", 
"curl" );
 
   54          _access.reset( 
new MediaSetAccess( abs_url ) );
 
   55          _localfile = _access->provideFile( url_r.getPathName() );
 
   58        const Pathname & localfile()
 const 
   59        { 
return _localfile; }
 
   62        shared_ptr<MediaSetAccess> _access;
 
   67      inline std::vector<Url> RepoMirrorListParseXML( 
const Pathname &tmpfile )
 
   69        InputStream tmpfstream (tmpfile);
 
   70        media::MetaLinkParser metalink;
 
   71        metalink.parse(tmpfstream);
 
   72        return metalink.getUrls();
 
   75      inline std::vector<Url> RepoMirrorListParseTXT( 
const Pathname &tmpfile )
 
   77        InputStream tmpfstream (tmpfile);
 
   78        std::vector<Url> my_urls;
 
   80        while (
getline(tmpfstream.stream(), tmpurl))
 
   82          if ( tmpurl[0] == 
'#' )
 
   85            my_urls.push_back(
Url(tmpurl));
 
   94      inline std::vector<Url> RepoMirrorListParse( 
const Url & url_r, 
const Pathname & listfile_r, 
bool mirrorListForceMetalink_r )
 
   96        USR << url_r << 
" " << listfile_r << endl;
 
   98        std::vector<Url> mirrorurls;
 
   99        if ( mirrorListForceMetalink_r || url_r.asString().find( 
"/metalink" ) != std::string::npos )
 
  100          mirrorurls = RepoMirrorListParseXML( listfile_r );
 
  102          mirrorurls = RepoMirrorListParseTXT( listfile_r );
 
  105        std::vector<Url> ret;
 
  106        for ( 
auto & murl : mirrorurls )
 
  108          if ( murl.getScheme() != 
"rsync" )
 
  110            size_t delpos = murl.getPathName().find(
"repodata/repomd.xml");
 
  111            if( delpos != std::string::npos )
 
  113              murl.setPathName( murl.getPathName().erase(delpos)  );
 
  115            ret.push_back( murl );
 
  117            if ( ret.size() >= 4 )      
 
  132        _urls = RepoMirrorListParse( url_r, url_r.
getPathName(), mirrorListForceMetalink_r );
 
  134      else if ( ! 
PathInfo( metadatapath_r).isDir() )
 
  137        RepoMirrorListTempProvider provider( url_r );   
 
  138        _urls = RepoMirrorListParse( url_r, provider.localfile(), mirrorListForceMetalink_r );
 
  143        Pathname cachefile( metadatapath_r );
 
  144        if ( mirrorListForceMetalink_r || url_r.
asString().find( 
"/metalink" ) != std::string::npos )
 
  145          cachefile /= 
"mirrorlist.xml";
 
  147          cachefile /= 
"mirrorlist.txt";
 
  152          DBG << 
"Getting MirrorList from URL: " << url_r << endl;
 
  153          RepoMirrorListTempProvider provider( url_r ); 
 
  156          DBG << 
"Copy MirrorList file to " << cachefile << endl;
 
  161        _urls = RepoMirrorListParse( url_r, cachefile, mirrorListForceMetalink_r );
 
  164          DBG << 
"Removing Cachefile as it contains no URLs" << endl;
 
 
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 hardlinkCopy(const Pathname &oldpath, const Pathname &newpath)
Create newpath as hardlink or copy of oldpath.
int unlink(const Pathname &path)
Like 'unlink'.
int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
std::string getline(std::istream &str)
Read one line from stream.
Easy-to use interface to the ZYPP dependency resolver.