Merged from trunk 6861:6867
authorFabian Groffen <grobian@gentoo.org>
Fri, 22 Jun 2007 08:32:45 +0000 (08:32 -0000)
committerFabian Groffen <grobian@gentoo.org>
Fri, 22 Jun 2007 08:32:45 +0000 (08:32 -0000)
   +------------------------------------------------------------------------+
   | 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
pym/portage/news.py

index 9cc678c6200e567ff644e51eb40cec0e403fab56..35ed7fe086e467711fa5e691335c3c93ea0d9611 100644 (file)
@@ -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:
index 0288058760c68758d0442678cd1b9bc7250b9cc7..d8df8c294257b5c0c670a3f548bbec84e5c72864 100644 (file)
@@ -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