From 96db74ce38e9451609fe33f9e25f3f9d42b1fe22 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 2 Jun 2010 16:40:40 +0200 Subject: * apt-pkg/deb/dpkgpm.cc: - add missing include * methods/mirror.{cc,h}: - add SelectNextMirror() and InitMirrors() functions - read all mirrors into the AllMirrors vector --- methods/mirror.cc | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) (limited to 'methods/mirror.cc') diff --git a/methods/mirror.cc b/methods/mirror.cc index b3a956b95..0a0d07e6b 100644 --- a/methods/mirror.cc +++ b/methods/mirror.cc @@ -162,7 +162,21 @@ bool MirrorMethod::DownloadMirrorFile(string mirror_uri_str) return res; } -bool MirrorMethod::SelectMirror() +bool MirrorMethod::SelectNextMirror() +{ + if (AllMirrors.size() < 1) + return false; + + Mirror = AllMirrors[0]; + AllMirrors.erase(AllMirrors.begin()); + if(Debug) + cerr << "using mirror: " << Mirror << endl; + + UsedMirror = Mirror; + return true; +} + +bool MirrorMethod::InitMirrors() { // if we do not have a MirrorFile, fallback if(!FileExists(MirrorFile)) @@ -179,11 +193,13 @@ bool MirrorMethod::SelectMirror() // get into sync issues (got indexfiles from mirror A, // but packages from mirror B - one might be out of date etc) ifstream in(MirrorFile.c_str()); - getline(in, Mirror); - if(Debug) - cerr << "Using mirror: " << Mirror << endl; - - UsedMirror = Mirror; + string s; + while (!in.eof()) + { + getline(in, s); + AllMirrors.push_back(s); + } + SelectNextMirror(); return true; } @@ -275,7 +291,7 @@ bool MirrorMethod::Fetch(FetchItem *Itm) } if(Mirror.empty()) { - if(!SelectMirror()) { + if(!InitMirrors()) { // no valid mirror selected, something went wrong downloading // from the master mirror site most likely and there is // no old mirror file availalbe -- cgit v1.2.3