1 |
Change cache modules to write md5 in cache entries, instead of mtime. |
2 |
Since portage-2.2.27, the relevant cache modules have had the ability |
3 |
to read cache entries containing either md5 or mtime, therefore this |
4 |
change is backward-compatible with portage-2.2.27 and later. |
5 |
|
6 |
Also, fix the reconstruct_eclasses function to raise CacheCorruption |
7 |
when the specified chf_type is md5 and the cache entry contains mtime |
8 |
data. This is needed so that the cache module chf_types attributes can |
9 |
list md5 before mtime, without having mtime data be incorrectly |
10 |
interpreted as md5 data. |
11 |
|
12 |
X-Gentoo-Bug: 568934 |
13 |
X-Gentoo-Bug-url: https://bugs.gentoo.org/show_bug.cgi?id=568934 |
14 |
--- |
15 |
pym/portage/cache/anydbm.py | 4 ++-- |
16 |
pym/portage/cache/flat_hash.py | 4 ++-- |
17 |
pym/portage/cache/sqlite.py | 4 ++-- |
18 |
pym/portage/cache/template.py | 19 +++++++++++++++---- |
19 |
4 files changed, 21 insertions(+), 10 deletions(-) |
20 |
|
21 |
diff --git a/pym/portage/cache/anydbm.py b/pym/portage/cache/anydbm.py |
22 |
index 80d24e5..88d85b0 100644 |
23 |
--- a/pym/portage/cache/anydbm.py |
24 |
+++ b/pym/portage/cache/anydbm.py |
25 |
@@ -36,8 +36,8 @@ from portage.cache import cache_errors |
26 |
|
27 |
class database(fs_template.FsBased): |
28 |
|
29 |
- validation_chf = 'mtime' |
30 |
- chf_types = ('mtime', 'md5') |
31 |
+ validation_chf = 'md5' |
32 |
+ chf_types = ('md5', 'mtime') |
33 |
|
34 |
autocommits = True |
35 |
cleanse_keys = True |
36 |
diff --git a/pym/portage/cache/flat_hash.py b/pym/portage/cache/flat_hash.py |
37 |
index cca0f10..3a899c0 100644 |
38 |
--- a/pym/portage/cache/flat_hash.py |
39 |
+++ b/pym/portage/cache/flat_hash.py |
40 |
@@ -163,5 +163,5 @@ class md5_database(database): |
41 |
|
42 |
|
43 |
class mtime_md5_database(database): |
44 |
- validation_chf = 'mtime' |
45 |
- chf_types = ('mtime', 'md5') |
46 |
+ validation_chf = 'md5' |
47 |
+ chf_types = ('md5', 'mtime') |
48 |
diff --git a/pym/portage/cache/sqlite.py b/pym/portage/cache/sqlite.py |
49 |
index 32e4076..69150f6 100644 |
50 |
--- a/pym/portage/cache/sqlite.py |
51 |
+++ b/pym/portage/cache/sqlite.py |
52 |
@@ -18,8 +18,8 @@ if sys.hexversion >= 0x3000000: |
53 |
|
54 |
class database(fs_template.FsBased): |
55 |
|
56 |
- validation_chf = 'mtime' |
57 |
- chf_types = ('mtime', 'md5') |
58 |
+ validation_chf = 'md5' |
59 |
+ chf_types = ('md5', 'mtime') |
60 |
|
61 |
autocommits = False |
62 |
synchronous = False |
63 |
diff --git a/pym/portage/cache/template.py b/pym/portage/cache/template.py |
64 |
index a7c6de0..021c706 100644 |
65 |
--- a/pym/portage/cache/template.py |
66 |
+++ b/pym/portage/cache/template.py |
67 |
@@ -310,6 +310,18 @@ def serialize_eclasses(eclass_dict, chf_type='mtime', paths=True): |
68 |
for k, v in sorted(eclass_dict.items(), key=_keysorter)) |
69 |
|
70 |
|
71 |
+def _md5_deserializer(md5): |
72 |
+ if len(md5) != 32: |
73 |
+ raise ValueError('expected 32 hex digits') |
74 |
+ return md5 |
75 |
+ |
76 |
+ |
77 |
+_chf_deserializers = { |
78 |
+ 'md5': _md5_deserializer, |
79 |
+ 'mtime': long, |
80 |
+} |
81 |
+ |
82 |
+ |
83 |
def reconstruct_eclasses(cpv, eclass_string, chf_type='mtime', paths=True): |
84 |
"""returns a dict when handed a string generated by serialize_eclasses""" |
85 |
eclasses = eclass_string.rstrip().lstrip().split("\t") |
86 |
@@ -317,9 +329,7 @@ def reconstruct_eclasses(cpv, eclass_string, chf_type='mtime', paths=True): |
87 |
# occasionally this occurs in the fs backends. they suck. |
88 |
return {} |
89 |
|
90 |
- converter = _unicode |
91 |
- if chf_type == 'mtime': |
92 |
- converter = long |
93 |
+ converter = _chf_deserializers.get(chf_type, lambda x: x) |
94 |
|
95 |
if paths: |
96 |
if len(eclasses) % 3 != 0: |
97 |
@@ -340,6 +350,7 @@ def reconstruct_eclasses(cpv, eclass_string, chf_type='mtime', paths=True): |
98 |
raise cache_errors.CacheCorruption(cpv, |
99 |
"_eclasses_ was of invalid len %i" % len(eclasses)) |
100 |
except ValueError: |
101 |
- raise cache_errors.CacheCorruption(cpv, "_eclasses_ mtime conversion to long failed") |
102 |
+ raise cache_errors.CacheCorruption(cpv, |
103 |
+ "_eclasses_ not valid for chf_type {}".format(chf_type)) |
104 |
del eclasses |
105 |
return d |
106 |
-- |
107 |
2.7.4 |