From 6e1c132f99166c716c991d687e4017167c2a37d0 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Tue, 18 Oct 2016 17:22:08 +0200 Subject: [PATCH] =?UTF-8?q?Remove=20Cask=E2=80=99s=20`which`=20method.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Library/Homebrew/cask/lib/hbc/cli.rb | 4 ++-- Library/Homebrew/cask/lib/hbc/utils.rb | 28 -------------------------- 2 files changed, 2 insertions(+), 30 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli.rb b/Library/Homebrew/cask/lib/hbc/cli.rb index ad8c02aabe..11f8cc7167 100644 --- a/Library/Homebrew/cask/lib/hbc/cli.rb +++ b/Library/Homebrew/cask/lib/hbc/cli.rb @@ -107,7 +107,7 @@ module Hbc if command.respond_to?(:run) # usual case: built-in command verb command.run(*rest) - elsif require? Utils.which("brewcask-#{command}.rb").to_s + elsif require? which("brewcask-#{command}.rb").to_s # external command as Ruby library on PATH, Homebrew-style elsif command.to_s.include?("/") && require?(command.to_s) # external command as Ruby library with literal path, useful @@ -124,7 +124,7 @@ module Hbc # other Ruby libraries must do everything via "require" klass.run(*rest) end - elsif Utils.which "brewcask-#{command}" + elsif which("brewcask-#{command}") # arbitrary external executable on PATH, Homebrew-style exec "brewcask-#{command}", *ARGV[1..-1] elsif Pathname.new(command.to_s).executable? && diff --git a/Library/Homebrew/cask/lib/hbc/utils.rb b/Library/Homebrew/cask/lib/hbc/utils.rb index c2c0916984..38fa23463f 100644 --- a/Library/Homebrew/cask/lib/hbc/utils.rb +++ b/Library/Homebrew/cask/lib/hbc/utils.rb @@ -38,34 +38,6 @@ end module Hbc module Utils - def self.which(cmd, path = ENV["PATH"]) - unless File.basename(cmd) == cmd.to_s - # cmd contains a directory element - cmd_pn = Pathname(cmd) - return nil unless cmd_pn.absolute? - return resolve_executable(cmd_pn) - end - path.split(File::PATH_SEPARATOR).each do |elt| - fq_cmd = Pathname(elt).expand_path.join(cmd) - resolved = resolve_executable fq_cmd - return resolved if resolved - end - nil - end - - def self.resolve_executable(cmd) - cmd_pn = Pathname(cmd) - return nil unless cmd_pn.exist? - return nil unless cmd_pn.executable? - begin - cmd_pn = Pathname(cmd_pn.realpath) - rescue RuntimeError - return nil - end - return nil unless cmd_pn.file? - cmd_pn - end - def self.gain_permissions_remove(path, command: SystemCommand) if path.respond_to?(:rmtree) && path.exist? gain_permissions(path, ["-R"], command, &:rmtree)