Cleanup HOMEBREW_TEMP handling

- Ensure that `HOMEBREW_TEMP` is only displayed in `brew config` when
  it's non-default.
- Attempt to create a missing `HOMEBREW_TEMP` directory rather than
  failing to `realpath`. Note this will still fail on permissions errors
  which is to be expected.
This commit is contained in:
Mike McQuaid 2018-07-03 15:41:33 +01:00
parent 09ee556833
commit f46e4596c0
4 changed files with 50 additions and 37 deletions

View File

@ -105,8 +105,7 @@ then
fi
HOMEBREW_CACHE="${HOMEBREW_CACHE:-${HOME}/Library/Caches/Homebrew}"
HOMEBREW_TEMP="${HOMEBREW_TEMP:-/private/tmp}"
HOMEBREW_SYSTEM_TEMP="/private/tmp"
else
HOMEBREW_PROCESSOR="$(uname -m)"
HOMEBREW_PRODUCT="${HOMEBREW_SYSTEM}brew"
@ -116,10 +115,11 @@ else
CACHE_HOME="${XDG_CACHE_HOME:-${HOME}/.cache}"
HOMEBREW_CACHE="${HOMEBREW_CACHE:-${CACHE_HOME}/Homebrew}"
HOMEBREW_TEMP="${HOMEBREW_TEMP:-/tmp}"
HOMEBREW_SYSTEM_TEMP="/tmp"
fi
HOMEBREW_TEMP="${HOMEBREW_TEMP:-${HOMEBREW_SYSTEM_TEMP}}"
if [[ -n "$HOMEBREW_FORCE_BREWED_CURL" &&
-x "$HOMEBREW_PREFIX/opt/curl/bin/curl" ]] &&
"$HOMEBREW_PREFIX/opt/curl/bin/curl" --version >/dev/null
@ -147,6 +147,7 @@ export HOMEBREW_BREW_FILE
export HOMEBREW_PREFIX
export HOMEBREW_REPOSITORY
export HOMEBREW_LIBRARY
export HOMEBREW_SYSTEM_TEMP
export HOMEBREW_TEMP
# Declared in brew.sh

View File

@ -39,7 +39,11 @@ HOMEBREW_CACHE_FORMULA = HOMEBREW_CACHE/"Formula"
HOMEBREW_LOGS = Pathname.new(ENV["HOMEBREW_LOGS"] || "~/Library/Logs/Homebrew/").expand_path
# Must use /tmp instead of $TMPDIR because long paths break Unix domain sockets
HOMEBREW_TEMP = Pathname.new(ENV["HOMEBREW_TEMP"]).realpath
HOMEBREW_TEMP = begin
tmp = Pathname.new(ENV["HOMEBREW_TEMP"])
tmp.mkpath unless tmp.exist?
tmp.realpath
end
unless defined? HOMEBREW_LIBRARY_PATH
# Root of the Homebrew code base

View File

@ -31,14 +31,15 @@ module Homebrew
ENV["HOMEBREW_UPDATE_TEST"] = "1"
if args.to_tag?
branch = if args.to_tag?
ENV["HOMEBREW_UPDATE_TO_TAG"] = "1"
branch = "stable"
"stable"
else
branch = "master"
"master"
end
cd HOMEBREW_REPOSITORY
start_commit, end_commit = nil
cd HOMEBREW_REPOSITORY do
start_commit = if commit = args.commit
commit
elsif date = args.before
@ -68,12 +69,12 @@ module Homebrew
end_commit = Utils.popen_read("git", "rev-parse", "HEAD").chomp
odie "Could not find end commit!" if end_commit.empty?
end
puts "Start commit: #{start_commit}"
puts "End commit: #{end_commit}"
mktemp("update-test") do |staging|
staging.retain! if args.keep_tmp?
mkdir "update-test" do
curdir = Pathname.new(Dir.pwd)
oh1 "Setup test environment..."
@ -107,5 +108,7 @@ module Homebrew
EOS
end
end
ensure
FileUtils.rm_r "update-test" unless args.keep_tmp?
end
end

View File

@ -116,6 +116,7 @@ class SystemConfig
HOMEBREW_CELLAR: "/usr/local/Cellar",
HOMEBREW_CACHE: "#{ENV["HOME"]}/Library/Caches/Homebrew",
HOMEBREW_RUBY_WARNINGS: "-W0",
HOMEBREW_TEMP: ENV["HOMEBREW_SYSTEM_TEMP"],
}.freeze
boring_keys = %w[
HOMEBREW_BROWSER
@ -134,6 +135,7 @@ class SystemConfig
HOMEBREW_MACOS_VERSION
HOMEBREW_RUBY_PATH
HOMEBREW_SYSTEM
HOMEBREW_SYSTEM_TEMP
HOMEBREW_OS_VERSION
HOMEBREW_PATH
HOMEBREW_PROCESSOR
@ -155,6 +157,9 @@ class SystemConfig
if defaults_hash[:HOMEBREW_RUBY_WARNINGS] != ENV["HOMEBREW_RUBY_WARNINGS"].to_s
f.puts "HOMEBREW_RUBY_WARNINGS: #{ENV["HOMEBREW_RUBY_WARNINGS"]}"
end
if defaults_hash[:HOMEBREW_TEMP] != HOMEBREW_TEMP.to_s
f.puts "HOMEBREW_TEMP: #{HOMEBREW_TEMP}"
end
unless ENV["HOMEBREW_ENV"]
ENV.sort.each do |key, value|
next unless key.start_with?("HOMEBREW_")