pkg_add doesn't exit with a failure code if non-existant package installation is attempted

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

pkg_add doesn't exit with a failure code if non-existant package installation is attempted

Mart Tõnso
Hello Bugs,

Stumbled upon this:

# pkg_add nonexistantpackage || echo false && echo true
Can't find nonexistantpackage
true

This makes it impossible to detect in an external script/program that
package installation failed when an invalid package name was passed to
pkg_add. I think it would make sense to return an error code in this
case?

Regards,

Mart

Reply | Threaded
Open this post in threaded view
|

Re: pkg_add doesn't exit with a failure code if non-existant package installation is attempted

Anthony J. Bentley-4
Mart Tõnso writes:

> Hello Bugs,
>
> Stumbled upon this:
>
> # pkg_add nonexistantpackage || echo false && echo true
> Can't find nonexistantpackage
> true
>
> This makes it impossible to detect in an external script/program that
> package installation failed when an invalid package name was passed to
> pkg_add. I think it would make sense to return an error code in this
> case?

Try pkg_add followed by "pkg_info inst:pkgname"?

Reply | Threaded
Open this post in threaded view
|

Re: pkg_add doesn't exit with a failure code if non-existant package installation is attempted

Mart Tõnso
Yes, it would work as a one-off workaround, but still leaves the
underlying inconsistency. pkg_remove reports errors very nicely if you
pass invalid package names as a parameter and this behaviour "makes
sense".

Regards,

Mart

On Sun, Aug 14, 2016 at 10:32 PM, Anthony J. Bentley <[hidden email]> wrote:

> Mart Tõnso writes:
>> Hello Bugs,
>>
>> Stumbled upon this:
>>
>> # pkg_add nonexistantpackage || echo false && echo true
>> Can't find nonexistantpackage
>> true
>>
>> This makes it impossible to detect in an external script/program that
>> package installation failed when an invalid package name was passed to
>> pkg_add. I think it would make sense to return an error code in this
>> case?
>
> Try pkg_add followed by "pkg_info inst:pkgname"?

Reply | Threaded
Open this post in threaded view
|

Re: pkg_add doesn't exit with a failure code if non-existant package installation is attempted

Patrik Lundin-3
In reply to this post by Mart Tõnso
On Sun, Aug 14, 2016 at 09:27:49PM +0300, Mart Tõnso wrote:

> Hello Bugs,
>
> Stumbled upon this:
>
> # pkg_add nonexistantpackage || echo false && echo true
> Can't find nonexistantpackage
> true
>
> This makes it impossible to detect in an external script/program that
> package installation failed when an invalid package name was passed to
> pkg_add. I think it would make sense to return an error code in this
> case?
>

Just an FYI: The behaviour changes when a version number is included in the
name.
===
# pkg_add nonexistantpackage-1.0
[...]
Can't install nonexistantpackage-1.0: not found
# echo $?
1
===

In the Ansible package management module I check for the presence of stderr
output when working with a packge name that does not include a version
string.

You can see comments describing the problem in
https://github.com/ansible/ansible-modules-extras/blob/devel/packaging/os/openbsd_pkg.py,
currently at line 153.

I am not saying this is correct, just pointing out possible workarounds.

--
Patrik Lundin