From 3b26ccc2a542c67769af5b7150137500dd1eb26f Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Fri, 28 Jun 2024 16:55:39 +0200 Subject: [PATCH] Properly handle case where $parent is empty to simplify condition --- helpers/helpers.v2.1.d/utils | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/helpers/helpers.v2.1.d/utils b/helpers/helpers.v2.1.d/utils index 6c63fe82d..af2859d78 100644 --- a/helpers/helpers.v2.1.d/utils +++ b/helpers/helpers.v2.1.d/utils @@ -237,23 +237,24 @@ _ynh_apply_default_permissions() { local target=$1 is_in_dir() { - # Returns false if child or parent is empty - child=$(realpath "$1" 2>/dev/null) - parent=$(realpath "$2" 2>/dev/null) + # Returns false if parent is empty + [ -n "$2" ] || return 1 + local child=$(realpath "$1" 2>/dev/null) + local parent=$(realpath "$2" 2>/dev/null) [[ "${child/$parent/}" != "$child" ]] } # App files can have files of their own if ynh_system_user_exists --username="$app"; then # If this is a file in $install_dir or $data_dir : it should be owned and read+writable by $app only - if [ -f "$target" ] && (([[ -z "${install_dir:-}" ]] is_in_dir "$target" "$install_dir") || ([[ -z "${install_dir:-}" ]] is_in_dir "$target" "$data_dir")) + if [ -f "$target" ] && (is_in_dir "$target" "${install_dir:-}" || is_in_dir "$target" "${data_dir:-}") then chmod 600 "$target" chown "$app:$app" "$target" return fi # If this is the install dir (so far this is the only way this helper is called with a directory) - if [ "$target" == "$install_dir" ] + if [ "$target" == "${install_dir:-}" ] then # Files inside should be owned by $app/www-data with rw-r----- (+x for folders or files that already have +x) chmod -R u=rwX,g=r-X,o=--- "$target"