|
|
@ -648,25 +648,37 @@ export -f get_service_deps |
|
|
|
|
|
|
|
|
|
|
|
_rec_get_depth() { |
|
|
|
local elt=$1 |
|
|
|
|
|
|
|
#debug "Asking for $DARKYELLOW$elt$NORMAL dependencies" |
|
|
|
if [ "${depths[$elt]}" ]; then |
|
|
|
local elt=$1 dep deps max cache_file="$state_tmpdir/$FUNCNAME.cache.$1" |
|
|
|
[ "${depths[$elt]}" ] && return 0 |
|
|
|
if [ -e "$cache_file" ]; then |
|
|
|
# debug "$FUNCNAME: cache hit ($*)" |
|
|
|
depths[$elt]=$(cat "$cache_file") |
|
|
|
return 0 |
|
|
|
fi |
|
|
|
deps=$(get_service_deps "$elt") || return 1 |
|
|
|
if [ -z "$deps" ]; then |
|
|
|
depths[$elt]=0 |
|
|
|
fi |
|
|
|
|
|
|
|
visited[$elt]=1 |
|
|
|
#debug "Setting visited[$elt]" |
|
|
|
#debug "Asking for $DARKYELLOW$elt$NORMAL dependencies" |
|
|
|
deps=$(get_service_deps "$elt") || { |
|
|
|
debug "Failed get_service_deps $elt" |
|
|
|
return 1 |
|
|
|
} |
|
|
|
# debug "$elt deps are:" $deps |
|
|
|
max=0 |
|
|
|
for dep in $deps; do |
|
|
|
[ "${visited[$dep]}" ] && { |
|
|
|
#debug "Already computing $dep" |
|
|
|
continue |
|
|
|
} |
|
|
|
_rec_get_depth "$dep" || return 1 |
|
|
|
if (( "${depths[$dep]}" > "$max" )); then |
|
|
|
#debug "Requesting depth[$dep]" |
|
|
|
if (( ${depths[$dep]} > max )); then |
|
|
|
max="${depths[$dep]}" |
|
|
|
fi |
|
|
|
fi |
|
|
|
done |
|
|
|
# debug "Setting depth[$elt] to $((max + 1))" |
|
|
|
depths[$elt]=$((max + 1)) |
|
|
|
echo "${depths[$elt]}" > $cache_file |
|
|
|
} |
|
|
|
export -f _rec_get_depth |
|
|
|
|
|
|
@ -685,11 +697,10 @@ get_ordered_service_dependencies() { |
|
|
|
fi |
|
|
|
|
|
|
|
declare -A depths |
|
|
|
visited=() |
|
|
|
declare -A visited |
|
|
|
heads=("${services[@]}") |
|
|
|
while [ "${#heads[@]}" != 0 ]; do |
|
|
|
array_pop heads head |
|
|
|
visited+=("$head") |
|
|
|
_rec_get_depth "$head" || return 1 |
|
|
|
done |
|
|
|
|
|
|
|