From 78c8f3cd7e0d2a61ee564cb010277bccb232b523 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 14 Mar 2011 18:03:14 +0100 Subject: methods/mirror.cc: randomize only based on hostname --- methods/mirror.cc | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/methods/mirror.cc b/methods/mirror.cc index ed42cdbfb..e499b054b 100644 --- a/methods/mirror.cc +++ b/methods/mirror.cc @@ -16,12 +16,15 @@ #include #include -#include + #include +#include #include + #include #include #include +#include #include 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(); -- cgit v1.2.3