From 551ff807923eb74a1783e8abdd3e41cc22f3bfad Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Sat, 16 Nov 2019 15:46:23 +0100 Subject: [PATCH] Improve ynh_secure_remove to detect empty args instead of miserably saying 'Avoid deleting .' --- data/helpers.d/utils | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/data/helpers.d/utils b/data/helpers.d/utils index a359423bb..d449f0c39 100644 --- a/data/helpers.d/utils +++ b/data/helpers.d/utils @@ -312,22 +312,23 @@ ynh_secure_remove () { 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." fi - if [[ "$forbidden_path" =~ "$file" \ + if [[ -z "$file" ]] + then + ynh_print_warn --message="ynh_secure_remove called with empty argument, ignoring." + else if [[ "$forbidden_path" =~ "$file" \ # Match all paths or subpaths in $forbidden_path || "$file" =~ ^/[[:alnum:]]+$ \ # Match all first level paths from / (Like /var, /root, etc...) || "${file:${#file}-1}" = "/" ]] # Match if the path finishes by /. Because it seems there is an empty variable then - ynh_print_warn --message="Avoid deleting $file." + ynh_print_warn --message="Not deleting '$file' because it is not an acceptable path to delete." + else if [ -e "$file" ] + then + rm -R "$file" else - if [ -e "$file" ] - then - sudo rm -R "$file" - else - ynh_print_info --message="$file wasn't deleted because it doesn't exist." - fi - fi + ynh_print_info --message="'$file' wasn't deleted because it doesn't exist." + fi fi fi } # Extract a key from a plain command output