user to insert the CD on each apt-get update
* mirror method:
- when downloading data, show the mirror being used
+ - randomize mirror list to ensure more even load
-- Michael Vogt <michael.vogt@ubuntu.com> Thu, 10 Mar 2011 15:56:54 +0100
#include <apt-pkg/sourcelist.h>
#include <fstream>
+#include <algorithm>
#include <iostream>
#include <stdarg.h>
#include <sys/stat.h>
return res;
}
+// Randomizes the lines in the mirror file, this is used so that
+// we spread the load on the mirrors evenly
+bool MirrorMethod::RandomizeMirrorFile(string mirror_file)
+{
+ vector<string> content;
+ string line;
+
+ // read
+ ifstream in(mirror_file.c_str());
+ while ( ! in.eof() ) {
+ getline(in, line);
+ content.push_back(line);
+ }
+
+ // randomize
+ random_shuffle(content.begin(), content.end());
+
+ // write
+ ofstream out(mirror_file.c_str());
+ while ( !content.empty()) {
+ line = content.back();
+ content.pop_back();
+ out << line << "\n";
+ }
+
+ return true;
+}
+
/* convert a the Queue->Uri back to the mirror base uri and look
* at all mirrors we have for this, this is needed as queue->uri
* may point to different mirrors (if TryNextMirror() was run)
{
Clean(_config->FindDir("Dir::State::mirrors"));
DownloadMirrorFile(Itm->Uri);
+ RandomizeMirrorFile(MirrorFile);
}
if(AllMirrors.empty()) {
protected:
bool DownloadMirrorFile(string uri);
+ bool RandomizeMirrorFile(string file);
string GetMirrorFileName(string uri);
bool InitMirrors();
bool TryNextMirror();