[Yum-devel] [PATCH] Return an error code if yum can't install any of the specified packages

Mike Bonnet mikeb at redhat.com
Thu Mar 11 20:31:50 UTC 2010


On 03/11/2010 02:54 PM, James Antill wrote:
>  People want a bash scriptable way to say "X should be installed". So
> with this patch:
> 
> . If _any_ package specified: is installed already; or is found and will
> be installed == yum returns 0 (or at least goes into depchecking etc.)
> 
> . If _all_ package(s) are "not found", yum turns the message "Nothing to do"
> into an error (returns 1, atm).
> 
> ...thus:
> 
> 1. yum install -y a b && echo worked
> 
> This will echo "worked" if _either_ a or b is installed after yum
> finishes, but tries to install both.

I would argue that if I run "yum install -y a b" and either a or b is
not found or not installable for any reason, then nothing should happen
and yum should print an error and return a non-zero exitcode.  Ignoring
missing packages that are explicitly listed on the command-line has
always seemed wrong.

> 2. yum install a && yum install b && echo worked
> 
> This will echo "worked" if both are installed (and if a is not
> available, b will not even try to be installed).
> ---
>  cli.py |    6 ++++++
>  1 files changed, 6 insertions(+), 0 deletions(-)
> 
> diff --git a/cli.py b/cli.py
> index a34d205..cebbae3 100644
> --- a/cli.py
> +++ b/cli.py
> @@ -595,6 +595,7 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
>          
>          oldcount = len(self.tsInfo)
>          
> +        done = False
>          for arg in userlist:
>              if (arg.endswith('.rpm') and (yum.misc.re_remote_url(arg) or
>                                            os.path.exists(arg))):
> @@ -609,8 +610,13 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
>                                          self.term.MODE['bold'], arg,
>                                          self.term.MODE['normal'])
>                  self._maybeYouMeant(arg)
> +            else:
> +                done = True
>          if len(self.tsInfo) > oldcount:
>              return 2, [_('Package(s) to install')]
> +
> +        if not done:
> +            return 1, [_('Nothing to do')]
>          return 0, [_('Nothing to do')]
>          
>      def updatePkgs(self, userlist, quiet=0):



More information about the Yum-devel mailing list