Skip to content

Commit 5964ceb

Browse files
committed
revised code if path_entry_reoder is set
1 parent ddc1d4a commit 5964ceb

File tree

1 file changed

+33
-34
lines changed

1 file changed

+33
-34
lines changed

tcl/envmngt.tcl.in

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,47 +1816,46 @@ proc add-path {cmd mode dflbhv args} {
18161816
set val [get-env $var]
18171817

18181818
foreach dir $path_list {
1819-
# With the following variable, we indicate that $dir has been removed
1820-
# from the path if path_entry_reorder is true and duplicates are not
1821-
# allowed.
1822-
set dir_removed 0
1823-
if {[getConf path_entry_reorder]} {
1824-
if {[info exists countarr($dir)] && ! $allow_dup} {
1825-
# if $dir is in $val and duplicates are not allowed:
1826-
# first remove all occurences of $dir in $val
1827-
# and add $dir at the beginning or end later again
1828-
set mpath_list [split $val $separator]
1829-
set mpath_list [lsearch -inline -all -not -exact $mpath_list $dir]
1830-
set val [join $mpath_list $separator]
1831-
1832-
# Set counter to 0. Unfortunatelly we cannot use countarr($dir)
1833-
# in the following if statement.
1834-
set countarr($dir) 0
1835-
# make sure $dir is added again
1836-
set dir_removed 1
1837-
}
1838-
}
1839-
if {![info exists countarr($dir)] || $dir_removed || $allow_dup} {
1840-
# ignore env var set empty if no empty entry found in reference
1841-
# counter array (sometimes var is cleared by setting it empty not
1842-
# unsetting it)
1843-
if {$val ne {} || [info exists countarr()]} {
1819+
if {[getConf path_entry_reorder] && [info exists countarr($dir)]\
1820+
&& ! $allow_dup} {
1821+
# if $dir is in $val and duplicates are not allowed:
1822+
# first remove all occurences of $dir in $val
1823+
# and add $dir at the beginning or end if $val
1824+
# is not the empty string
1825+
set mpath_list [split $val $separator]
1826+
set mpath_list [lsearch -inline -all -not -exact $mpath_list $dir]
1827+
set val [join $mpath_list $separator]
1828+
if {$val ne {}} {
18441829
set sep [expr {$val eq $separator ? {} : $separator}]
18451830
set val [expr {$bhv eq {prepend} ? "$dir$sep$val" :\
18461831
"$val$sep$dir"}]
1832+
} else {
1833+
set val $dir
1834+
}
1835+
set countarr($dir) 1
1836+
} else {
1837+
if {![info exists countarr($dir)] || $allow_dup} {
1838+
# ignore env var set empty if no empty entry found in reference
1839+
# counter array (sometimes var is cleared by setting it empty not
1840+
# unsetting it)
1841+
if {$val ne {} || [info exists countarr()]} {
1842+
set sep [expr {$val eq $separator ? {} : $separator}]
1843+
set val [expr {$bhv eq {prepend} ? "$dir$sep$val" :\
1844+
"$val$sep$dir"}]
18471845
} else {
18481846
set val $dir
18491847
}
1850-
}
1851-
if {[info exists countarr($dir)]} {
1852-
# do not increase counter if bare separator string is added or if
1853-
# reference count is ignored (--ignore-refcount set) unless if
1854-
# duplicate mode is enabled (--duplicates set)
1855-
if {!$val_set_is_delim && (!$ign_refcount || $allow_dup)} {
1856-
incr countarr($dir)
18571848
}
1858-
} else {
1859-
set countarr($dir) 1
1849+
if {[info exists countarr($dir)]} {
1850+
# do not increase counter if bare separator string is added or if
1851+
# reference count is ignored (--ignore-refcount set) unless if
1852+
# duplicate mode is enabled (--duplicates set)
1853+
if {!$val_set_is_delim && (!$ign_refcount || $allow_dup)} {
1854+
incr countarr($dir)
1855+
}
1856+
} else {
1857+
set countarr($dir) 1
1858+
}
18601859
}
18611860
}
18621861

0 commit comments

Comments
 (0)