From 3c8f133adfc7ed82251a9aaa2de6fe8e24eb66ff Mon Sep 17 00:00:00 2001 From: Joshua Root Date: Fri, 16 Feb 2024 11:11:55 +1100 Subject: [PATCH] cleanup: correct check for inactive deps The dependencies registry key will return all installed versions of ports that a port depends on, and of course at most one can be active. Only deactivate if there is no active version of the dep. --- tools/uninstall-unneeded-ports.tcl | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tools/uninstall-unneeded-ports.tcl b/tools/uninstall-unneeded-ports.tcl index 4ff2c64..a7594f9 100755 --- a/tools/uninstall-unneeded-ports.tcl +++ b/tools/uninstall-unneeded-ports.tcl @@ -160,9 +160,16 @@ foreach port [registry::entry imaged] { # Deactivate anything with inactive dependencies # (can happen with non-port: deps) # https://trac.macports.org/ticket/68662 + +# Track if each port has any version active +# (ports may have multiple installed variants, e.g. universal) +set has_active [dict create] foreach port [registry::entry installed] { foreach dep [$port dependencies] { - if {[$dep state] ne "installed"} { + if {![dict exists $has_active [$dep name]]} { + dict set has_active [$dep name] [expr {[registry::entry installed [$dep name]] ne ""}] + } + if {![dict get $has_active [$dep name]]} { ui_msg "Deactivating [$port name] because its dependency [$dep name] is not active" deactivate_with_dependents $port break