From 3288d9f38b35e02b75d74d3fc55fe6e405879348 Mon Sep 17 00:00:00 2001 From: merakor Date: Wed, 3 Nov 2021 12:45:33 +0000 Subject: run_hook: fix logging, simplify FossilOrigin-Name: 4b091264bec032884deb45237731351d8f3307b6546f3be08da751d8f9110bbd --- src/cpt-lib.in | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/cpt-lib.in b/src/cpt-lib.in index effb730..517f198 100644 --- a/src/cpt-lib.in +++ b/src/cpt-lib.in @@ -555,25 +555,26 @@ pop() { } run_hook() { - # Run hooks defined by the system and the user. - - if [ "$2" ]; then - logv "$2" "Running $1 hook" - else - logv "Running $1 hook" - fi - - # Run all the hooks found in the configuration directory. + # Check that hooks exist before announcing that we are running a hook. set +f - for hook in "$cpt_confdir/hooks/"*; do + for hook in "$cpt_confdir/hooks/"* "$CPT_HOOK"; do + [ -f "$hook" ] && { + if [ "$2" ]; then + logv "$2" "Running $1 hook" + else + logv "Running $1 hook" + fi + break + } + done + + # Run all the hooks found in the configuration directory, and the user + # defined hook. + for hook in "$cpt_confdir/hooks/"* "$CPT_HOOK"; do set -f [ -f "$hook" ] || continue TYPE=${1:-null} PKG=${2:-null} DEST=${3:-null} . "$hook" done - - [ -f "$CPT_HOOK" ] || return 0 - - TYPE=${1:-null} PKG=${2:-null} DEST=${3:-null} . "$CPT_HOOK" } # An optional argument could be provided to enforce a compression algorithm. -- cgit v1.2.3