modulecmd/libpmodules.bash: interface of compute_group_depth() changed

retrun result in a reference variable
This commit is contained in:
2022-06-30 10:44:56 +02:00
parent 44e5edeebb
commit d408a73d89
2 changed files with 13 additions and 8 deletions
+10 -7
View File
@@ -38,18 +38,17 @@ print_help() {
# $1: absolute path of a modulefile directory
#
compute_group_depth () {
local -r dir=$1
local -n result="$1"
local -r dir="$2"
test -d "${dir}" || return 1
local group=${dir%/*}
local group=${group##*/}
[[ -n "${GroupDepths[${group}]}" ]] && return 0
local -i depth=$(${find} "${dir}" -depth \( -type f -o -type l \) \
local -i result=$(${find} "${dir}" -depth \( -type f -o -type l \) \
-printf "%d" -quit 2>/dev/null)
(( depth-=2 ))
(( result-=2 ))
# if a group doesn't contain a modulefile, depth is negativ
# :FIXME: better solution?
(( depth < 0 )) && (( depth = 0 ))
GroupDepths[$group]=${depth}
(( result < 0 )) && (( result = 0 ))
}
#
@@ -62,9 +61,13 @@ scan_groups () {
local ol
for ol in "$@"; do
local mod_root="${OverlayInfo[${ol}:mod_root]}"
local -i depth
local dir
for dir in ${mod_root}/*/${PMODULES_MODULEFILES_DIR}; do
compute_group_depth "${dir}"
if [[ -n "${GroupDepths[${group}]}" ]]; then
compute_group_depth depth "${dir}"
GroupDepths[$group]=${depth}
fi
Dir2OverlayMap[${dir%/${PMODULES_MODULEFILES_DIR}*}]="${ol}"
done
done
+3 -1
View File
@@ -484,7 +484,9 @@ subcommand_load() {
local ol=''
find_overlay_with_group ol "${group}" || return 1
local moduledir="${OverlayInfo[${ol}:mod_root]}/${group}/${PMODULES_MODULEFILES_DIR}"
compute_group_depth "${moduledir}" || return 1
local -i depth
compute_group_depth depth "${moduledir}" || return 1
GroupDepths[${group}]=${depth}
g_env_must_be_saved='yes'
}