Skip to content

Commit

Permalink
allow force activation of already active ports
Browse files Browse the repository at this point in the history
Allows to use `port -f activate foo` to activate (reactivate) ports
that are already active.
Useful as a shortcut to `port deactivate foo && port activate foo`
when that operation is required, but also when activating multiple
ports e.g. when one or more already turn out to have the desired
variant/version activated.
  • Loading branch information
RJVB committed Aug 17, 2024
1 parent b2e06d5 commit 858c760
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
22 changes: 14 additions & 8 deletions src/port/port.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -2213,14 +2213,20 @@ proc action_activate { action portlist opts } {
}
foreachport $portlist {
set composite_version [composite_version $portversion $variations]
if {[catch {registry_installed $portname $composite_version} result]} {
break_softcontinue "port activate failed: $result" 1 status
}
set regref $result
if {![dict exists $options ports_activate_no-exec] &&
[registry::run_target $regref activate $options]
} then {
continue
# if the user passed -f we go for activate_composite at once so that
# the selection list won't be shown twice if there are multiple versions
# or variants installed and the goal was to re-activate the already
# active port.
if {![dict exists $options ports_force]} {
if {[catch {registry_installed $portname $composite_version} result]} {
break_softcontinue "port activate failed: $result" 1 status
}
set regref $result
if {![dict exists $options ports_activate_no-exec] &&
[registry::run_target $regref activate $options]
} then {
continue
}
}
if {![macports::global_option_isset ports_dryrun]} {
if {[catch {portimage::activate_composite $portname $composite_version $options} result]} {
Expand Down
14 changes: 10 additions & 4 deletions src/registry2.0/portimage.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ proc activate {name {version ""} {revision ""} {variants 0} {options ""}} {
set rename_list [dict get $options portactivate_rename_files]
}
set todeactivate [list]
set actaction "Activating"

registry::read {

Expand All @@ -104,9 +105,14 @@ proc activate {name {version ""} {revision ""} {variants 0} {options ""}} {
set location [$requested location]

if {[$requested state] eq "installed"} {
ui_info "${name} @${specifier} is already active."
#registry::entry close $requested
return
if {$force} {
set actaction "Reactivating"
lappend todeactivate $requested
} else {
ui_info "${name} @${specifier} is already active."
#registry::entry close $requested
return
}
}

# this shouldn't be possible
Expand Down Expand Up @@ -137,7 +143,7 @@ proc activate {name {version ""} {revision ""} {variants 0} {options ""}} {
}
}

ui_msg "$UI_PREFIX [format [msgcat::mc "Activating %s @%s"] $name $specifier]"
ui_msg "$UI_PREFIX [format [msgcat::mc "$actaction %s @%s"] $name $specifier]"

_activate_contents $requested $rename_list
} finally {
Expand Down

0 comments on commit 858c760

Please sign in to comment.