mirror of
https://github.com/envmodules/modules.git
synced 2026-06-18 00:06:53 +08:00
Always set/unset var when removing path in it
Even if no change on variable value, always set (or unset) this variable as its relative counter reference variable is always set (or unset).
This commit is contained 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"
|
||||
|
||||
@@ -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]
|
||||
|
||||
|
||||
@@ -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]
|
||||
|
||||
|
||||
@@ -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 ""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user