@@ -273,23 +273,46 @@ _mk_pgp_signature() {
273273# Helper function to run functions only one time.
274274# $1: function name
275275_run_once () {
276- if type -t " pre_$1 " > /dev/null 2>&1 && [[ ! -e " ${work_dir} /${run_once_mode} .pre_$1 " ]]; then
277- " pre_$1 "
278- touch " ${work_dir} /${run_once_mode} .pre_$1 "
279- fi
280- if [[ ! -e " ${work_dir} /${run_once_mode} .${1} " ]]; then
281- if type -t " override_$1 " > /dev/null 2>&1 ; then
282- " override_$1 "
276+ local _is_func _is_array _execute
277+ _is_func () {
278+ type -t " $1 " > /dev/null 2>&1
279+ }
280+ _is_array () {
281+ declare -p " $1 " 2> /dev/null | grep -q ' declare \-a'
282+ }
283+
284+ # _execute(prefix: "pre" | "post" | "override", function: ()=>void)
285+ _execute () {
286+ local _prefix=" $1 " _org_function=" $2 "
287+ local _lockfile=" ${work_dir} /${run_once_mode} .${_prefix} _${_org_function} "
288+ local _injected=" ${_prefix} _${_org_function} "
289+ local _func
290+
291+ if [[ " $_prefix " == " override" ]]; then
292+ _lockfile=" ${work_dir} /${run_once_mode} .${_org_function} "
293+ fi
294+ if [[ -e " ${_lockfile} " ]]; then
295+ return 0
296+ fi
297+
298+ if _is_func " $_injected " ; then
299+ " $_injected "
300+ elif _is_array " $_injected " ; then
301+ while read -r _func; do
302+ " $_func "
303+ done < <( eval " printf '%s\n' \"\$ {${_injected} [@]}\" " )
304+ elif [[ " $_prefix " == " override" ]]; then
305+ " $_org_function "
283306 else
284- " $1 "
307+ return 0
285308 fi
309+ touch " ${_lockfile} "
286310
287- touch " ${work_dir} /${run_once_mode} .${1} "
288- fi
289- if type -t " post_$1 " > /dev/null 2>&1 && [[ ! -e " ${work_dir} /${run_once_mode} .post_$1 " ]]; then
290- " post_$1 "
291- touch " ${work_dir} /${run_once_mode} .post_$1 "
292- fi
311+ }
312+
313+ _execute " pre" " $1 "
314+ _execute " override" " $1 "
315+ _execute " post" " $1 "
293316}
294317
295318# Set up custom pacman.conf with custom cache and pacman hook directories.
0 commit comments