From 6b1afd49840a2daaaa5affe7ca50066cfe0908df Mon Sep 17 00:00:00 2001 From: Xavier Delaruelle Date: Tue, 2 Jul 2024 20:05:43 +0200 Subject: [PATCH] Unload all matching mods on "module unload" modfile cmd When conflict_unload and auto_handling options are enabled, a "module unload" modulefile command unloads all loaded modulefiles that match module designation passed as argument. Same behavior than for conflict modulefile command is then obtained. Fixes #215 --- tcl/subcmd.tcl.in | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tcl/subcmd.tcl.in b/tcl/subcmd.tcl.in index 6ad59059..b54fb40b 100644 --- a/tcl/subcmd.tcl.in +++ b/tcl/subcmd.tcl.in @@ -1427,7 +1427,17 @@ proc cmdModuleIntUnload {mode args} { # enable auto unload and allow force mode if both auto handling and # conflict unload features are enabled if {[getConf conflict_unload] && [getConf auto_handling]} { - set ret [cmdModuleUnload conun match 1 s 0 {*}$args] + set conun_mod_list {} + foreach conun_arg $args { + # unload attempt in reverse load order + appendNoDupToList conun_mod_list {*}[lreverse\ + [getLoadedMatchingName $conun_arg returnall]] + } + if {[llength $conun_mod_list]} { + set ret [cmdModuleUnload conun match 1 s 0 {*}$conun_mod_list] + } else { + set ret 0 + } # otherwise module required by others are not unloaded and force mode is # disabled } else {