From f8c1f8e4763fa9b885a90a08b5a8bf3688a60b8d Mon Sep 17 00:00:00 2001 From: Fabian Groffen Date: Fri, 22 Jun 2007 08:32:45 +0000 Subject: [PATCH] Merged from trunk 6861:6867 +------------------------------------------------------------------------+ | 6862 | Fix profile and config arguments to NewsItem.isRelevant() | | zmedico | inside NewsManager.updateItems(). | |---------+--------------------------------------------------------------| | 6863 | For bug #182346, use dblink.isowner() during unmerge so that | | zmedico | device/inode numbers are used to determine ownership | | | (despite path mismatch due to symlinks). | |---------+--------------------------------------------------------------| | 6865 | In dblink.isowner() don't bother to stat the file when it's | | zmedico | contained in the contents. | |---------+--------------------------------------------------------------| | 6867 | During unmerge, always verify that the file isn't a symlink | | zmedico | before doing chmod. | +------------------------------------------------------------------------+ svn path=/main/branches/prefix/; revision=6942 --- pym/portage/dbapi/vartree.py | 39 +++++++++++++++++++++++------------- pym/portage/news.py | 12 ++++++++++- 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/pym/portage/dbapi/vartree.py b/pym/portage/dbapi/vartree.py index 9cc678c62..35ed7fe08 100644 --- a/pym/portage/dbapi/vartree.py +++ b/pym/portage/dbapi/vartree.py @@ -1146,9 +1146,9 @@ class dblink(object): others_in_slot.append(dblink(self.cat, catsplit(cur_cpv)[1], self.vartree.root, self.settings, vartree=self.vartree)) - claimed_paths = set() - for dblnk in others_in_slot: - claimed_paths.update(dblnk.getcontents()) + dest_root = normalize_path(self.vartree.root).rstrip(os.path.sep) + \ + os.path.sep + dest_root_len = len(dest_root) unmerge_orphans = "unmerge-orphans" in self.settings.features @@ -1164,12 +1164,6 @@ class dblink(object): obj = normalize_path(objkey) file_data = pkgfiles[objkey] file_type = file_data[0] - if obj in claimed_paths: - # A new instance of this package claims the file, so don't - # unmerge it. - writemsg_stdout("--- !owned %s %s\n" % \ - (pkgfiles[objkey][0], obj)) - continue statobj = None try: statobj = os.stat(obj) @@ -1184,6 +1178,19 @@ class dblink(object): if lstatobj is None: writemsg_stdout("--- !found %s %s\n" % (file_type, obj)) continue + if obj.startswith(dest_root): + relative_path = obj[dest_root_len:] + is_owned = False + for dblnk in others_in_slot: + if dblnk.isowner(relative_path, dest_root): + is_owned = True + break + if is_owned: + # A new instance of this package claims the file, so + # don't unmerge it. + writemsg_stdout("--- !owned %s %s\n" % \ + (file_type, obj)) + continue # next line includes a tweak to protect modules from being unmerged, # but we don't protect modules from being overwritten if they are # upgraded. We effectively only want one half of the config protection @@ -1256,7 +1263,8 @@ class dblink(object): try: # Remove permissions to ensure that any hardlinks to # suid/sgid files are rendered harmless. - os.chmod(obj, 0) + if not islink: + os.chmod(obj, 0) os.unlink(obj) except (OSError, IOError), e: pass @@ -1298,15 +1306,18 @@ class dblink(object): """ destfile = normalize_path( os.path.join(destroot, filename.lstrip(os.path.sep))) - try: - mylstat = os.lstat(destfile) - except (OSError, IOError): - return True pkgfiles = self.getcontents() if pkgfiles and destfile in pkgfiles: return True if pkgfiles: + try: + mylstat = os.lstat(destfile) + except EnvironmentError, e: + if e.errno != errno.ENOENT: + raise + del e + return True if self._contents_inodes is None: self._contents_inodes = set() for x in pkgfiles: diff --git a/pym/portage/news.py b/pym/portage/news.py index 028805876..d8df8c294 100644 --- a/pym/portage/news.py +++ b/pym/portage/news.py @@ -36,6 +36,15 @@ class NewsManager(object): self.vdb = vardb self.portdb = portdb + portdir = portdb.porttree_root + profiles_base = os.path.join(portdir, "profiles") + os.path.sep + from portage.util import normalize_path + profile_path = normalize_path( + os.path.realpath(portdb.mysettings.profile_path)) + if profile_path.startswith(profiles_base): + profile_path = profile_path[len(profiles_base):] + self._profile_path = profile_path + # Ensure that the unread path exists and is writable. dirmode = 02070 modemask = 02 @@ -76,7 +85,8 @@ class NewsManager(object): item = NewsItem(filename, itemid, timestamp) except (TypeError, ValueError), e: continue - if item.isRelevant(profile=os.readlink(PROFILE_PATH), config=config, vardb=self.vdb): + if item.isRelevant(profile=self._profile_path, + config=self.config, vardb=self.vdb): updates.append(item) del path -- 2.26.2