Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

brew.sh: Don't allow system tmp dirs as prefixes #4397

Merged
merged 14 commits into from
Jul 3, 2018
13 changes: 13 additions & 0 deletions Library/Homebrew/brew.sh
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,19 @@ EOS
}
check-run-command-as-root

check-prefix-is-not-tmpdir() {
if [[ $(realpath "${HOMEBREW_PREFIX}") = /private/tmp/* ]]
then
odie <<EOS
Your HOMEBREW_PREFIX is in the system temporary directory, which Homebrew
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe worth just saying e.g. /private/tmp? Also, should we do this on Linux or with a different directory?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought that the connection between /tmp and /private/tmp might confuse some users (Apple links /tmp to /private/tmp for FHS compliance), so I just went with "system temporary directory." I can change it/add those directories to the message if you think it'll improve the error, though.

The relocation code at fault isn't used on Linux, so Linuxbrew users might not encounter this problem at all. I'll confirm that in a bit with some local testing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HOMEBREW_TEMP isn't necessary the system temporary directory. To expand on my previous comment (and avoid the autohiding): is the issue if:

  • the prefix is in the system temporary directory
  • the prefix is the in the HOMEBREW_TEMP temporary directory
  • either

We should ensure that the wording makes that clear and the logic is as minimal as possible to the actual problems we've seen people experience.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is when the prefix is in the HOMEBREW_TEMP temporary directory. I'll correct the language here 🙂

uses to store downloads and builds. You can resolve this by installing Homebrew to
either the standard prefix (/usr/local/) or to a non-standard prefix that is not
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(/usr/local) maybe?

in the system temporary directory.
EOS
fi
}
check-prefix-is-not-tmpdir

if [[ "$HOMEBREW_PREFIX" = "/usr/local" &&
"$HOMEBREW_PREFIX" != "$HOMEBREW_REPOSITORY" &&
"$HOMEBREW_CELLAR" = "$HOMEBREW_REPOSITORY/Cellar" ]]
Expand Down