pkg-install on locked package sometimes has return code 1
pkg install exits with return code 1 if the package is locked. Sometimes, depending on the package, which makes it more confusing.
This does not seem to depend on whether the package is already at the latest version from the fetched repositories or not.
Here are some runs. For all the packages below, I've tried it while the package was at a previous version (so still room for upgrade) and while the package was fully upgraded. In both cases, the return code was the same, as follows:
$ pkg lock -y bash; pkg install -y bash; echo $?
Locking bash-5.1.12
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
Checking integrity... done (0 conflicting)
The most recent versions of packages are already installed
0
$ pkg lock -y zsh; pkg install -y zsh; echo $?
Locking zsh-5.9
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
1
$ pkg lock -y openssl; pkg install -y openssl; echo $?
Locking openssl-1.1.1q,1
openssl-1.1.1q,1: already locked
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
All repositories are up to date.
1
If the package is unlocked, pkg install always returns 0.
It seems that if the command is succesful, it outputs:
Checking integrity... done (0 conflicting)
The most recent versions of packages are already installed
Does that mean that the others come into conflict?
The reason I think this is incovenient is because there is no way for an automatic script to make sure that certain packages are installed on the system while still monitoring for exit codes. In other words, either all errors are ignored, or you gamble for errors depending on package.
A suggested solution would be to not treat a locked package as an error and always return 0.