From f80700806fb21f784ca5f7c45246016a793b7f7a Mon Sep 17 00:00:00 2001 From: Alexander Barton Date: Wed, 21 Sep 2022 23:19:09 +0200 Subject: [PATCH] homebrew: brew() function: Test permissions on the repository Don't test it on the "prefix", because permissions on this directory can be more restrictive (which could be fine ...). --- plugins/homebrew/homebrew.zshrc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/plugins/homebrew/homebrew.zshrc b/plugins/homebrew/homebrew.zshrc index 34f0b69..8759da5 100644 --- a/plugins/homebrew/homebrew.zshrc +++ b/plugins/homebrew/homebrew.zshrc @@ -31,9 +31,11 @@ function brew() { return 101 fi - brew_prefix=$("$real_brew_cmd" --prefix) || return 102 + if [[ -z "$HOMEBREW_REPOSITORY" ]]; then + eval "$("$real_brew_cmd" shellenv)" + fi - if [[ $(/bin/ls -ldn "$brew_prefix" | awk '{print $3}') -eq $UID ]]; then + if [[ $(/bin/ls -ldn "$HOMEBREW_REPOSITORY" | awk '{print $3}') -eq $UID ]]; then # We are the owner of the Homebrew installation. ( [[ $# -eq 0 && -t 1 ]] \ @@ -48,8 +50,8 @@ function brew() { priv_exec="umask 0022 || exit 103; \"$real_brew_cmd\" $*" ( cd /tmp - user="$(/bin/ls -ld "$brew_prefix" | awk '{print $3}')" - group="$(/bin/ls -ld "$brew_prefix" | awk '{print $4}')" + user="$(/bin/ls -ld "$HOMEBREW_REPOSITORY" | awk '{print $3}')" + group="$(/bin/ls -ld "$HOMEBREW_REPOSITORY" | awk '{print $4}')" [[ $# -eq 0 && -t 1 ]] \ && echo "Running \"$real_brew_cmd\" as user \"$user:$group\" ..." sudo -u "$user" -g "$group" -- sh -c "$priv_exec" -- 2.39.2