1 |
With python 3.3 and later, hash randomization causes __hash__() results |
2 |
to vary randomly for each run. Fix gen_label to use a md5 digest which |
3 |
gives consistent results for all runs. Maintain backward compatible |
4 |
behavior for older python when hash randomization is disabled. This |
5 |
fixes the anydbm module so that its database file name will be |
6 |
consistent for all runs (no randomization). |
7 |
--- |
8 |
pym/portage/cache/fs_template.py | 12 ++++++++++-- |
9 |
1 file changed, 10 insertions(+), 2 deletions(-) |
10 |
|
11 |
diff --git a/pym/portage/cache/fs_template.py b/pym/portage/cache/fs_template.py |
12 |
index fa44abc..05dfaab 100644 |
13 |
--- a/pym/portage/cache/fs_template.py |
14 |
+++ b/pym/portage/cache/fs_template.py |
15 |
@@ -5,10 +5,11 @@ |
16 |
import os as _os |
17 |
import sys |
18 |
from portage.cache import template |
19 |
-from portage import os |
20 |
+from portage import os, _unicode_encode |
21 |
|
22 |
from portage.proxy.lazyimport import lazyimport |
23 |
lazyimport(globals(), |
24 |
+ 'portage:checksum', |
25 |
'portage.exception:PortageException', |
26 |
'portage.util:apply_permissions,ensure_dirs', |
27 |
) |
28 |
@@ -89,5 +90,12 @@ def gen_label(base, label): |
29 |
label = label.strip("\"").strip("'") |
30 |
label = os.path.join(*(label.rstrip(os.path.sep).split(os.path.sep))) |
31 |
tail = os.path.split(label)[1] |
32 |
- return "%s-%X" % (tail, abs(label.__hash__())) |
33 |
+ if sys.hexversion >= 0x3030000 or os.environ.get("PYTHONHASHSEED") == "random": |
34 |
+ # Hash randomization makes __hash__() random, so don't use it. |
35 |
+ hexdigest = checksum._new_md5(_unicode_encode(label)).hexdigest() |
36 |
+ else: |
37 |
+ # backward compat |
38 |
+ hexdigest = "%X" % abs(label.__hash__()) |
39 |
+ |
40 |
+ return "%s-%s" % (tail, hexdigest) |
41 |
|
42 |
-- |
43 |
2.4.10 |