From a4033c7196ad842ed37ef05110fd58fd7aa33856 Mon Sep 17 00:00:00 2001 From: Shaun Jackman Date: Mon, 11 Dec 2017 15:32:57 -0800 Subject: [PATCH 1/2] Do not specify absolute paths to utilities Specifying an absolute path to utilities is no longer needed, since environment filtering uses a default PATH. --- Library/Homebrew/brew.sh | 4 ++-- Library/Homebrew/keg_relocate.rb | 6 +++--- Library/Homebrew/utils.rb | 2 +- Library/Homebrew/utils/curl.rb | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Library/Homebrew/brew.sh b/Library/Homebrew/brew.sh index ef024cb53e..3299917ec5 100644 --- a/Library/Homebrew/brew.sh +++ b/Library/Homebrew/brew.sh @@ -85,7 +85,7 @@ case "$HOMEBREW_SYSTEM" in Linux) HOMEBREW_LINUX="1" ;; esac -HOMEBREW_CURL="/usr/bin/curl" +HOMEBREW_CURL="curl" if [[ -n "$HOMEBREW_MACOS" ]] then HOMEBREW_PROCESSOR="$(uname -p)" @@ -136,7 +136,7 @@ else fi fi HOMEBREW_USER_AGENT="$HOMEBREW_PRODUCT/$HOMEBREW_USER_AGENT_VERSION ($HOMEBREW_SYSTEM; $HOMEBREW_PROCESSOR $HOMEBREW_OS_USER_AGENT_VERSION)" -HOMEBREW_CURL_VERSION="$("$HOMEBREW_CURL" --version 2>/dev/null | head -n1 | /usr/bin/awk '{print $1"/"$2}')" +HOMEBREW_CURL_VERSION="$("$HOMEBREW_CURL" --version 2>/dev/null | head -n1 | awk '{print $1"/"$2}')" HOMEBREW_USER_AGENT_CURL="$HOMEBREW_USER_AGENT $HOMEBREW_CURL_VERSION" # Declared in bin/brew diff --git a/Library/Homebrew/keg_relocate.rb b/Library/Homebrew/keg_relocate.rb index 71773db816..f70bbcbacd 100644 --- a/Library/Homebrew/keg_relocate.rb +++ b/Library/Homebrew/keg_relocate.rb @@ -96,7 +96,7 @@ class Keg alias generic_recursive_fgrep_args recursive_fgrep_args def each_unique_file_matching(string) - Utils.popen_read("/usr/bin/fgrep", recursive_fgrep_args, string, to_s) do |io| + Utils.popen_read("fgrep", recursive_fgrep_args, string, to_s) do |io| hardlinks = Set.new until io.eof? @@ -113,7 +113,7 @@ class Keg def text_files text_files = [] - return text_files unless File.exist?("/usr/bin/file") + return text_files unless which("file") && which("xargs") # file has known issues with reading files on other locales. Has # been fixed upstream for some time, but a sufficiently new enough @@ -132,7 +132,7 @@ class Keg end false } - output, _status = Open3.capture2("/usr/bin/xargs -0 /usr/bin/file --no-dereference --print0", + output, _status = Open3.capture2("xargs -0 file --no-dereference --print0", stdin_data: files.to_a.join("\0")) # `file` output sometimes contains data from the file, which may include # invalid UTF-8 entities, so tell Ruby this is just a bytestring diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 48ab94c4fb..b592b20649 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -344,7 +344,7 @@ def which_editor editor = %w[atom subl mate edit vim].find do |candidate| candidate if which(candidate, ENV["HOMEBREW_PATH"]) end - editor ||= "/usr/bin/vim" + editor ||= "vim" opoo <<~EOS Using #{editor} because no editor was set in the environment. diff --git a/Library/Homebrew/utils/curl.rb b/Library/Homebrew/utils/curl.rb index 84853047c3..cf17355760 100644 --- a/Library/Homebrew/utils/curl.rb +++ b/Library/Homebrew/utils/curl.rb @@ -3,7 +3,7 @@ require "open3" def curl_executable curl = Pathname.new ENV["HOMEBREW_CURL"] - curl = Pathname.new "/usr/bin/curl" unless curl.exist? + curl = which("curl") unless curl.exist? return curl if curl.executable? raise "#{curl} is not executable" end From ce85e3b3b57d29236a6ff1bcc7809f65e9e18867 Mon Sep 17 00:00:00 2001 From: Shaun Jackman Date: Tue, 12 Dec 2017 09:27:06 -0800 Subject: [PATCH 2/2] Remove with_system_path The method with_system_path is no longer needed, since environment filtering uses a default PATH. --- Library/Homebrew/download_strategy.rb | 18 ++++++++---------- Library/Homebrew/utils.rb | 8 +------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index f9a359450c..6c414b941a 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -217,12 +217,12 @@ class AbstractFileDownloadStrategy < AbstractDownloadStrategy def stage case type = cached_location.compression_type when :zip - with_system_path { quiet_safe_system "unzip", "-qq", cached_location } + quiet_safe_system "unzip", "-qq", cached_location chdir when :gzip_only - with_system_path { buffered_write("gunzip") } + buffered_write "gunzip" when :bzip2_only - with_system_path { buffered_write("bunzip2") } + buffered_write "bunzip2" when :gzip, :bzip2, :xz, :compress, :tar tar_flags = "x" if type == :gzip @@ -233,16 +233,14 @@ class AbstractFileDownloadStrategy < AbstractDownloadStrategy tar_flags << "J" end tar_flags << "f" - with_system_path do - if type == :xz && DependencyCollector.tar_needs_xz_dependency? - pipe_to_tar(xzpath) - else - safe_system "tar", tar_flags, cached_location - end + if type == :xz && DependencyCollector.tar_needs_xz_dependency? + pipe_to_tar xzpath + else + safe_system "tar", tar_flags, cached_location end chdir when :lzip - with_system_path { pipe_to_tar(lzippath) } + pipe_to_tar lzippath chdir when :lha safe_system lhapath, "x", cached_location diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index b592b20649..3ea472c588 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -267,12 +267,6 @@ module Homebrew # rubocop:enable Style/GlobalVars end -def with_system_path - with_env(PATH: PATH.new("/usr/bin", "/bin")) do - yield - end -end - def with_homebrew_path with_env(PATH: PATH.new(ENV["HOMEBREW_PATH"])) do yield @@ -376,7 +370,7 @@ end # GZips the given paths, and returns the gzipped paths def gzip(*paths) paths.collect do |path| - with_system_path { safe_system "gzip", path } + safe_system "gzip", path Pathname.new("#{path}.gz") end end