Re: `pkg autoremove` uninstalls pkg itself

From: Yasuhiro Kimura <yasu_at_FreeBSD.org>
Date: Fri, 19 Apr 2024 12:43:07 UTC
From: Torfinn Ingolfsen <tingox@gmail.com>
Subject: Re: `pkg autoremove` uninstalls pkg itself
Date: Thu, 4 Apr 2024 18:02:22 +0200

> Yes, this is the expected behavior.
> Bonus points for figuring out how to install pkg on a system that
> doesn't have it. :-)

From: Gleb Popov <arrowd@freebsd.org>
Subject: Re: `pkg autoremove` uninstalls pkg itself
Date: Thu, 4 Apr 2024 19:08:38 +0300

> Eh? Why did you do that?
> 
> This probably removed pkg that you bootstrapped earlier and then
> reinstalled it from ports which changed the automatic flag value (my
> guess).

From: Dag-Erling Smørgrav <des@FreeBSD.org>
Subject: Re: `pkg autoremove` uninstalls pkg itself
Date: Thu, 04 Apr 2024 18:17:04 +0200

>> Then is it expected behavior?
> 
> Yes, it did exactly what you asked it to do.

At first, I apologize for this very late reply. Just after I wrote
original message I had to be away from keyboard for a while
unexpectedly.

Next, thanks everyone for replying me. I read all of them and
understand my question in original message is improper and
insufficient. So I'd like to explain my question more in detail
including backgroud of it.

On the last weekend of March I was reported the build error of
security/clamav-lts by private mail (I'm maintainer of the port).
In the message the reporter said as following.

1. He made clean install of 14.0-RELEASE amd64 system.
2. He started installing packages he wants to use.
3. When he tried to install security/clamav-lts, it failed because of
   build error.

I checked build of security/clamav-lts on 14.0-RELEASE amd64 with both
using poudriere and `cd /usr/ports/security/clamav-lts; make`. But
build finished successfully with both cases. So I asked him some
questions to get more information. Accoding to them the build failure
happens as fllowing.

1. After installation of the sytem was completed, he checked out ports
   tree with following steps.

   a. Install git-tiny package with `pkg install git-tiny`
   b. Check out ports tree with `cd /usr/ports;
      git clone https://git.freebsd.org/ports.git .`.
   c. Uninstall all installed packages with `pkg delete -af`.

   (He said he did step c to install packages from scratch.)
2. He installed dozen of packages with `cd /usr/ports/category/name;
   make install`. (He told me the list of installed packages and the
   order of installation.)
3. Then he tried to install clamav-lts package with
   `cd /usr/ports/security/clamav-lts; make install`.
4. Build of clamav-lts failed with error.

And I succeeded to reproduce the error with additional information.

While working as maintainer of ports I have experienced such build
error of ports under non-cleanroom environment. And the cause of such
error is often one or more packages already installed but not listed
as dependency of the ports in question. So my step of investigation is
to remove some of installed packages to reduce the number of
candidates and check if build error still happens. And I often use
`pkg autoremove` as a first step.

So I executed `pkg autoremove` this time too. When I tried
`cd /usr/ports/security/clamav-lts; make` after that, however, weird
error never seed before happend. And I noticee 'pkg' is uninstalled.

As I wrote above I have tried `pkg autoremove` several times under
similar situation. But I have never experienced that `pkg` itself is
removed by the command before.

My question is, then, why what didn't happen before has happend?

A. Something (ports-mgmt/pkg or ports framework) has changed
   resently so `pkg` is marked as automatically installed when it is
   installed with such situation as above.
B. There ins't such change and `pkg` has been marked automaticall
   installed when it is installed with such situation. But
   `pkg autoremove`  didn't remove itself simply because there is
   manually installed package that depends on `pkg` (either directly
   or indirectly).

IIRC, last time when I executed `pkg autoremove` is at least a year
before. So if there is someone who experienced same result under
similar situation before a year or more, then the answer is B. And it
means everything have worked as is expected. But if there isn't, then
the answer is probably A and it may be worth investgating the reason
of the change.

---
Yasuhiro Kimura