From 82130814f81e6b548d7c9a2f0a37503584bc2997 Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Sat, 16 Feb 2019 06:47:54 +0100 Subject: [PATCH] fix: dev: bad cache would mess output of ``get_ordered_service_dependencies`` the second time. --- bin/compose-core | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/bin/compose-core b/bin/compose-core index eab3752..fb1636b 100755 --- a/bin/compose-core +++ b/bin/compose-core @@ -1370,13 +1370,16 @@ get_service_deps() { } export -f get_service_deps - +## XXXvlab: cache was disabled because improper. Indeed, this needs to cache +## 'depths' full state. Second, it should be _rec_get_depth() { - local elt=$1 dep deps max cache_file="$state_tmpdir/$FUNCNAME.cache.$1" + local elt=$1 dep deps max cache_file="$state_tmpdir/$FUNCNAME.cache.$1.$(declare -pA depths | md5_compat)" [ "${depths[$elt]}" ] && return 0 if [ -e "$cache_file" ]; then # debug "$FUNCNAME: cache hit ($*)" - depths[$elt]=$(cat "$cache_file") + while read-0 k v; do + depths["$k"]="$v" + done < "$cache_file" return 0 fi @@ -1402,20 +1405,21 @@ _rec_get_depth() { done # debug "Setting depth[$elt] to $((max + 1))" depths[$elt]=$((max + 1)) - echo "${depths[$elt]}" > $cache_file + array_kv_to_stdin depths > $cache_file } export -f _rec_get_depth get_ordered_service_dependencies() { - local services=("$@") cache_file="$state_tmpdir/$FUNCNAME.cache.$(echo "$*" | md5_compat)" + local services=("$@") cache_file="$state_tmpdir/$FUNCNAME.cache.$(H "$@")" \ + i value key heads depths visited if [ -e "$cache_file" ]; then # debug "$FUNCNAME: cache hit ($*)" cat "$cache_file" return 0 fi - #debug "Figuring ordered deps of $DARKYELLOW$services$NORMAL" + #debug "Figuring ordered deps of $DARKYELLOW${services[@]}$NORMAL" if [ -z "${services[*]}" ]; then return 0 # print_syntax_error "$FUNCNAME: no arguments" @@ -1439,7 +1443,7 @@ get_ordered_service_dependencies() { unset depths[$key] fi done - i=$((i + 1)) + ((i++)) done | tee "$cache_file" } export -f get_ordered_service_dependencies