32 RepoMirrorList::RepoMirrorList(
const Url &
url,
const Pathname &metadatapath )
34 std::vector<Url> my_urls;
35 Pathname tmpfile, cachefile;
37 if ( url.
asString().find(
"/metalink") != string::npos )
38 cachefile = metadatapath /
"mirrorlist.xml";
40 cachefile = metadatapath /
"mirrorlist.txt";
45 if ( !cacheinfo.
isFile() || cacheinfo.
mtime() < time(NULL) - (long) ZConfig::instance().repo_refresh_delay() * 60 )
50 DBG <<
"Getting MirrorList from URL: " << abs_url << endl;
52 abs_url.setPathName(
"");
53 abs_url.setQueryParam(
"mediahandler",
"curl");
61 DBG <<
"Copy MirrorList file to " << cachefile << endl;
65 if ( url.
asString().find(
"/metalink") != string::npos )
67 my_urls = parseXML(cachefile);
71 my_urls = parseTXT(cachefile);
77 DBG <<
"Removing Cachefile as it contains no URLs" << endl;
82 RepoMirrorList::RepoMirrorList(
const Url &
url )
84 std::vector<Url> my_urls;
90 DBG <<
"Getting MirrorList from URL: " << abs_url << endl;
92 abs_url.setPathName(
"");
93 abs_url.setQueryParam(
"mediahandler",
"curl");
98 if ( url.
asString().find(
"/metalink") != string::npos )
100 my_urls = parseXML(tmpfile);
104 my_urls = parseTXT(tmpfile);
110 void RepoMirrorList::setUrls( std::vector<Url> my_urls )
113 for (std::vector<Url>::iterator it = my_urls.begin() ; it != my_urls.end() and valid_urls < 4 ; ++it)
115 if ( it->getScheme() !=
"rsync" )
117 size_t delpos = it->getPathName().find(
"repodata/repomd.xml");
118 if( delpos != string::npos )
120 it->setPathName( it->getPathName().erase(delpos) );
128 std::vector<Url> RepoMirrorList::parseXML(
const Pathname &tmpfile )
const
132 metalink.
parse(tmpfstream);
136 std::vector<Url> RepoMirrorList::parseTXT(
const Pathname &tmpfile )
const
139 std::vector<Url> my_urls;
143 my_urls.push_back(
Url(tmpurl));
148 std::vector<Url> RepoMirrorList::getUrls()
const
153 RepoMirrorList::~RepoMirrorList()
int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
std::string getPathName(EEncoding eflag=zypp::url::E_DECODED) const
Returns the path name from the URL.
std::string asString() const
Returns a default string representation of the Url object.
std::string getline(std::istream &str)
Read one line from stream.
int unlink(const Pathname &path)
Like 'unlink'.
int copy(const Pathname &file, const Pathname &dest)
Like 'cp file dest'.
Wrapper class for ::stat/::lstat.