@@ -1612,12 +1612,26 @@ if {$install_setmanpath eq {y}} {
16121612 } else {
16131613 set mandirenc $install_mandir
16141614 }
1615- if {$install_appendmanpath eq {y}} {
1616- set updatedmanpath $default_manpath:$install_mandir
1617- set lmsourceshpath "append-path MANPATH $mandirenc|"
1618- } else {
1619- set updatedmanpath $install_mandir:$default_manpath
1620- set lmsourceshpath "prepend-path MANPATH $mandirenc|"
1615+ set updated_manpath_list [split $default_manpath :]
1616+ set is_default_manpath_updated 0
1617+ foreach install_manpath_elt [split $install_mandir :] {
1618+ if {$install_manpath_elt ni $updated_manpath_list} {
1619+ if {$install_appendmanpath eq {y}} {
1620+ lappend updated_manpath_list $install_manpath_elt
1621+ } else {
1622+ set updated_manpath_list [linsert $updated_manpath_list 0 $install_manpath_elt]
1623+ }
1624+ set is_default_manpath_updated 1
1625+ }
1626+ }
1627+ set updatedmanpath [join $updated_manpath_list :]
1628+
1629+ if {$is_default_manpath_updated} {
1630+ if {$install_appendmanpath eq {y}} {
1631+ set lmsourceshpath "append-path MANPATH $mandirenc|"
1632+ } else {
1633+ set lmsourceshpath "prepend-path MANPATH $mandirenc|"
1634+ }
16211635 }
16221636}
16231637# setup PATH without Modules bin location
@@ -1647,13 +1661,13 @@ if {$install_versioning eq {y}} {
16471661lappend ans [list set MODULE_VERSION_STACK $install_version]
16481662}
16491663# MANPATH is set before PATH if the latter is appended and not the former
1650- if {$install_setmanpath eq {y} && $install_appendbinpath eq {y} && $install_appendmanpath eq {n}} {
1664+ if {$install_setmanpath eq {y} && $install_appendbinpath eq {y} && $install_appendmanpath eq {n} && $is_default_manpath_updated } {
16511665lappend ans [list set MANPATH $updatedmanpath]
16521666}
16531667if {$install_setbinpath eq {y}} {
16541668lappend ans [list set PATH $updatedpath]
16551669}
1656- if {$install_setmanpath eq {y} && ($install_appendbinpath eq {n} || $install_appendmanpath eq {y})} {
1670+ if {$install_setmanpath eq {y} && ($install_appendbinpath eq {n} || $install_appendmanpath eq {y}) && $is_default_manpath_updated } {
16571671lappend ans [list set MANPATH $updatedmanpath]
16581672}
16591673lappend ans [list set _LMFILES_ $mp/source-sh/1]
@@ -1703,7 +1717,7 @@ set extratserr {}
17031717set tserr "-------------------------------------------------------------------
17041718$mp/source-sh/1:\n\n"
17051719set tserr_path {}
1706- if {$install_setmanpath eq {y}} {
1720+ if {$install_setmanpath eq {y} && $is_default_manpath_updated } {
17071721 if {$install_appendmanpath eq {y}} {
17081722 append tserr_path "append-path\tMANPATH $mandirenc\n"
17091723 } else {
@@ -1754,13 +1768,13 @@ if {$install_versioning eq {y}} {
17541768lappend ans [list set MODULE_VERSION_STACK $install_version]
17551769}
17561770# MANPATH is set before PATH if the latter is appended and not the former
1757- if {$install_setmanpath eq {y} && $install_appendbinpath eq {y} && $install_appendmanpath eq {n}} {
1771+ if {$install_setmanpath eq {y} && $install_appendbinpath eq {y} && $install_appendmanpath eq {n} && $is_default_manpath_updated } {
17581772lappend ans [list set MANPATH $updatedmanpath]
17591773}
17601774if {$install_setbinpath eq {y}} {
17611775lappend ans [list set PATH $updatedpath]
17621776}
1763- if {$install_setmanpath eq {y} && ($install_appendbinpath eq {n} || $install_appendmanpath eq {y})} {
1777+ if {$install_setmanpath eq {y} && ($install_appendbinpath eq {n} || $install_appendmanpath eq {y}) && $is_default_manpath_updated } {
17641778lappend ans [list set MANPATH $updatedmanpath]
17651779}
17661780lappend ans [list set _LMFILES_ $mp/source-sh/1]
@@ -1792,13 +1806,13 @@ if {$install_versioning eq {y}} {
17921806lappend ans [list set MODULE_VERSION_STACK $install_version]
17931807}
17941808# MANPATH is set before PATH if the latter is appended and not the former
1795- if {$install_setmanpath eq {y} && $install_appendbinpath eq {y} && $install_appendmanpath eq {n}} {
1809+ if {$install_setmanpath eq {y} && $install_appendbinpath eq {y} && $install_appendmanpath eq {n} && $is_default_manpath_updated } {
17961810lappend ans [list set MANPATH $updatedmanpath]
17971811}
17981812if {$install_setbinpath eq {y}} {
17991813lappend ans [list set PATH $updatedpath]
18001814}
1801- if {$install_setmanpath eq {y} && ($install_appendbinpath eq {n} || $install_appendmanpath eq {y})} {
1815+ if {$install_setmanpath eq {y} && ($install_appendbinpath eq {n} || $install_appendmanpath eq {y}) && $is_default_manpath_updated } {
18021816lappend ans [list set MANPATH $updatedmanpath]
18031817}
18041818lappend ans [list set _LMFILES_ $modpath/setenv/1.0:$mp/source-sh/1]
@@ -1829,19 +1843,19 @@ setenv_var MODULES_COLLECTION_TARGET bar
18291843if {$install_setbinpath eq {y}} {
18301844setenv_var PATH $updatedpath
18311845}
1832- if {$install_setmanpath eq {y}} {
1846+ if {$install_setmanpath eq {y} && $is_default_manpath_updated } {
18331847setenv_var MANPATH $updatedmanpath
18341848}
18351849setenv_var __MODULES_LMSOURCESH source-sh/1\&bash\ testsuite/example/sh-to-mod.sh\|${lmsourceshpath}setenv\ MODULES_COLLECTION_TARGET\ bar\|setenv\ testsuite\ yes
18361850set ans [list]
18371851# MANPATH is set before PATH if the latter is appended and not the former
1838- if {$install_setmanpath eq {y} && $install_appendbinpath eq {y} && $install_appendmanpath eq {n}} {
1852+ if {$install_setmanpath eq {y} && $install_appendbinpath eq {y} && $install_appendmanpath eq {n} && $is_default_manpath_updated } {
18391853lappend ans [list set MANPATH $default_manpath]
18401854}
18411855if {$install_setbinpath eq {y}} {
18421856lappend ans [list set PATH $default_path]
18431857}
1844- if {$install_setmanpath eq {y} && ($install_appendbinpath eq {n} || $install_appendmanpath eq {y})} {
1858+ if {$install_setmanpath eq {y} && ($install_appendbinpath eq {n} || $install_appendmanpath eq {y}) && $is_default_manpath_updated } {
18451859lappend ans [list set MANPATH $default_manpath]
18461860}
18471861lappend ans [list unset _LMFILES_]
0 commit comments