From 88271757a51a9ea991eda169244a568a5b80d857 Mon Sep 17 00:00:00 2001 From: Ghe Rivero Date: Wed, 8 Oct 2014 10:43:32 +0000 Subject: [PATCH] Avoid overwritting of hooks Until now there was a possibility for two elements to install hooks with the same name, so one of them was overwritten. Change logic to copy the hooks and fail in case one with the same name exists. Change-Id: Ic2c46835b27c9319f7a889ffd0ccf3f5ccc1f0cd Closes-Bug: 1251952 --- lib/common-functions | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/common-functions b/lib/common-functions index f7b32cd2..d66900a7 100644 --- a/lib/common-functions +++ b/lib/common-functions @@ -58,12 +58,30 @@ function save_image () { finish_image $1 } +function copy_hooks_not_overwrite () { + _DIR=$(basename $1) + test -d $TMP_HOOKS_PATH/$_DIR || mkdir $TMP_HOOKS_PATH/$_DIR + for _HOOK in $(ls $1); do + if [ ! -f $TMP_HOOKS_PATH/$_DIR/$_HOOK ]; then + cp -t $TMP_HOOKS_PATH/$_DIR -a $1/$_HOOK + else + echo "There is a duplicated hook in your elements: $_ELEMENT/$_DIR/$_HOOK" + exit 1 + fi + done +} + function generate_hooks () { mkdir -p $TMP_HOOKS_PATH for _ELEMENT in $IMAGE_ELEMENT ; do for dir in ${ELEMENTS_PATH//:/ } ; do [ -d $dir/$_ELEMENT ] || continue - cp -t $TMP_HOOKS_PATH -a $dir/$_ELEMENT/* ; + for _DIR in $(find $dir/$_ELEMENT -mindepth 1 -maxdepth 1 -type d -not -name tests); do + copy_hooks_not_overwrite $_DIR + done + for _FILE in $(find $dir/$_ELEMENT -maxdepth 1 -type f); do + cp -t $TMP_HOOKS_PATH -a $_FILE + done break done done