Gentoo Archives: gentoo-commits

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