mirror of
https://github.com/Pmodules/Pmodules.git
synced 2026-06-27 18:13:08 +02:00
modulecmd: don't remove a loaded Pmodules module with module purge
Removing a Pmodule module with module purge has some unwanted side-effects. It is not required to have modulecmd in a directory of PATH. If you user explicitly loads a Pmodules module the bin directory of the Pmodule module is added to the PATH. A Pmodules module might be loaded for two reasons. First to change the Pmodules version, second to make the build system available. If we remove a Pmodules module with module purge the build systems is getting unavailable again. This is confusing for the user.
This commit is contained in:
@@ -1320,7 +1320,7 @@ reset_modulepath() {
|
||||
MODULEPATH=''
|
||||
local group
|
||||
local root="${PMODULES_ROOT}"
|
||||
for group in ${PMODULES_DEFAULT_GROUPS}; do
|
||||
for group in ${UsedGroups//:/ }; do
|
||||
local dir="${root}/${group}/${PMODULES_MODULEFILES_DIR}"
|
||||
[[ -d "${dir}" ]] && std::prepend_path MODULEPATH "${dir}"
|
||||
done
|
||||
@@ -1395,6 +1395,13 @@ USAGE:
|
||||
'
|
||||
|
||||
subcommand_purge() {
|
||||
#
|
||||
# unload all loaded modules
|
||||
#
|
||||
# Note:
|
||||
# If a Pmodule module is loaded, it will *not* be
|
||||
# unloaded!
|
||||
#
|
||||
local -r subcommand='purge'
|
||||
local -a args=()
|
||||
while (( $# > 0)); do
|
||||
@@ -1411,21 +1418,66 @@ subcommand_purge() {
|
||||
shift
|
||||
done
|
||||
if (( ${#args[@]} > 0 )); then
|
||||
std::die 3 "%s %s: %s\n" \
|
||||
std::die 3 "%s %s: %s" \
|
||||
"${CMD}" "${subcommand}" \
|
||||
"no arguments allowd"
|
||||
fi
|
||||
# we cannot unset PMODULES_HOME, otherwise the module function
|
||||
# would fail.
|
||||
local saved_home="${PMODULES_HOME}"
|
||||
"${modulecmd}" "${Shell}" "${subcommand}"
|
||||
|
||||
# is a Pmodule module loaded?
|
||||
# if yes, save name in variable 'pmodule'
|
||||
local pmodule=''
|
||||
IFS=':'
|
||||
local -a lmfiles=($_LMFILES_)
|
||||
unset IFS
|
||||
for f in "${lmfiles[@]}"; do
|
||||
if [[ $f == */${PMODULES_MODULEFILES_DIR}/Pmodules/* ]]; then
|
||||
pmodule="${f##*/${PMODULES_MODULEFILES_DIR}/}"
|
||||
break;
|
||||
fi
|
||||
done
|
||||
|
||||
# run module purge
|
||||
# since we might have to reload a Pmodules module, we cannot
|
||||
# just run 'modulecmd ${Shell} purge'
|
||||
local tmpfile=$( "${mktemp}" /tmp/Pmodules.XXXXXX ) \
|
||||
|| std::die 1 "Oops: unable to create tmp file!\n"
|
||||
|
||||
local output=$("${modulecmd}" 'bash' 'purge' 2> "${tmpfile}")
|
||||
|
||||
local error=$( < "${tmpfile}")
|
||||
${rm} "${tmpfile}"
|
||||
if [[ "${error}" =~ ":ERROR:" ]]; then
|
||||
local s=${error%%$'\n'*}
|
||||
local error_txt='failed'
|
||||
std::die 3 "%s %s: %s" \
|
||||
"${CMD}" "${subcommand}" \
|
||||
"${error_txt}"
|
||||
fi
|
||||
if [[ "${Shell}" == "sh" ]]; then
|
||||
# for sh-like shells just echo
|
||||
echo "${output}"
|
||||
else
|
||||
# re-run with right shell
|
||||
"${modulecmd}" "${Shell}" 'purge'
|
||||
fi
|
||||
eval "${output}"
|
||||
if [[ -n "${error}" ]]; then
|
||||
echo "${error}" 1>&2
|
||||
fi
|
||||
|
||||
if [[ -n "${pmodule}" ]]; then
|
||||
# reload a previously loaded Pmodule module
|
||||
# stderr is redirected to /dev/null, otherwise
|
||||
# we may get output like
|
||||
# 'unstable module has been loaded'
|
||||
subcommand_load "${pmodule}" 2> /dev/null
|
||||
fi
|
||||
reset_modulepath
|
||||
reset_used_groups
|
||||
PMODULES_HOME="${saved_home}"
|
||||
|
||||
export_env MODULEPATH PMODULES_HOME
|
||||
}
|
||||
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# list [-hlt]
|
||||
|
||||
Reference in New Issue
Block a user