1 |
Since operations like `git reset --hard` (useful to implement shallow |
2 |
pull) will reset timestamps of all files in the tree, the status quo |
3 |
of using timestamps for validation of cache in /var/cache/edb/dep |
4 |
is sub-optimal. |
5 |
|
6 |
For forward-compatibility, add a flat_hash.mtime_md5_database cache |
7 |
module which is capable of validating cache entries containing either |
8 |
mtimes or md5 digests. Update the config class to use this cache |
9 |
module by default for /var/cache/edb/dep. |
10 |
|
11 |
X-Gentoo-Bug: 568934 |
12 |
X-Gentoo-Bug-url: https://bugs.gentoo.org/show_bug.cgi?id=568934 |
13 |
--- |
14 |
[PATCH v2] only updates the commit message to mention the motivation for using |
15 |
md5 instead of mtime. |
16 |
|
17 |
pym/portage/cache/flat_hash.py | 5 +++++ |
18 |
pym/portage/cache/template.py | 35 ++++++++++++++++++++++++++++++----- |
19 |
pym/portage/package/ebuild/config.py | 6 +++--- |
20 |
3 files changed, 38 insertions(+), 8 deletions(-) |
21 |
|
22 |
diff --git a/pym/portage/cache/flat_hash.py b/pym/portage/cache/flat_hash.py |
23 |
index 5304296..cca0f10 100644 |
24 |
--- a/pym/portage/cache/flat_hash.py |
25 |
+++ b/pym/portage/cache/flat_hash.py |
26 |
@@ -160,3 +160,8 @@ class md5_database(database): |
27 |
|
28 |
validation_chf = 'md5' |
29 |
store_eclass_paths = False |
30 |
+ |
31 |
+ |
32 |
+class mtime_md5_database(database): |
33 |
+ validation_chf = 'mtime' |
34 |
+ chf_types = ('mtime', 'md5') |
35 |
diff --git a/pym/portage/cache/template.py b/pym/portage/cache/template.py |
36 |
index bc81b86..a942b36 100644 |
37 |
--- a/pym/portage/cache/template.py |
38 |
+++ b/pym/portage/cache/template.py |
39 |
@@ -47,8 +47,21 @@ class database(object): |
40 |
self.updates = 0 |
41 |
d=self._getitem(cpv) |
42 |
if self.serialize_eclasses and "_eclasses_" in d: |
43 |
- d["_eclasses_"] = reconstruct_eclasses(cpv, d["_eclasses_"], |
44 |
- self.validation_chf, paths=self.store_eclass_paths) |
45 |
+ try: |
46 |
+ chf_types = self.chf_types |
47 |
+ except AttributeError: |
48 |
+ chf_types = (self.validation_chf,) |
49 |
+ |
50 |
+ for chf_type in chf_types: |
51 |
+ try: |
52 |
+ d["_eclasses_"] = reconstruct_eclasses(cpv, d["_eclasses_"], |
53 |
+ chf_type, paths=self.store_eclass_paths) |
54 |
+ except cache_errors.CacheCorruption: |
55 |
+ if chf_type is chf_types[-1]: |
56 |
+ raise |
57 |
+ else: |
58 |
+ break |
59 |
+ |
60 |
elif "_eclasses_" not in d: |
61 |
d["_eclasses_"] = {} |
62 |
# Never return INHERITED, since portdbapi.aux_get() will |
63 |
@@ -204,15 +217,27 @@ class database(object): |
64 |
return x |
65 |
|
66 |
def validate_entry(self, entry, ebuild_hash, eclass_db): |
67 |
- hash_key = '_%s_' % self.validation_chf |
68 |
+ try: |
69 |
+ chf_types = self.chf_types |
70 |
+ except AttributeError: |
71 |
+ chf_types = (self.validation_chf,) |
72 |
+ |
73 |
+ for chf_type in chf_types: |
74 |
+ if self._validate_entry(chf_type, entry, ebuild_hash, eclass_db): |
75 |
+ return True |
76 |
+ |
77 |
+ return False |
78 |
+ |
79 |
+ def _validate_entry(self, chf_type, entry, ebuild_hash, eclass_db): |
80 |
+ hash_key = '_%s_' % chf_type |
81 |
try: |
82 |
entry_hash = entry[hash_key] |
83 |
except KeyError: |
84 |
return False |
85 |
else: |
86 |
- if entry_hash != getattr(ebuild_hash, self.validation_chf): |
87 |
+ if entry_hash != getattr(ebuild_hash, chf_type): |
88 |
return False |
89 |
- update = eclass_db.validate_and_rewrite_cache(entry['_eclasses_'], self.validation_chf, |
90 |
+ update = eclass_db.validate_and_rewrite_cache(entry['_eclasses_'], chf_type, |
91 |
self.store_eclass_paths) |
92 |
if update is None: |
93 |
return False |
94 |
diff --git a/pym/portage/package/ebuild/config.py b/pym/portage/package/ebuild/config.py |
95 |
index d45c2a0..0bae55b 100644 |
96 |
--- a/pym/portage/package/ebuild/config.py |
97 |
+++ b/pym/portage/package/ebuild/config.py |
98 |
@@ -160,8 +160,8 @@ class config(object): |
99 |
'repository', 'RESTRICT', 'LICENSE',) |
100 |
|
101 |
_module_aliases = { |
102 |
- "cache.metadata_overlay.database" : "portage.cache.flat_hash.database", |
103 |
- "portage.cache.metadata_overlay.database" : "portage.cache.flat_hash.database", |
104 |
+ "cache.metadata_overlay.database" : "portage.cache.flat_hash.mtime_md5_database", |
105 |
+ "portage.cache.metadata_overlay.database" : "portage.cache.flat_hash.mtime_md5_database", |
106 |
} |
107 |
|
108 |
_case_insensitive_vars = special_env_vars.case_insensitive_vars |
109 |
@@ -444,7 +444,7 @@ class config(object): |
110 |
(user_auxdbmodule, modules_file)) |
111 |
|
112 |
self.modules["default"] = { |
113 |
- "portdbapi.auxdbmodule": "portage.cache.flat_hash.database", |
114 |
+ "portdbapi.auxdbmodule": "portage.cache.flat_hash.mtime_md5_database", |
115 |
} |
116 |
|
117 |
self.configlist=[] |
118 |
-- |
119 |
2.4.10 |