Bug #244975 - Don't allow the user to make portage unmerge itself since
authorZac Medico <zmedico@gentoo.org>
Thu, 30 Oct 2008 22:18:55 +0000 (22:18 -0000)
committerZac Medico <zmedico@gentoo.org>
Thu, 30 Oct 2008 22:18:55 +0000 (22:18 -0000)
there's never any valid reason to do so.

svn path=/main/trunk/; revision=11756

pym/_emerge/__init__.py

index 8e2df4d5804e4b73a32dc59d1069a3ed5e9fb15d..bbfd073973693acfbb50ffcd9f209faf17bb404c 100644 (file)
@@ -10489,7 +10489,7 @@ def unmerge(root_config, myopts, unmerge_action,
        candidate_catpkgs=[]
        global_unmerge=0
        xterm_titles = "notitles" not in settings.features
-
+       out = portage.output.EOutput()
        pkg_cache = {}
        db_keys = list(vartree.dbapi._aux_cache_keys)
 
@@ -10754,6 +10754,21 @@ def unmerge(root_config, myopts, unmerge_action,
                                # It could have been uninstalled
                                # by a concurrent process.
                                continue
+
+                       if unmerge_action != "clean" and \
+                               root_config.root == "/" and \
+                               portage.match_from_list(
+                               portage.const.PORTAGE_PACKAGE_ATOM, [pkg]):
+                               msg = ("Not unmerging package %s since there is no valid " + \
+                               "reason for portage to unmerge itself.") % (pkg.cpv,)
+                               for line in textwrap.wrap(msg, 75):
+                                       out.eerror(line)
+                               # adjust pkgmap so the display output is correct
+                               pkgmap[cp]["selected"].remove(cpv)
+                               all_selected.remove(cpv)
+                               pkgmap[cp]["protected"].add(cpv)
+                               continue
+
                        parents = []
                        for s in installed_sets:
                                # skip sets that the user requested to unmerge, and skip world 
@@ -10812,10 +10827,18 @@ def unmerge(root_config, myopts, unmerge_action,
                                print "    %s\n" % ", ".join(parents)
                                # adjust pkgmap so the display output is correct
                                pkgmap[cp]["selected"].remove(cpv)
+                               all_selected.remove(cpv)
                                pkgmap[cp]["protected"].add(cpv)
        
        del installed_sets
 
+       numselected = len(all_selected)
+       if not numselected:
+               writemsg_level(
+                       "\n>>> No packages selected for removal by " + \
+                       unmerge_action + "\n")
+               return 0
+
        # Unmerge order only matters in some cases
        if not ordered:
                unordered = {}