diff --git a/modulecmd.tcl.in b/modulecmd.tcl.in index 082f09cc..a06488e4 100755 --- a/modulecmd.tcl.in +++ b/modulecmd.tcl.in @@ -1918,6 +1918,10 @@ proc unload-path {args} { # save initial variable content to match index arguments if {[info exists env($var)]} { set dir_list [split $env($var) $separator] + # detect if empty env value means empty path entry + if {[llength $dir_list] == 0 && [info exists countarr()]} { + lappend dir_list {} + } } else { set dir_list [list] } @@ -1978,7 +1982,7 @@ proc unload-path {args} { # update variable if some element need to be removed if {[llength $del_idx_list] > 0} { set del_idx_list [lsort -integer -unique $del_idx_list] - set newpath "" + set newpath [list] set nbelem [llength $dir_list] # rebuild list of element without indexes set for deletion for {set i 0} {$i < $nbelem} {incr i} { @@ -1986,13 +1990,17 @@ proc unload-path {args} { lappend newpath [lindex $dir_list $i] } } - if {$newpath eq ""} { - unset-env $var - set g_stateEnvVars($var) "del" - } else { - set env($var) [join $newpath $separator] - set g_stateEnvVars($var) "new" - } + } else { + set newpath $dir_list + } + + # set env variable and corresponding reference counter in any case + if {[llength $newpath] == 0} { + unset-env $var + set g_stateEnvVars($var) "del" + } else { + set env($var) [join $newpath $separator] + set g_stateEnvVars($var) "new" } set sharevar "${var}_modshare" diff --git a/testsuite/modules.50-cmds/055-prepend-undo.exp b/testsuite/modules.50-cmds/055-prepend-undo.exp index a9dcc8c5..352be39f 100644 --- a/testsuite/modules.50-cmds/055-prepend-undo.exp +++ b/testsuite/modules.50-cmds/055-prepend-undo.exp @@ -215,9 +215,9 @@ set env(LOADEDMODULES) "$module:$module2" set env(LOADEDMODULES_modshare) "$module:1:$module2:1" set ans [list] -lappend ans [list unset FOO] lappend ans [list unset _LMFILES__modshare] lappend ans [list unset LOADEDMODULES_modshare] +lappend ans [list unset FOO] lappend ans [list unset _LMFILES_] lappend ans [list unset LOADEDMODULES] lappend ans [list unset FOO_modshare] @@ -234,6 +234,7 @@ testouterr_cmd "sh" "unload $module2" $ans "" set ans [list] lappend ans [list set FOO_modshare "/path/to/dir:1::1"] +lappend ans [list set FOO "/path/to/dir:"] lappend ans [list setpath LOADEDMODULES $module2] lappend ans [list setpath _LMFILES_ $modulefile2] @@ -248,9 +249,9 @@ set env(LOADEDMODULES) "$module2:$module" set env(LOADEDMODULES_modshare) "$module:1:$module2:1" set ans [list] -lappend ans [list unset FOO] lappend ans [list unset _LMFILES__modshare] lappend ans [list unset LOADEDMODULES_modshare] +lappend ans [list unset FOO] lappend ans [list unset _LMFILES_] lappend ans [list unset LOADEDMODULES] lappend ans [list unset FOO_modshare] @@ -267,6 +268,7 @@ testouterr_cmd "sh" "unload $module2" $ans "" set ans [list] lappend ans [list set FOO_modshare "/path/to/dir:1::1"] +lappend ans [list set FOO "/path/to/dir:"] lappend ans [list setpath LOADEDMODULES $module2] lappend ans [list setpath _LMFILES_ $modulefile2] diff --git a/testsuite/modules.50-cmds/060-remove.exp b/testsuite/modules.50-cmds/060-remove.exp index 620f9d7f..936d738b 100644 --- a/testsuite/modules.50-cmds/060-remove.exp +++ b/testsuite/modules.50-cmds/060-remove.exp @@ -115,6 +115,25 @@ lappend ans [list setpath _LMFILES_ $modulefile] testouterr_cmd "sh" "load $module" $ans "" +# +# Remove unknown path on a var set empty +# + +set module "remove/3.0" +set modulefile "$modpath/$module" + +set env(FOO_modshare) ":1" +set env(FOO) "" + +set ans [list] +lappend ans [list set FOO_modshare ":1"] +lappend ans [list set FOO ""] +lappend ans [list setpath LOADEDMODULES $module] +lappend ans [list setpath _LMFILES_ $modulefile] + +testouterr_cmd "sh" "load $module" $ans "" + + # # Remove path added in duplication mode # @@ -157,6 +176,7 @@ set env(FOO_modshare) "/path/to/dir1:3:/path/to/dir2:1" set ans [list] lappend ans [list set FOO_modshare "/path/to/dir1:2:/path/to/dir2:1"] +lappend ans [list set FOO "/path/to/dir1:/path/to/dir2:/path/to/dir1"] lappend ans [list setpath LOADEDMODULES $module] lappend ans [list setpath _LMFILES_ $modulefile] @@ -195,6 +215,7 @@ set env(FOO) "" set ans [list] lappend ans [list set FOO_modshare ":1"] +lappend ans [list set FOO ""] lappend ans [list setpath LOADEDMODULES $module] lappend ans [list setpath _LMFILES_ $modulefile] @@ -217,6 +238,7 @@ set env(FOO) "/path/to/dir1:/path/to/dir2:/path/to/dir1:/path/to/dir1" set ans [list] lappend ans [list set FOO_modshare "/path/to/dir1:2:/path/to/dir2:1"] +lappend ans [list set FOO "/path/to/dir1:/path/to/dir2:/path/to/dir1:/path/to/dir1"] lappend ans [list setpath LOADEDMODULES $module] lappend ans [list setpath _LMFILES_ $modulefile] diff --git a/testsuite/modules.70-maint/152-remove-path.exp b/testsuite/modules.70-maint/152-remove-path.exp index eefc5caa..6d5873e0 100644 --- a/testsuite/modules.70-maint/152-remove-path.exp +++ b/testsuite/modules.70-maint/152-remove-path.exp @@ -32,7 +32,7 @@ set path1 "/path/to/dir1" set path2 "/path/other/dir2" set path3 "/path/other/dir3" -lappend ans [list unset FOO_modshare] +lappend ans [list unsetpath FOO] testouterr_cmd_re "sh" "remove-path FOO $path1" $ans "" @@ -60,6 +60,7 @@ testouterr_cmd_re "sh" "remove-path --delim : FOO $path2" $ans "" testouterr_cmd_re "sh" "remove-path --delim=: FOO $path2" $ans "" set ans [list] +lappend ans [list set FOO "$path1:$path2"] lappend ans [list set FOO_modshare "$path1:1:$path2:1"] testouterr_cmd_re "sh" "remove-path FOO $path3" $ans ""