public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Zac Medico" <zmedico@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/gentoolkit:master commit in: pym/gentoolkit/revdep_rebuild/
Date: Fri, 10 Mar 2017 17:31:33 +0000 (UTC)	[thread overview]
Message-ID: <1489167053.9ffefd66e618155ffb479cd1dbce9c3afe9a9ea4.zmedico@gentoo> (raw)

commit:     9ffefd66e618155ffb479cd1dbce9c3afe9a9ea4
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Fri Mar 10 09:38:04 2017 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Fri Mar 10 17:30:53 2017 +0000
URL:        https://gitweb.gentoo.org/proj/gentoolkit.git/commit/?id=9ffefd66

revdep_rebuild/assign.py: handle directory symlinks (bug 611808)

Use a _file_matcher class to make file comparisons work regardless
of directory symlinks.

X-Gentoo-bug: 611808
X-Gentoo-bug-url: https://bugs.gentoo.org/show_bug.cgi?id=611808
Acked-by: Brian Dolbec <dolsen <AT> gentoo.org>

 pym/gentoolkit/revdep_rebuild/assign.py | 67 +++++++++++++++++++++++++++++----
 1 file changed, 60 insertions(+), 7 deletions(-)

diff --git a/pym/gentoolkit/revdep_rebuild/assign.py b/pym/gentoolkit/revdep_rebuild/assign.py
index 00dda6e..84bd59f 100644
--- a/pym/gentoolkit/revdep_rebuild/assign.py
+++ b/pym/gentoolkit/revdep_rebuild/assign.py
@@ -6,6 +6,7 @@ Functions used for determining the package the broken lib belongs to.
 
 from __future__ import print_function
 
+import errno
 import os
 import io
 import re
@@ -22,11 +23,61 @@ try:
 except NameError:
 	pass
 
+
+class _file_matcher(object):
+	"""
+	Compares files by basename and parent directory (device, inode),
+	so comparisons work regardless of directory symlinks. If a
+	parent directory does not exist, the realpath of the parent
+	directory is used instead of the (device, inode). When multiple
+	files share the same parent directory, stat is only called
+	once per directory, and the result is cached internally.
+	"""
+	def __init__(self):
+		self._file_ids = {}
+		self._added = {}
+
+	def _file_id(self, filename):
+		try:
+			return self._file_ids[filename]
+		except KeyError:
+			try:
+				st = os.stat(filename)
+			except OSError as e:
+				if e.errno != errno.ENOENT:
+					raise
+				file_id = (os.path.realpath(filename),)
+			else:
+				file_id = (st.st_dev, st.st_ino)
+
+			self._file_ids[filename] = file_id
+			return file_id
+
+	def _file_key(self, filename):
+		head, tail = os.path.split(filename)
+		key = self._file_id(head) + (tail,)
+		return key
+
+	def add(self, filename):
+		self._added[self._file_key(filename)] = filename
+
+	def intersection(self, other):
+		for file_key in self._added:
+			match = other._added.get(file_key)
+			if match is not None:
+				yield match
+
+
 def assign_packages(broken, logger, settings):
 	''' Finds and returns packages that owns files placed in broken.
 		Broken is list of files
 	'''
 	stime = current_milli_time()
+
+	broken_matcher = _file_matcher()
+	for filename in broken:
+		broken_matcher.add(filename)
+
 	assigned_pkgs = set()
 	assigned_filenames = set()
 	for group in os.listdir(settings['PKG_DIR']):
@@ -39,21 +90,23 @@ def assign_packages(broken, logger, settings):
 				continue
 			f = pkgpath + '/CONTENTS'
 			if os.path.exists(f):
+				contents_matcher = _file_matcher()
 				try:
 					with io.open(f, 'r', encoding='utf_8') as cnt:
 						for line in cnt.readlines():
 							m = re.match('^obj (/[^ ]+)', line)
 							if m is not None:
-								m = m.group(1)
-								if m in broken:
-									found = group+'/'+pkg
-									assigned_pkgs.add(found)
-									assigned_filenames.add(m)
-									logger.info('\t' + green('* ') + m +
-												' -> ' + bold(found))
+								contents_matcher.add(m.group(1))
 				except Exception as e:
 					logger.warning(red(' !! Failed to read ' + f))
 					logger.warning(red(' !! Error was:' + str(e)))
+				else:
+					for m in contents_matcher.intersection(broken_matcher):
+						found = group+'/'+pkg
+						assigned_pkgs.add(found)
+						assigned_filenames.add(m)
+						logger.info('\t' + green('* ') + m +
+									' -> ' + bold(found))
 
 	broken_filenames = set(broken)
 	orphaned = broken_filenames.difference(assigned_filenames)


             reply	other threads:[~2017-03-10 17:31 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-10 17:31 Zac Medico [this message]
  -- strict thread matches above, loose matches on Subject: below --
2022-07-09  1:49 [gentoo-commits] proj/gentoolkit:master commit in: pym/gentoolkit/revdep_rebuild/ Mike Gilbert
2020-02-14 18:13 Zac Medico
2019-08-19  3:41 Zac Medico
2019-08-19  3:41 Zac Medico
2017-05-05 19:38 Paul Varner
2016-12-29 21:36 Jason Donenfeld
2016-09-15 15:05 Brian Dolbec
2016-09-15 15:05 Brian Dolbec
2016-08-15 21:06 Paul Varner
2016-06-09 19:38 Slawek Lis
2016-05-18 15:41 Brian Dolbec
2016-05-18 15:41 Brian Dolbec
2016-05-18 15:14 Brian Dolbec
2016-05-18  6:10 Brian Dolbec
2016-02-25 21:26 Brian Dolbec
2016-01-18  0:00 Jason Donenfeld
2015-12-20  2:05 Brian Dolbec
2015-12-16 17:53 Brian Dolbec

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1489167053.9ffefd66e618155ffb479cd1dbce9c3afe9a9ea4.zmedico@gentoo \
    --to=zmedico@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox