From 29423ac3b648eb608155954e4dce083b7ee87b91 Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Wed, 4 May 2022 09:59:33 +0200 Subject: [PATCH] new: [compose-core] make ``service:relation-file`` always return an existing file It must create it with ``compose`` / ``default-options`` values by default if not already created. Signed-off-by: Valentin Lab --- bin/compose-core | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/bin/compose-core b/bin/compose-core index a32bd67..ecc3233 100755 --- a/bin/compose-core +++ b/bin/compose-core @@ -2148,7 +2148,7 @@ service:relation-file() { fi relation="${service_path##*${TRAVERSE_SEPARATOR}}" service=$(service:traverse "${service_path%${TRAVERSE_SEPARATOR}*}") || return 1 - if ! read-0 ts _ _ < <(get_service_relation "${service}" "${relation}"); then + if ! read-0 ts rc _ < <(get_service_relation "${service}" "${relation}"); then err "Couldn't find relation ${DARKCYAN}${relation}${NORMAL}" \ "from ${DARKYELLOW}$service${NORMAL}." return 1 @@ -2157,7 +2157,12 @@ service:relation-file() { err "Failed to find relation file" return 1 } - echo "$relation_dir/data" + relation_file="$relation_dir/data" + if ! [ -e "$relation_file" ]; then + e "$rc" > "$relation_file" + chmod go-rwx "$relation_file" ## protecting this file + fi + echo "$relation_file" } export -f service:relation-file