pkg upgrade sometimes reinstalls packages

Sometimes when I run `pkg upgrade` I'll see X number of packages that will be upgraded, but Y number of packages that will be reinstalled.
Why is that? Why does pkg sometimes reinstall (actually removes package and then installs new package) instead of upgrade?

It's causing me problems because I have an ansible playbook that runs `pkg upgrade` and then reads json from EVENT_PIPE to monitor which
service needs restart. It only monitors INFO_UPGRADE_FINISHED now, so if the package is reinstalled, my playbook doesn't pick it up. I guess
I'll have to monitor INFO_INSTALL_FINISHED as well and treat that the same way, but I'm curious why pkg sometimes reinstalls.
 
Usually it is because some dependency of the package got upgrade. A shared library for example.
If you do # pkg upgrade -n it will tell you which packages will be reinstalled.
 
That makes sense, but in this case it's not just reinstalling the same version, it's uninstalling one version and installing a newer one.

Code:
{ "type": "INFO_FETCH_BEGIN", "data": { "url": "https://pkgbuild.isnic.is/packages/14amd64/All/openssh-portable-10.0.p1,1.pkg" }}
{ "type": "INFO_FETCH_FINISHED", "data": { "url": "https://pkgbuild.isnic.is/packages/14amd64/All/openssh-portable-10.0.p1,1.pkg" }}
{ "type": "INFO_DEINSTALL_BEGIN", "data": { "pkgname": "openssh-portable", "pkgversion": "9.9.p1_1,1"}}
{ "type": "INFO_INSTALL_BEGIN", "data": { "pkgname": "openssh-portable", "pkgversion": "10.0.p1,1"}}
{ "type": "INFO_EXTRACT_BEGIN", "data": { "pkgname": "openssh-portable", "pkgversion": "10.0.p1,1"}}
{ "type": "INFO_EXTRACT_FINISHED", "data": { "pkgname": "openssh-portable", "pkgversion": "10.0.p1,1"}}
{ "type": "INFO_INSTALL_FINISHED", "data": { "pkgname": "openssh-portable", "pkgversion": "10.0.p1,1", "message": "[{"message":"To enable this port, add openssh_enable=\"YES\" in your rc.conf. To\nprevent conflict with openssh in the base system add sshd_enable=\"NO\"\nin your rc.conf. Also you can configure openssh at another TCP port (via\nsshd_config 'Port' and 'Listen' options or via 'openssh_flags'\nvariable in rc.conf) and run it in same time with base sshd.\n\n'PermitRootLogin no' is the default for the OpenSSH port.\nThis now matches the PermitRootLogin configuration of OpenSSH in\nthe base system.  Please be aware of this when upgrading your\nOpenSSH port, and if truly necessary, re-enable remote root login\nby readjusting this option in your sshd_config.\n\nUsers are encouraged to create single-purpose users with ssh keys, disable\nPassword authentication by setting 'PasswordAuthentication no' and\n'ChallengeResponseAuthentication no', and to define very narrow sudo\nprivileges instead of using root for automated tasks.","type":"install"}]"}}

Is it because of a shared library upgrade *AND* a new version, so it gets marked as reinstall, if there wasn't an upgraded shared library it would just be an upgrade?
 
Actually, this only manifests in the JSON output in EVENT_PIPE. The stdout was:

Code:
Installed packages to be UPGRADED:
    glib: 2.80.5_1,2 -> 2.82.4_1,2
    gnutls: 3.8.8 -> 3.8.9
    icu: 74.2_1,1 -> 76.1,1
    indexinfo: 0.3.1 -> 0.3.1_1
    libcbor: 0.11.0 -> 0.12.0
    libedit: 3.1.20240808,1 -> 3.1.20250104,1
    libffi: 3.4.6 -> 3.4.7
    libidn2: 2.3.7 -> 2.3.8
    libtasn1: 4.19.0_1 -> 4.20.0_1
    openssh-portable: 9.9.p1_1,1 -> 10.0.p1,1
    pcre2: 10.43 -> 10.45
    postfix: 3.9.1,1 -> 3.10.1,1
    vim: 9.1.1043 -> 9.1.1265
    xxd: 9.1.1043 -> 9.1.1265

Installed packages to be REINSTALLED:
    sudo-1.9.16p2_1 (option removed: SSSD2)

Number of packages to be upgraded: 14
Number of packages to be reinstalled: 1
 
Back
Top