mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
Properly handle case where $parent is empty to simplify condition
This commit is contained in:
parent
3608c5678c
commit
3b26ccc2a5
1 changed files with 6 additions and 5 deletions
|
@ -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"
|
||||
|
|
Loading…
Add table
Reference in a new issue