diff --git a/Pmodules/libpmodules.bash.in b/Pmodules/libpmodules.bash.in index f118b8d..ea15fbc 100644 --- a/Pmodules/libpmodules.bash.in +++ b/Pmodules/libpmodules.bash.in @@ -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 diff --git a/Pmodules/modulecmd.bash.in b/Pmodules/modulecmd.bash.in index ea7f5c0..42e9471 100644 --- a/Pmodules/modulecmd.bash.in +++ b/Pmodules/modulecmd.bash.in @@ -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' }