Skip to content

pkg_autoremove: Fix order#2608

Merged
evadot merged 1 commit intomainfrom
autoremove
Feb 19, 2026
Merged

pkg_autoremove: Fix order#2608
evadot merged 1 commit intomainfrom
autoremove

Conversation

@evadot
Copy link
Contributor

@evadot evadot commented Feb 17, 2026

If package A depends on package B (on a binary or script for example), when autoremove is called currently the order is (likely) by alphabetic. This cause problems as if package A is removed first and package B needs a script from package A it will fails to clean up correctly the system. Since autoremove is considered as force internally simply extend the check so we will process the removals in the correct order.

Sponsored by: Beckhoff Automation GmbH & Co. KG

@vstakhov
Copy link
Member

Let me add some insights on that as I feel responsible for the sorting architecture here:

Current Architecture

  1. Job Collection (pkg_jobs.c:jobs_solve_autoremove, line 1426-1450):
  • Finds orphaned packages using pkg_jobs_test_automatic()
  • Adds them to the delete request via pkg_jobs_add_req()
  1. Topological Sorting (pkg_jobs_schedule.c:pkg_jobs_schedule_topological_sort, line 351-387):
  • Uses Kahn's algorithm for topological sort
  • Builds a directed graph where edges represent scheduling constraints
  • For delete jobs, the edge rule is at line 177-183:
if (a_old != NULL && b_old != NULL &&
    pkg_jobs_schedule_direct_depends(a_old, b_old)) {
    return (PKG_SCHEDULE_EDGE_OLD_DEP_OLD);
}
  • This means: if package A depends on package B, there's an edge A -> B, so A gets deleted before B

The problem is in pkg_jobs_process_delete_request() (line 519-581):

  bool force = j->flags & PKG_FLAG_FORCE;  // autoremove sets PKG_FLAG_FORCE
  ...
  if (force)
      return (EPKG_OK);  // Skips reverse dependency processing!

So autoremove is treated as "force" internally, which causes it to skip adding reverse dependencies to the delete request. Without the full dependency graph in the job list, the topological sort cannot correctly order the deletions.

Another approach is to rethink force flag usage here - I'm not sure why autoremove requires force flag at all :)

@vstakhov
Copy link
Member

Yeah, we can actually set something like PKG_FLAG_AUTOREMOVE to make the overall architecture slightly more sound but the proposed change efficiently does the same...

If package A depends on package B (on a binary or script for example), when
autoremove is called currently the order is (likely) by alphabetic.
This cause problems as if package A is removed first and package B needs a script
from package A it will fails to clean up correctly the system.
Since autoremove is considered as force internally simply remove the check so we will
process the removals in the correct order.

Sponsored by:	Beckhoff Automation GmbH & Co. KG
@evadot evadot merged commit b67e56f into main Feb 19, 2026
14 checks passed
@bdrewery
Copy link
Member

bdrewery commented Mar 2, 2026

With this change added to the release-2.5 branch pkg autoremove wants to remove packages that are listed in pkg noauto. Something isn't right here. There should be tests covering this change too. @bapt

@bdrewery
Copy link
Member

bdrewery commented Mar 2, 2026

And packages marked vital.

@bapt
Copy link
Member

bapt commented Mar 3, 2026

this changed broken many things, I will revert and redo it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants