Browse Source

fix: dev: bad cache would mess output of ``get_ordered_service_dependencies`` the second time.

hostresources
Valentin Lab 6 years ago
parent
commit
82130814f8
  1. 18
      bin/compose-core

18
bin/compose-core

@ -1370,13 +1370,16 @@ get_service_deps() {
} }
export -f 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() { _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 [ "${depths[$elt]}" ] && return 0
if [ -e "$cache_file" ]; then if [ -e "$cache_file" ]; then
# debug "$FUNCNAME: cache hit ($*)" # debug "$FUNCNAME: cache hit ($*)"
depths[$elt]=$(cat "$cache_file")
while read-0 k v; do
depths["$k"]="$v"
done < "$cache_file"
return 0 return 0
fi fi
@ -1402,20 +1405,21 @@ _rec_get_depth() {
done done
# debug "Setting depth[$elt] to $((max + 1))" # debug "Setting depth[$elt] to $((max + 1))"
depths[$elt]=$((max + 1)) depths[$elt]=$((max + 1))
echo "${depths[$elt]}" > $cache_file
array_kv_to_stdin depths > $cache_file
} }
export -f _rec_get_depth export -f _rec_get_depth
get_ordered_service_dependencies() { 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 if [ -e "$cache_file" ]; then
# debug "$FUNCNAME: cache hit ($*)" # debug "$FUNCNAME: cache hit ($*)"
cat "$cache_file" cat "$cache_file"
return 0 return 0
fi fi
#debug "Figuring ordered deps of $DARKYELLOW$services$NORMAL"
#debug "Figuring ordered deps of $DARKYELLOW${services[@]}$NORMAL"
if [ -z "${services[*]}" ]; then if [ -z "${services[*]}" ]; then
return 0 return 0
# print_syntax_error "$FUNCNAME: no arguments" # print_syntax_error "$FUNCNAME: no arguments"
@ -1439,7 +1443,7 @@ get_ordered_service_dependencies() {
unset depths[$key] unset depths[$key]
fi fi
done done
i=$((i + 1))
((i++))
done | tee "$cache_file" done | tee "$cache_file"
} }
export -f get_ordered_service_dependencies export -f get_ordered_service_dependencies

Loading…
Cancel
Save