helpers 2.1: rename ynh_secure_remove --file to ynh_safe_rm --target

This commit is contained in:
Alexandre Aubin 2024-06-08 16:56:23 +02:00
parent 3a1c8287b4
commit 727b0e093a
13 changed files with 40 additions and 40 deletions

View file

@ -481,10 +481,10 @@ EOF
# Requires YunoHost version 3.8.1 or higher.
ynh_remove_extra_repo() {
ynh_secure_remove --file="/etc/apt/sources.list.d/$app.list"
ynh_secure_remove --file="/etc/apt/preferences.d/$app"
ynh_safe_rm --target="/etc/apt/sources.list.d/$app.list"
ynh_safe_rm --target="/etc/apt/preferences.d/$app"
if [ -e /etc/apt/trusted.gpg.d/$app.gpg ]; then
ynh_secure_remove --file="/etc/apt/trusted.gpg.d/$app.gpg"
ynh_safe_rm --target="/etc/apt/trusted.gpg.d/$app.gpg"
fi
ynh_package_update
}

View file

@ -265,7 +265,7 @@ ynh_restore_file() {
mkdir --parents "$(dirname "$backup_file")"
mv "${dest_path}" "$backup_file" # Move the current file or directory
else
ynh_secure_remove --file=${dest_path}
ynh_safe_rm --target=${dest_path}
fi
fi

View file

@ -76,7 +76,7 @@ _ynh_app_config_apply_one() {
local bind_file="$(echo "$bind" | sed s@__INSTALL_DIR__@${install_dir:-}@ | sed s@__FINALPATH__@${final_path:-}@ | sed s/__APP__/$app/)"
if [[ "${!short_setting}" == "" ]]; then
ynh_backup_if_checksum_is_different --file="$bind_file"
ynh_secure_remove --file="$bind_file"
ynh_safe_rm --target="$bind_file"
ynh_delete_file_checksum --file="$bind_file"
ynh_print_info --message="File '$bind_file' removed"
else

View file

@ -129,7 +129,7 @@ ignoreregex =
#
# Requires YunoHost version 3.5.0 or higher.
ynh_remove_fail2ban_config() {
ynh_secure_remove --file="/etc/fail2ban/jail.d/$app.conf"
ynh_secure_remove --file="/etc/fail2ban/filter.d/$app.conf"
ynh_safe_rm --target="/etc/fail2ban/jail.d/$app.conf"
ynh_safe_rm --target="/etc/fail2ban/filter.d/$app.conf"
ynh_systemd_action --service_name=fail2ban --action=reload
}

View file

@ -240,7 +240,7 @@ ynh_cleanup_go () {
then
# Remove goenv environment configuration
ynh_print_info --message="Removing of goenv"
ynh_secure_remove --file="$goenv_install_dir"
ynh_secure_remove --file="/etc/profile.d/goenv.sh"
ynh_safe_rm --target="$goenv_install_dir"
ynh_safe_rm --target="/etc/profile.d/goenv.sh"
fi
}

View file

@ -197,7 +197,7 @@ ynh_exec_and_print_stderr_only_if_error() {
"$@" 2> "$logfile" || rc="$?"
if (( rc != 0 )); then
ynh_exec_warn cat "$logfile"
ynh_secure_remove --file="$logfile"
ynh_safe_rm --target="$logfile"
return "$rc"
fi
}

View file

@ -339,7 +339,7 @@ ynh_remove_mongo() {
mongodb_servicename=mongod
# Remove the mongodb service
yunohost service remove $mongodb_servicename
ynh_secure_remove --file="/var/lib/mongodb"
ynh_secure_remove --file="/var/log/mongodb"
ynh_safe_rm --target="/var/lib/mongodb"
ynh_safe_rm --target="/var/log/mongodb"
fi
}

View file

@ -39,7 +39,7 @@ ynh_add_nginx_config() {
#
# Requires YunoHost version 2.7.2 or higher.
ynh_remove_nginx_config() {
ynh_secure_remove --file="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_safe_rm --target="/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_systemd_action --service_name=nginx --action=reload
}
@ -58,7 +58,7 @@ ynh_change_url_nginx_config() {
local old_nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
ynh_backup_if_checksum_is_different --file="$old_nginx_conf_path"
ynh_delete_file_checksum --file="$old_nginx_conf_path"
ynh_secure_remove --file="$old_nginx_conf_path"
ynh_safe_rm --target="$old_nginx_conf_path"
# Regen the nginx conf
ynh_add_nginx_config

View file

@ -176,8 +176,8 @@ ynh_remove_nodejs() {
# If no other app uses n, remove n
if [ ! -s "$n_install_dir/ynh_app_version" ]; then
ynh_secure_remove --file="$n_install_dir"
ynh_secure_remove --file="/usr/local/n"
ynh_safe_rm --target="$n_install_dir"
ynh_safe_rm --target="/usr/local/n"
sed --in-place "/N_PREFIX/d" /root/.bashrc
rm --force /etc/cron.daily/node_update
fi

View file

@ -127,7 +127,7 @@ pm.process_idle_timeout = 10s
# Validate that the new php conf doesn't break php-fpm entirely
if ! php-fpm${phpversion} --test 2>/dev/null; then
php-fpm${phpversion} --test || true
ynh_secure_remove --file="$finalphpconf"
ynh_safe_rm --target="$finalphpconf"
ynh_die --message="The new configuration broke php-fpm?"
fi
ynh_systemd_action --service_name=$fpm_service --action=reload
@ -142,7 +142,7 @@ ynh_remove_fpm_config() {
local fpm_config_dir=$(ynh_app_setting_get --key=fpm_config_dir)
local fpm_service=$(ynh_app_setting_get --key=fpm_service)
ynh_secure_remove --file="$fpm_config_dir/pool.d/$app.conf"
ynh_safe_rm --target="$fpm_config_dir/pool.d/$app.conf"
ynh_systemd_action --service_name=$fpm_service --action=reload
}

View file

@ -123,7 +123,7 @@ ynh_install_ruby () {
else
ynh_print_info --message="Reinstalling rbenv..."
cd ..
ynh_secure_remove --file=$rbenv_install_dir
ynh_safe_rm --target=$rbenv_install_dir
mkdir -p $rbenv_install_dir
cd $rbenv_install_dir
git init -q
@ -291,8 +291,8 @@ ynh_cleanup_ruby () {
then
# Remove rbenv environment configuration
ynh_print_info --message="Removing rbenv"
ynh_secure_remove --file="$rbenv_install_dir"
ynh_secure_remove --file="/etc/profile.d/rbenv.sh"
ynh_safe_rm --target="$rbenv_install_dir"
ynh_safe_rm --target="/etc/profile.d/rbenv.sh"
fi
}

View file

@ -46,7 +46,7 @@ ynh_remove_systemd_config() {
if [ -e "$finalsystemdconf" ]; then
ynh_systemd_action --service_name=$service --action=stop
systemctl disable $service --quiet
ynh_secure_remove --file="$finalsystemdconf"
ynh_safe_rm --target="$finalsystemdconf"
systemctl daemon-reload
fi
}
@ -181,6 +181,6 @@ ynh_clean_check_starting() {
kill -SIGTERM $pid_tail 2>&1
fi
if [ -n "${templog:-}" ]; then
ynh_secure_remove --file="$templog" 2>&1
ynh_safe_rm --target="$templog" 2>&1
fi
}

View file

@ -259,7 +259,7 @@ ynh_setup_source() {
fi
if [ "$full_replace" -eq 1 ]; then
ynh_secure_remove --file="$dest_dir"
ynh_safe_rm --target="$dest_dir"
fi
# Extract source into the app dir
@ -288,11 +288,11 @@ ynh_setup_source() {
local tmp_dir=$(mktemp --directory)
unzip -quo $src_filename -d "$tmp_dir"
cp --archive $tmp_dir/*/. "$dest_dir"
ynh_secure_remove --file="$tmp_dir"
ynh_safe_rm --target="$tmp_dir"
else
unzip -quo $src_filename -d "$dest_dir"
fi
ynh_secure_remove --file="$src_filename"
ynh_safe_rm --target="$src_filename"
else
local strip=""
if [ "$src_in_subdir" != "false" ]; then
@ -308,7 +308,7 @@ ynh_setup_source() {
else
ynh_die --message="Archive format unrecognized."
fi
ynh_secure_remove --file="$src_filename"
ynh_safe_rm --target="$src_filename"
fi
# Apply patches
@ -432,30 +432,30 @@ _acceptable_path_to_delete() {
# Remove a file or a directory securely
#
# usage: ynh_secure_remove --file=path_to_remove
# | arg: -f, --file= - File or directory to remove
# usage: ynh_safe_rm --target=path_to_remove
# | arg: -t, --target= - File or directory to remove
#
# Requires YunoHost version 2.6.4 or higher.
ynh_secure_remove() {
ynh_safe_rm() {
# ============ Argument parsing =============
local -A args_array=([f]=file=)
local file
local -A args_array=([t]=target=)
local target
ynh_handle_getopts_args "$@"
# ===========================================
set +o xtrace # set +x
if [ $# -ge 2 ]; then
ynh_print_warn --message="/!\ Packager ! You provided more than one argument to ynh_secure_remove but it will be ignored... Use this helper with one argument at time."
ynh_print_warn --message="/!\ Packager ! You provided more than one argument to ynh_safe_rm but it will be ignored... Use this helper with one argument at time."
fi
if [[ -z "$file" ]]; then
ynh_print_warn --message="ynh_secure_remove called with empty argument, ignoring."
elif [[ ! -e $file ]]; then
ynh_print_info --message="'$file' wasn't deleted because it doesn't exist."
elif ! _acceptable_path_to_delete "$file"; then
ynh_print_warn --message="Not deleting '$file' because it is not an acceptable path to delete."
if [[ -z "$target" ]]; then
ynh_print_warn --message="ynh_safe_rm called with empty argument, ignoring."
elif [[ ! -e $target ]]; then
ynh_print_info --message="'$target' wasn't deleted because it doesn't exist."
elif ! _acceptable_path_to_delete "$target"; then
ynh_print_warn --message="Not deleting '$target' because it is not an acceptable path to delete."
else
rm --recursive "$file"
rm --recursive "$target"
fi
set -o xtrace # set -x