config helpers: Semantics / comments on the validation-apply workflow

This commit is contained in:
Alexandre Aubin 2021-09-05 19:15:52 +02:00
parent 62eecb28db
commit ee55b9bf42

View file

@ -160,7 +160,8 @@ _ynh_app_config_show() {
_ynh_app_config_validate() { _ynh_app_config_validate() {
# Change detection # Change detection
ynh_script_progression --message="Checking what changed in the new configuration..." --weight=1 ynh_script_progression --message="Checking what changed in the new configuration..." --weight=1
local is_error=true local nothing_changed=true
local changes_validated=true
#for changed_status in "${!changed[@]}" #for changed_status in "${!changed[@]}"
for short_setting in "${!old[@]}" for short_setting in "${!old[@]}"
do do
@ -178,7 +179,7 @@ _ynh_app_config_validate() {
file_hash[old__$short_setting]=$(sha256sum "${old[$short_setting]}" | cut -d' ' -f1) file_hash[old__$short_setting]=$(sha256sum "${old[$short_setting]}" | cut -d' ' -f1)
if [ -z "${!short_setting}" ] ; then if [ -z "${!short_setting}" ] ; then
changed[$short_setting]=true changed[$short_setting]=true
is_error=false nothing_changed=false
fi fi
fi fi
if [ -f "${!short_setting}" ] ; then if [ -f "${!short_setting}" ] ; then
@ -186,18 +187,18 @@ _ynh_app_config_validate() {
if [[ "${file_hash[old__$short_setting]}" != "${file_hash[new__$short_setting]}" ]] if [[ "${file_hash[old__$short_setting]}" != "${file_hash[new__$short_setting]}" ]]
then then
changed[$short_setting]=true changed[$short_setting]=true
is_error=false nothing_changed=false
fi fi
fi fi
else else
if [[ "${!short_setting}" != "${old[$short_setting]}" ]] if [[ "${!short_setting}" != "${old[$short_setting]}" ]]
then then
changed[$short_setting]=true changed[$short_setting]=true
is_error=false nothing_changed=false
fi fi
fi fi
done done
if [[ "$is_error" == "true" ]] if [[ "$nothing_changed" == "true" ]]
then then
ynh_print_info "Nothing has changed" ynh_print_info "Nothing has changed"
exit 0 exit 0
@ -217,11 +218,13 @@ _ynh_app_config_validate() {
then then
local key="YNH_ERROR_${short_setting}" local key="YNH_ERROR_${short_setting}"
ynh_return "$key: \"$result\"" ynh_return "$key: \"$result\""
is_error=true changes_validated=false
fi fi
done done
if [[ "$is_error" == "true" ]] # If validation failed, exit the script right now (instead of going into apply)
# Yunohost core will pick up the errors returned via ynh_return previously
if [[ "$changes_validated" == "false" ]]
then then
exit 0 exit 0
fi fi