projects
/
apt.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
0190e31
)
methods/mirror.cc: randomize only based on hostname
author
Michael Vogt
<michael.vogt@ubuntu.com>
Mon, 14 Mar 2011 17:03:14 +0000
(18:03 +0100)
committer
Michael Vogt
<michael.vogt@ubuntu.com>
Mon, 14 Mar 2011 17:03:14 +0000
(18:03 +0100)
methods/mirror.cc
patch
|
blob
|
blame
|
history
diff --git
a/methods/mirror.cc
b/methods/mirror.cc
index ed42cdbfb75087c9011345aa2b5792f4562cb0e5..e499b054b15edb0e36a62bf08417a6867e6aeba4 100644
(file)
--- a/
methods/mirror.cc
+++ b/
methods/mirror.cc
@@
-16,12
+16,15
@@
#include <apt-pkg/hashes.h>
#include <apt-pkg/sourcelist.h>
#include <apt-pkg/hashes.h>
#include <apt-pkg/sourcelist.h>
-#include <fstream>
+
#include <algorithm>
#include <algorithm>
+#include <fstream>
#include <iostream>
#include <iostream>
+
#include <stdarg.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <stdarg.h>
#include <sys/stat.h>
#include <sys/types.h>
+#include <sys/utsname.h>
#include <dirent.h>
using namespace std;
#include <dirent.h>
using namespace std;
@@
-162,7
+165,17
@@
bool MirrorMethod::RandomizeMirrorFile(string mirror_file)
content.push_back(line);
}
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
random_shuffle(content.begin(), content.end());
// write
@@
-403,8
+416,6
@@
int main()
{
setlocale(LC_ALL, "");
{
setlocale(LC_ALL, "");
- srand ( time(NULL) );
-
MirrorMethod Mth;
return Mth.Loop();
MirrorMethod Mth;
return Mth.Loop();