regression: ?garbage does not work correctly in install commands

Bug #1995790 reported by Mekaniserad Apelsin
10
This bug affects 2 people
Affects Status Importance Assigned to Milestone
apt (Ubuntu)
Status tracked in Mantic
Jammy
Confirmed
Undecided
Unassigned
Lunar
Confirmed
Undecided
Unassigned
Mantic
Triaged
High
Julian Andres Klode

Bug Description

The awesome apt has a some wonderful tips on their EXAMPLES section (printed below). The choice of name to "garbage" might not have been the best but the function is extremely useful.

$ man apt-patterns | sed '/EXAMPLES/,/^[^ ]/!d;/^[^ ]/d'
       apt remove ?garbage
           Remove all packages that are automatically installed and no longer needed -
           same as apt autoremove

       apt purge ?config-files
           Purge all packages that only have configuration files left

       apt list '~i !~M (~slibs|~sperl|~spython)'
           List all manually-installed packages in sections matching libs, perl, or
           python.

Lets mark a package as automatically installed, and use the examples.

$ sudo apt-mark auto shotwell
shotwell set to automatically installed.

$ sudo apt remove ?garbage
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libraw20 shotwell shotwell-common
Use 'sudo apt autoremove' to remove them.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

$ sudo apt autoremove
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
  libraw20 shotwell shotwell-common
0 upgraded, 0 newly installed, 3 to remove and 0 not upgraded.
After this operation, 9.806 kB disk space will be freed.
Do you want to continue? [Y/n] N
Abort.

Apt-patterns works as it should everywhere else, as far as I can see, it works wonders with ie `apt list '~g|~c'` and many other applications. I used `apt purge '~g|~c'` successfully in Ubuntu 20.04 for years, so I feel this is a regression.

ProblemType: Bug
DistroRelease: Ubuntu 22.04
Package: apt 2.4.8
ProcVersionSignature: Ubuntu 5.15.0-52.58-generic 5.15.60
Uname: Linux 5.15.0-52-generic x86_64
NonfreeKernelModules: zfs zunicode zavl icp zcommon znvpair
ApportVersion: 2.20.11-0ubuntu82.1
Architecture: amd64
CasperMD5CheckResult: unknown
CurrentDesktop: ubuntu:GNOME
Date: Sun Nov 6 10:57:52 2022
SourcePackage: apt
UpgradeStatus: Upgraded to jammy on 2022-03-26 (224 days ago)

Revision history for this message
Mekaniserad Apelsin (blippe) wrote :
Revision history for this message
Mekaniserad Apelsin (blippe) wrote :

Just tested on bullseye and both commands below works as expected|indented, packages marked as automatically installed (and no longer needed) and packages with configuration files left are removed, as per apt subcommand.

$ sudo apt purge '~g|~c'
$ sudo apt remove '~g|~c'

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in apt (Ubuntu):
status: New → Confirmed
Revision history for this message
Julian Andres Klode (juliank) wrote (last edit ): Re: ?garbage does not work correctly in install commands

I can confirm that ?garbage does not work correctly in install commands (install, remove, purge, etc). Presumably the pattern is evaluated while an action group is preventing the cache from updating the garbage state and hence it evaluates to nothing.

I can confirm that this works in focal but not in jammy, with those test cases:

podman run --rm -it ubuntu:focal bash -c "apt update && apt install hello && apt-mark auto hello && apt remove ?garbage -y"
podman run --rm -it ubuntu:jammy bash -c "apt update && apt install hello && apt-mark auto hello && apt remove ?garbage -y"

Not sure when it regressed

summary: - apt-patterns does not work as described in man pages
+ ?garbage does not work correctly in install commands
Changed in apt (Ubuntu):
importance: Undecided → High
assignee: nobody → Julian Andres Klode (juliank)
tags: added: foundations-todo
summary: - ?garbage does not work correctly in install commands
+ regression: ?garbage does not work correctly in install commands
Changed in apt (Ubuntu Jammy):
status: New → Confirmed
Changed in apt (Ubuntu Lunar):
status: New → Confirmed
Changed in apt (Ubuntu Mantic):
status: Confirmed → Triaged
Revision history for this message
Julian Andres Klode (juliank) wrote :

I think this is a regression of "Call MarkAndSweep only manually in apt-get for autoremove"

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.