public inbox for gentoo-portage-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-portage-dev] [PATCH 1/2] template.database.__getitem__: allow missing mtime (bug 568934)
@ 2015-12-24 11:30 Zac Medico
  2015-12-24 11:30 ` [gentoo-portage-dev] [PATCH 2/2] sqlite: enable md5 validation " Zac Medico
  0 siblings, 1 reply; 3+ messages in thread
From: Zac Medico @ 2015-12-24 11:30 UTC (permalink / raw
  To: gentoo-portage-dev; +Cc: Zac Medico

Fix __getitem__ to allow missing mtime when a suitable alternative
(such as md5) is available.

Fixes: 669d11bd8af5 ("flat_hash: enable md5 validation for /var/cache/edb/dep (bug 568934)")
---
 pym/portage/cache/template.py | 36 ++++++++++++++++++++++--------------
 1 file changed, 22 insertions(+), 14 deletions(-)

diff --git a/pym/portage/cache/template.py b/pym/portage/cache/template.py
index a942b36..a7c6de0 100644
--- a/pym/portage/cache/template.py
+++ b/pym/portage/cache/template.py
@@ -46,12 +46,13 @@ class database(object):
 			self.commit()
 			self.updates = 0
 		d=self._getitem(cpv)
-		if self.serialize_eclasses and "_eclasses_" in d:
-			try:
-				chf_types = self.chf_types
-			except AttributeError:
-				chf_types = (self.validation_chf,)
 
+		try:
+			chf_types = self.chf_types
+		except AttributeError:
+			chf_types = (self.validation_chf,)
+
+		if self.serialize_eclasses and "_eclasses_" in d:
 			for chf_type in chf_types:
 				try:
 					d["_eclasses_"] = reconstruct_eclasses(cpv, d["_eclasses_"],
@@ -69,16 +70,23 @@ class database(object):
 		# to omit it in comparisons between cache entries like
 		# those that egencache uses to avoid redundant writes.
 		d.pop("INHERITED", None)
+
+		mtime_required = not any(d.get('_%s_' % x)
+			for x in chf_types if x != 'mtime')
+
 		mtime = d.get('_mtime_')
-		if mtime is None:
-			raise cache_errors.CacheCorruption(cpv,
-				'_mtime_ field is missing')
-		try:
-			mtime = long(mtime)
-		except ValueError:
-			raise cache_errors.CacheCorruption(cpv,
-				'_mtime_ conversion to long failed: %s' % (mtime,))
-		d['_mtime_'] = mtime
+		if not mtime:
+			if mtime_required:
+				raise cache_errors.CacheCorruption(cpv,
+					'_mtime_ field is missing')
+			d.pop('_mtime_', None)
+		else:
+			try:
+				mtime = long(mtime)
+			except ValueError:
+				raise cache_errors.CacheCorruption(cpv,
+					'_mtime_ conversion to long failed: %s' % (mtime,))
+			d['_mtime_'] = mtime
 		return d
 
 	def _getitem(self, cpv):
-- 
2.4.10



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [gentoo-portage-dev] [PATCH 2/2] sqlite: enable md5 validation (bug 568934)
  2015-12-24 11:30 [gentoo-portage-dev] [PATCH 1/2] template.database.__getitem__: allow missing mtime (bug 568934) Zac Medico
@ 2015-12-24 11:30 ` Zac Medico
  2015-12-29 10:20   ` Alexander Berntsen
  0 siblings, 1 reply; 3+ messages in thread
From: Zac Medico @ 2015-12-24 11:30 UTC (permalink / raw
  To: gentoo-portage-dev; +Cc: Zac Medico

Add forward-compatibility for cache entries containing md5 digests
instead of mtimes for validation.

X-Gentoo-Bug: 568934
X-Gentoo-Bug-url: https://bugs.gentoo.org/show_bug.cgi?id=568934
---
 pym/portage/cache/sqlite.py | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/pym/portage/cache/sqlite.py b/pym/portage/cache/sqlite.py
index 310ac94..32e4076 100644
--- a/pym/portage/cache/sqlite.py
+++ b/pym/portage/cache/sqlite.py
@@ -18,6 +18,9 @@ if sys.hexversion >= 0x3000000:
 
 class database(fs_template.FsBased):
 
+	validation_chf = 'mtime'
+	chf_types = ('mtime', 'md5')
+
 	autocommits = False
 	synchronous = False
 	# cache_bytes is used together with page_size (set at sqlite build time)
@@ -28,10 +31,12 @@ class database(fs_template.FsBased):
 	def __init__(self, *args, **config):
 		super(database, self).__init__(*args, **config)
 		self._import_sqlite()
-		self._allowed_keys = ["_mtime_", "_eclasses_"]
+		self._allowed_keys = ["_eclasses_"]
 		self._allowed_keys.extend(self._known_keys)
-		self._allowed_keys.sort()
+		self._allowed_keys.extend('_%s_' % k for k in self.chf_types)
 		self._allowed_keys_set = frozenset(self._allowed_keys)
+		self._allowed_keys = sorted(self._allowed_keys_set)
+
 		self.location = os.path.join(self.location, 
 			self.label.lstrip(os.path.sep).rstrip(os.path.sep))
 
-- 
2.4.10



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [gentoo-portage-dev] [PATCH 2/2] sqlite: enable md5 validation (bug 568934)
  2015-12-24 11:30 ` [gentoo-portage-dev] [PATCH 2/2] sqlite: enable md5 validation " Zac Medico
@ 2015-12-29 10:20   ` Alexander Berntsen
  0 siblings, 0 replies; 3+ messages in thread
From: Alexander Berntsen @ 2015-12-29 10:20 UTC (permalink / raw
  To: gentoo-portage-dev

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

These two are eh probably fine.

- -- 
Alexander
bernalex@gentoo.org
https://secure.plaimi.net/~alexander
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQIcBAEBCgAGBQJWgl55AAoJENQqWdRUGk8Bdk0P/1eXVvw6qq2Baz9pOBN39sQ0
WQ2/WSIQYBgGE9lpmCoJUBviB8nzTFC4Yrxt+e6lyRHhYqMCxCOvBL81MG66ChjL
/HTSK4Sd6hjcaJUprcwc22NrL4Yiy034U0frmpqOlHZ+Hpe/E4YT9uXwZ+neT/nA
J7CtYnoljP4ZrEsrQlYUXiY9nphWN0rier89qYa/Thd+ZlWZc5NsF70D/p4EZIqZ
kwf9NqkUxML3pe7WJod7jWt30RTfhrVXw/HEvl6FSwZ01gGDevnpGfcbE4xO+fot
nvhrq/hr7z8TYEk9D3KuxcHuTW7wvLr4YWpO55dlzbSzX1mqgpL+2L3/H8dlipve
uE9eIVDJPcYpi+X/1ozb0mgkcV8TxEcMJFqAVsmRdayHlUnaGHK0VtmiEVAwuk3Z
CwWMedQVrkqU3/sk9DF8N+pKiBraGCTUQxGTiqSPloiRCaPUlWbu26rpOLCTG/cb
uLcWcxGvaFkcbm9gHpbbQFwFnOGLLUWN6zjwrs87mWKiwZHNCWrcnVNSFlpf3D0j
cAF1CCw8ElZ3M99sQX0xBGBo7a0czSjxmhnExkolDG4TPWfGTF7ixUNIKdr+TIUC
Dztz3AvQhhCwEkH3T/CvdFZuvyoGVdd9VXnAVvObSmWJHNDVRNaVNHd+V2dWu/Xx
Y4K6M5OmLMrUhvR1+jYL
=jZL2
-----END PGP SIGNATURE-----


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-12-29 10:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-24 11:30 [gentoo-portage-dev] [PATCH 1/2] template.database.__getitem__: allow missing mtime (bug 568934) Zac Medico
2015-12-24 11:30 ` [gentoo-portage-dev] [PATCH 2/2] sqlite: enable md5 validation " Zac Medico
2015-12-29 10:20   ` Alexander Berntsen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox