mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Improve ynh_secure_remove to detect empty args instead of miserably saying 'Avoid deleting .'
This commit is contained in:
parent
61e6840ed3
commit
551ff80792
1 changed files with 10 additions and 9 deletions
|
@ -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."
|
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
|
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
|
# Match all paths or subpaths in $forbidden_path
|
||||||
|| "$file" =~ ^/[[:alnum:]]+$ \
|
|| "$file" =~ ^/[[:alnum:]]+$ \
|
||||||
# Match all first level paths from / (Like /var, /root, etc...)
|
# Match all first level paths from / (Like /var, /root, etc...)
|
||||||
|| "${file:${#file}-1}" = "/" ]]
|
|| "${file:${#file}-1}" = "/" ]]
|
||||||
# Match if the path finishes by /. Because it seems there is an empty variable
|
# Match if the path finishes by /. Because it seems there is an empty variable
|
||||||
then
|
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
|
else
|
||||||
if [ -e "$file" ]
|
ynh_print_info --message="'$file' wasn't deleted because it doesn't exist."
|
||||||
then
|
fi fi fi
|
||||||
sudo rm -R "$file"
|
|
||||||
else
|
|
||||||
ynh_print_info --message="$file wasn't deleted because it doesn't exist."
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Extract a key from a plain command output
|
# Extract a key from a plain command output
|
||||||
|
|
Loading…
Add table
Reference in a new issue