Commit dc656647 authored by Vitaly Lipatov's avatar Vitaly Lipatov

improve load_helper to skip repeated include

parent 6f6ffd53
...@@ -47,9 +47,14 @@ fi ...@@ -47,9 +47,14 @@ fi
load_helper() load_helper()
{ {
local shieldname="loaded$(echo "$1" | sed -e 's|-||g')"
# already loaded
eval "test -n \"\$$shieldname\"" && debug "Already loaded $1" && return
local CMD="$SHAREDIR/$1" local CMD="$SHAREDIR/$1"
# do not use fatal() here, it can be initial state # do not use fatal() here, it can be initial state
[ -r "$CMD" ] || { echo "FATAL: Have no $CMD helper file" ; exit 1; } [ -r "$CMD" ] || { echo "FATAL: Have no $CMD helper file" ; exit 1; }
eval "$shieldname=1"
# shellcheck disable=SC1090 # shellcheck disable=SC1090
. $CMD . $CMD
} }
......
...@@ -33,13 +33,20 @@ SHAREDIR=$PROGDIR ...@@ -33,13 +33,20 @@ SHAREDIR=$PROGDIR
load_helper() load_helper()
{ {
local shieldname="loaded$(echo "$1" | sed -e 's|-||g')"
# already loaded
eval "test -n \"\$$shieldname\"" && debug "Already loaded $1" && return
local CMD="$SHAREDIR/$1" local CMD="$SHAREDIR/$1"
# do not use fatal() here, it can be initial state # do not use fatal() here, it can be initial state
[ -r "$CMD" ] || { echo "FATAL: Have no $CMD helper file" ; exit 1; } [ -r "$CMD" ] || { echo "FATAL: Have no $CMD helper file" ; exit 1; }
eval "$shieldname=1"
# shellcheck disable=SC1090 # shellcheck disable=SC1090
. $CMD . $CMD
} }
load_helper epm-sh-functions
esu_print_help() esu_print_help()
{ {
cat <<EOF cat <<EOF
...@@ -49,7 +56,6 @@ EOF ...@@ -49,7 +56,6 @@ EOF
} }
load_helper epm-sh-functions
if [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then if [ "$1" = "-h" ] || [ "$1" = "--help" ] ; then
esu_print_help esu_print_help
......
...@@ -48,11 +48,19 @@ fi ...@@ -48,11 +48,19 @@ fi
load_helper() load_helper()
{ {
local shieldname="loaded$(echo "$1" | sed -e 's|-||g')"
# already loaded
eval "test -n \"\$$shieldname\"" && debug "Already loaded $1" && return
local CMD="$SHAREDIR/$1" local CMD="$SHAREDIR/$1"
[ -r "$CMD" ] || fatal "Have no $CMD helper file" # do not use fatal() here, it can be initial state
[ -r "$CMD" ] || { echo "FATAL: Have no $CMD helper file" ; exit 1; }
eval "$shieldname=1"
# shellcheck disable=SC1090
. $CMD . $CMD
} }
load_helper epm-sh-functions load_helper epm-sh-functions
INITDIR=/etc/init.d INITDIR=/etc/init.d
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment