- add missing include
* methods/mirror.{cc,h}:
- add SelectNextMirror() and InitMirrors() functions
- read all mirrors into the AllMirrors vector
#include <stdlib.h>
#include <fcntl.h>
#include <sys/select.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/select.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
-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))
{
// if we do not have a MirrorFile, fallback
if(!FileExists(MirrorFile))
// 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());
// 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();
// no valid mirror selected, something went wrong downloading
// from the master mirror site most likely and there is
// no old mirror file availalbe
// no valid mirror selected, something went wrong downloading
// from the master mirror site most likely and there is
// no old mirror file availalbe
// we simply transform between BaseUri and Mirror
string BaseUri; // the original mirror://... url
string Mirror; // the selected mirror uri (http://...)
// we simply transform between BaseUri and Mirror
string BaseUri; // the original mirror://... url
string Mirror; // the selected mirror uri (http://...)
+ vector<string> AllMirrors; // all available mirrors
string MirrorFile; // the file that contains the list of mirrors
bool DownloadedMirrorFile; // already downloaded this session
string MirrorFile; // the file that contains the list of mirrors
bool DownloadedMirrorFile; // already downloaded this session
protected:
bool DownloadMirrorFile(string uri);
string GetMirrorFileName(string uri);
protected:
bool DownloadMirrorFile(string uri);
string GetMirrorFileName(string uri);
+ bool InitMirrors();
+ bool SelectNextMirror();
bool Clean(string dir);
// we need to overwrite those to transform the url back
bool Clean(string dir);
// we need to overwrite those to transform the url back