Improve HOMEBREW_TEMP handling

- if HOMEBREW_TEMP is not writable, use the default temp directory
- when running `brew bundle exec`, strip various temporary directories
  from the environment if they are not writable
This commit is contained in:
Mike McQuaid 2025-04-14 19:10:58 +01:00
parent f9fe0f573b
commit dbbffbaca5
No known key found for this signature in database
2 changed files with 12 additions and 0 deletions

View File

@ -104,6 +104,10 @@ HOMEBREW_CASKROOM="${HOMEBREW_PREFIX}/Caskroom"
HOMEBREW_CACHE="${HOMEBREW_CACHE:-${HOMEBREW_DEFAULT_CACHE}}"
HOMEBREW_LOGS="${HOMEBREW_LOGS:-${HOMEBREW_DEFAULT_LOGS}}"
HOMEBREW_TEMP="${HOMEBREW_TEMP:-${HOMEBREW_DEFAULT_TEMP}}"
if [[ ! -w "${HOMEBREW_TEMP}" ]]
then
HOMEBREW_TEMP="${HOMEBREW_DEFAULT_TEMP}"
fi
# commands that take a single or no arguments.
# HOMEBREW_LIBRARY set by bin/brew

View File

@ -111,6 +111,14 @@ module Homebrew
# For commands which aren't either absolute or relative
raise "command was not found in your PATH: #{command}" if command.exclude?("/") && which(command).nil?
%w[HOMEBREW_TEMP TMPDIR HOMEBREW_TMPDIR].each do |var|
value = ENV.fetch(var, nil)
next if value.blank?
next if File.writable?(value)
ENV.delete(var)
end
if subcommand == "env"
ENV.sort.each do |key, value|
# No need to export empty values.