Gentoo Archives: gentoo-portage-dev

From: Zac Medico <zmedico@g.o>
To: gentoo-portage-dev@l.g.o
Cc: Zac Medico <zmedico@g.o>
Subject: [gentoo-portage-dev] [PATCH 1/2] template.database.__getitem__: allow missing mtime (bug 568934)
Date: Thu, 24 Dec 2015 11:31:21
Message-Id: 1450956643-26923-1-git-send-email-zmedico@gentoo.org
1 Fix __getitem__ to allow missing mtime when a suitable alternative
2 (such as md5) is available.
3
4 Fixes: 669d11bd8af5 ("flat_hash: enable md5 validation for /var/cache/edb/dep (bug 568934)")
5 ---
6 pym/portage/cache/template.py | 36 ++++++++++++++++++++++--------------
7 1 file changed, 22 insertions(+), 14 deletions(-)
8
9 diff --git a/pym/portage/cache/template.py b/pym/portage/cache/template.py
10 index a942b36..a7c6de0 100644
11 --- a/pym/portage/cache/template.py
12 +++ b/pym/portage/cache/template.py
13 @@ -46,12 +46,13 @@ class database(object):
14 self.commit()
15 self.updates = 0
16 d=self._getitem(cpv)
17 - if self.serialize_eclasses and "_eclasses_" in d:
18 - try:
19 - chf_types = self.chf_types
20 - except AttributeError:
21 - chf_types = (self.validation_chf,)
22
23 + try:
24 + chf_types = self.chf_types
25 + except AttributeError:
26 + chf_types = (self.validation_chf,)
27 +
28 + if self.serialize_eclasses and "_eclasses_" in d:
29 for chf_type in chf_types:
30 try:
31 d["_eclasses_"] = reconstruct_eclasses(cpv, d["_eclasses_"],
32 @@ -69,16 +70,23 @@ class database(object):
33 # to omit it in comparisons between cache entries like
34 # those that egencache uses to avoid redundant writes.
35 d.pop("INHERITED", None)
36 +
37 + mtime_required = not any(d.get('_%s_' % x)
38 + for x in chf_types if x != 'mtime')
39 +
40 mtime = d.get('_mtime_')
41 - if mtime is None:
42 - raise cache_errors.CacheCorruption(cpv,
43 - '_mtime_ field is missing')
44 - try:
45 - mtime = long(mtime)
46 - except ValueError:
47 - raise cache_errors.CacheCorruption(cpv,
48 - '_mtime_ conversion to long failed: %s' % (mtime,))
49 - d['_mtime_'] = mtime
50 + if not mtime:
51 + if mtime_required:
52 + raise cache_errors.CacheCorruption(cpv,
53 + '_mtime_ field is missing')
54 + d.pop('_mtime_', None)
55 + else:
56 + try:
57 + mtime = long(mtime)
58 + except ValueError:
59 + raise cache_errors.CacheCorruption(cpv,
60 + '_mtime_ conversion to long failed: %s' % (mtime,))
61 + d['_mtime_'] = mtime
62 return d
63
64 def _getitem(self, cpv):
65 --
66 2.4.10

Replies