summaryrefslogtreecommitdiff
path: root/methods
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2011-03-14 18:03:14 +0100
committerMichael Vogt <michael.vogt@ubuntu.com>2011-03-14 18:03:14 +0100
commit78c8f3cd7e0d2a61ee564cb010277bccb232b523 (patch)
tree80a15a6df31f9a0ecf01bd8654c66f0fa012d5ac /methods
parent0190e315a34377c658fa3acb5c658a6b4a52ae1e (diff)
downloadapt-78c8f3cd7e0d2a61ee564cb010277bccb232b523.tar.gz
methods/mirror.cc: randomize only based on hostname
Diffstat (limited to 'methods')
-rw-r--r--methods/mirror.cc19
1 files changed, 15 insertions, 4 deletions
diff --git a/methods/mirror.cc b/methods/mirror.cc
index ed42cdbf..e499b054 100644
--- a/methods/mirror.cc
+++ b/methods/mirror.cc
@@ -16,12 +16,15 @@
#include <apt-pkg/hashes.h>
#include <apt-pkg/sourcelist.h>
-#include <fstream>
+
#include <algorithm>
+#include <fstream>
#include <iostream>
+
#include <stdarg.h>
#include <sys/stat.h>
#include <sys/types.h>
+#include <sys/utsname.h>
#include <dirent.h>
using namespace std;
@@ -162,7 +165,17 @@ bool MirrorMethod::RandomizeMirrorFile(string mirror_file)
content.push_back(line);
}
- // randomize
+ // we want the file to be random for each different machine, but also
+ // "stable" on the same machine. this is to avoid running into out-of-sync
+ // issues (i.e. Release/Release.gpg different on each mirror)
+ struct utsname buf;
+ int seed=1, i;
+ if(uname(&buf) == 0) {
+ for(i=0,seed=1; buf.nodename[i] != 0; i++) {
+ seed = seed * 31 + buf.nodename[i];
+ }
+ }
+ srand( seed );
random_shuffle(content.begin(), content.end());
// write
@@ -403,8 +416,6 @@ int main()
{
setlocale(LC_ALL, "");
- srand ( time(NULL) );
-
MirrorMethod Mth;
return Mth.Loop();