If an uninstall task fails inside MergeTask.merge(), use an UninstallFailure
authorZac Medico <zmedico@gentoo.org>
Fri, 9 May 2008 03:42:02 +0000 (03:42 -0000)
committerZac Medico <zmedico@gentoo.org>
Fri, 9 May 2008 03:42:02 +0000 (03:42 -0000)
exception to handle it instead of allowing unmerge() to call exit().
(trunk r10262)

svn path=/main/branches/2.1.2/; revision=10263

bin/emerge

index ef64ef1b36ac9ebcc867e7556143724a91c13013..4c6b76dddd2ee92c6657c58fd7dc45d97efd3567 100755 (executable)
@@ -5863,11 +5863,16 @@ class MergeTask(object):
                                mergecount += 1
                        pkg = x
                        metadata = pkg.metadata
+
                        if pkg.installed:
                                if not (buildpkgonly or fetchonly or pretend):
-                                       unmerge(root_config.settings, self.myopts,
-                                               root_config.trees["vartree"], "unmerge",
-                                               [pkg.cpv], mtimedb["ldpath"], clean_world=0)
+                                       try:
+                                               unmerge(root_config.settings, self.myopts,
+                                                       root_config.trees["vartree"], "unmerge",
+                                                       [pkg.cpv], mtimedb["ldpath"], clean_world=0,
+                                                       raise_on_error=1)
+                                       except UninstallFailure, e:
+                                               return e.status
                                continue
 
                        if x[0]=="blocks":
@@ -6186,8 +6191,20 @@ class MergeTask(object):
                                sys.exit(0)
                return os.EX_OK
 
-def unmerge(settings, myopts, vartree, unmerge_action, unmerge_files,
-       ldpath_mtimes, autoclean=0, clean_world=1, ordered=0):
+class UninstallFailure(portage_exception.PortageException):
+       """
+       An instance of this class is raised by unmerge() when
+       an uninstallation fails.
+       """
+       status = 1
+       def __init__(self, *pargs):
+               portage_exception.PortageException.__init__(self, pargs)
+               if pargs:
+                       self.status = pargs[0]
+
+def unmerge(settings, myopts, vartree, unmerge_action,
+       unmerge_files, ldpath_mtimes, autoclean=0,
+       clean_world=1, ordered=0, raise_on_error=0):
        candidate_catpkgs=[]
        global_unmerge=0
        xterm_titles = "notitles" not in settings.features
@@ -6518,6 +6535,8 @@ def unmerge(settings, myopts, vartree, unmerge_action, unmerge_files,
                                vartree=vartree, ldpath_mtimes=ldpath_mtimes)
                        if retval != os.EX_OK:
                                emergelog(xterm_titles, " !!! unmerge FAILURE: "+y)
+                               if raise_on_error:
+                                       raise UninstallFailure(retval)
                                sys.exit(retval)
                        else:
                                if clean_world: