Browse Source

chg: dev: refactor out ``metadata`` reading for provide

We will need it when looking for charms provider.
hostresources
Valentin Lab 6 years ago
parent
commit
f8ab2a87da
  1. 50
      bin/compose-core

50
bin/compose-core

@ -1977,6 +1977,54 @@ _get_services_uses() {
export -f _get_services_uses
_get_provides_provides() {
local provides="$1" cache_file="$CACHEDIR/$FUNCNAME.cache.$(printf "%s\0" "$@" | md5_compat)" \
service rn rd
if [ -e "$cache_file" ]; then
debug "$FUNCNAME: CACHEDIR cache hit $1"
cat "$cache_file"
return 0
fi
type=$(printf "%s" "$provides" | shyaml get-type)
case "$type" in
sequence)
while read-0 prov; do
printf "%s\0" "$prov" ""
done < <(echo "$provides" | shyaml get-values-0)
;;
struct)
printf "%s" "$provides" | shyaml key-values-0
;;
str)
printf "%s\0" "$(echo "$provides" | shyaml get-value)" ""
;;
*)
err "Unexpected type '$type' for provider identifier in charm '$charm'."
return 1
esac | tee "$cache_file"
return "${PIPESTATUS[0]}"
}
_get_metadata_provides() {
local metadata="$1" cache_file="$CACHEDIR/$FUNCNAME.cache.$(printf "%s\0" "$@" | md5_compat)" \
service rn rd
if [ -e "$cache_file" ]; then
debug "$FUNCNAME: CACHEDIR cache hit"
cat "$cache_file"
return 0
fi
provides=$(printf "%s" "$metadata" | shyaml get-value -y -q provides "")
[ "$provides" -a "$provides" != "''" ] || { touch "$cache_file"; return 0; }
_get_provides_provides "$provides" | tee "$cache_file"
return "${PIPESTATUS[0]}"
}
_get_services_provides() {
local cache_file="$state_tmpdir/$FUNCNAME.cache.$(printf "%s\0" "$@" | md5_compat)" \
service rn rd
@ -1993,7 +2041,7 @@ _get_services_provides() {
while read-0 rn rd; do
printf "%s\0" "$service" "$rn" "$rd"
done < <(printf "%s" "$metadata" | shyaml key-values-0 provides 2>/dev/null)
done < <(_get_metadata_provides "$metadata")
done > "$cache_file"
if [ "$?" != 0 ]; then
rm -f "$cache_file" ## no cache

Loading…
Cancel
Save