config helpers: Disable bash xtrace during ynh_read/write_var_from_file to avoid an horrendous amount of debug logs

This commit is contained in:
Alexandre Aubin 2021-09-16 18:52:21 +02:00
parent 63d3ccd827
commit 47db3e798e

View file

@ -519,6 +519,8 @@ ynh_read_var_in_file() {
[[ -f $file ]] || ynh_die --message="File $file does not exists" [[ -f $file ]] || ynh_die --message="File $file does not exists"
set +o xtrace # set +x
# Get the line number after which we search for the variable # Get the line number after which we search for the variable
local line_number=1 local line_number=1
if [[ -n "$after" ]]; if [[ -n "$after" ]];
@ -526,6 +528,7 @@ ynh_read_var_in_file() {
line_number=$(grep -n $after $file | cut -d: -f1) line_number=$(grep -n $after $file | cut -d: -f1)
if [[ -z "$line_number" ]]; if [[ -z "$line_number" ]];
then then
set -o xtrace # set -x
return 1 return 1
fi fi
fi fi
@ -555,6 +558,7 @@ ynh_read_var_in_file() {
# Extract the part after assignation sign # Extract the part after assignation sign
local expression_with_comment="$(tail +$line_number ${file} | grep -i -o -P $var_part'\K.*$' || echo YNH_NULL | head -n1)" local expression_with_comment="$(tail +$line_number ${file} | grep -i -o -P $var_part'\K.*$' || echo YNH_NULL | head -n1)"
if [[ "$expression_with_comment" == "YNH_NULL" ]]; then if [[ "$expression_with_comment" == "YNH_NULL" ]]; then
set -o xtrace # set -x
echo YNH_NULL echo YNH_NULL
return 0 return 0
fi fi
@ -570,6 +574,7 @@ ynh_read_var_in_file() {
else else
echo "$expression" echo "$expression"
fi fi
set -o xtrace # set -x
} }
# Set a value into heterogeneous file (yaml, json, php, python...) # Set a value into heterogeneous file (yaml, json, php, python...)
@ -594,6 +599,8 @@ ynh_write_var_in_file() {
[[ -f $file ]] || ynh_die --message="File $file does not exists" [[ -f $file ]] || ynh_die --message="File $file does not exists"
set +o xtrace # set +x
# Get the line number after which we search for the variable # Get the line number after which we search for the variable
local line_number=1 local line_number=1
if [[ -n "$after" ]]; if [[ -n "$after" ]];
@ -601,6 +608,7 @@ ynh_write_var_in_file() {
line_number=$(grep -n $after $file | cut -d: -f1) line_number=$(grep -n $after $file | cut -d: -f1)
if [[ -z "$line_number" ]]; if [[ -z "$line_number" ]];
then then
set -o xtrace # set -x
return 1 return 1
fi fi
fi fi
@ -631,6 +639,7 @@ ynh_write_var_in_file() {
# Extract the part after assignation sign # Extract the part after assignation sign
local expression_with_comment="$(tail +$line_number ${file} | grep -i -o -P $var_part'\K.*$' || echo YNH_NULL | head -n1)" local expression_with_comment="$(tail +$line_number ${file} | grep -i -o -P $var_part'\K.*$' || echo YNH_NULL | head -n1)"
if [[ "$expression_with_comment" == "YNH_NULL" ]]; then if [[ "$expression_with_comment" == "YNH_NULL" ]]; then
set -o xtrace # set -x
return 1 return 1
fi fi
@ -661,6 +670,7 @@ ynh_write_var_in_file() {
fi fi
sed -ri "${range}s$delimiter(^${var_part}).*\$$delimiter\1${value}${endline}${delimiter}i" ${file} sed -ri "${range}s$delimiter(^${var_part}).*\$$delimiter\1${value}${endline}${delimiter}i" ${file}
fi fi
set -o xtrace # set -x
} }