aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/cask/lib
diff options
context:
space:
mode:
authorMarkus Reiter2016-10-19 00:11:50 +0200
committerGitHub2016-10-19 00:11:50 +0200
commit63122c241ce5c46e8201fe55773632e11e7eb187 (patch)
tree001a7e56e82c0afd3fee053be09782774b48ebbf /Library/Homebrew/cask/lib
parent9f76e2bbe316d7e8700d0811fcc097172d5e0c9b (diff)
parent6e1c132f99166c716c991d687e4017167c2a37d0 (diff)
downloadbrew-63122c241ce5c46e8201fe55773632e11e7eb187.tar.bz2
Merge pull request #1319 from reitermarkus/refactor-containers
Look for container extraction programs in PATH.
Diffstat (limited to 'Library/Homebrew/cask/lib')
-rw-r--r--Library/Homebrew/cask/lib/hbc/cli.rb4
-rw-r--r--Library/Homebrew/cask/lib/hbc/container/cab.rb8
-rw-r--r--Library/Homebrew/cask/lib/hbc/container/generic_unar.rb4
-rw-r--r--Library/Homebrew/cask/lib/hbc/container/lzma.rb4
-rw-r--r--Library/Homebrew/cask/lib/hbc/container/xz.rb4
-rw-r--r--Library/Homebrew/cask/lib/hbc/utils.rb28
6 files changed, 8 insertions, 44 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/cli.rb b/Library/Homebrew/cask/lib/hbc/cli.rb
index ad8c02aab..11f8cc716 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/container/cab.rb b/Library/Homebrew/cask/lib/hbc/container/cab.rb
index d32b1b205..7ae6b0632 100644
--- a/Library/Homebrew/cask/lib/hbc/container/cab.rb
+++ b/Library/Homebrew/cask/lib/hbc/container/cab.rb
@@ -6,17 +6,15 @@ module Hbc
class Container
class Cab < Base
def self.me?(criteria)
- cabextract = Hbc.homebrew_prefix.join("bin", "cabextract")
+ cabextract = which("cabextract")
criteria.magic_number(%r{^MSCF}n) &&
- cabextract.exist? &&
+ !cabextract.nil? &&
criteria.command.run(cabextract, args: ["-t", "--", criteria.path.to_s]).stderr.empty?
end
def extract
- cabextract = Hbc.homebrew_prefix.join("bin", "cabextract")
-
- unless cabextract.exist?
+ if (cabextract = which("cabextract")).nil?
raise CaskError, "Expected to find cabextract executable. Cask '#{@cask}' must add: depends_on formula: 'cabextract'"
end
diff --git a/Library/Homebrew/cask/lib/hbc/container/generic_unar.rb b/Library/Homebrew/cask/lib/hbc/container/generic_unar.rb
index 32bbc8d15..5fa0dbdce 100644
--- a/Library/Homebrew/cask/lib/hbc/container/generic_unar.rb
+++ b/Library/Homebrew/cask/lib/hbc/container/generic_unar.rb
@@ -14,9 +14,7 @@ module Hbc
end
def extract
- unar = Hbc.homebrew_prefix.join("bin", "unar")
-
- unless unar.exist?
+ if (unar = which("unar")).nil?
raise CaskError, "Expected to find unar executable. Cask #{@cask} must add: depends_on formula: 'unar'"
end
diff --git a/Library/Homebrew/cask/lib/hbc/container/lzma.rb b/Library/Homebrew/cask/lib/hbc/container/lzma.rb
index a91132b55..cca4d814b 100644
--- a/Library/Homebrew/cask/lib/hbc/container/lzma.rb
+++ b/Library/Homebrew/cask/lib/hbc/container/lzma.rb
@@ -10,9 +10,7 @@ module Hbc
end
def extract
- unlzma = Hbc.homebrew_prefix.join("bin", "unlzma")
-
- unless unlzma.exist?
+ if (unlzma = which("unlzma")).nil?
raise CaskError, "Expected to find unlzma executable. Cask '#{@cask}' must add: depends_on formula: 'lzma'"
end
diff --git a/Library/Homebrew/cask/lib/hbc/container/xz.rb b/Library/Homebrew/cask/lib/hbc/container/xz.rb
index 831bef5aa..fc0ae064e 100644
--- a/Library/Homebrew/cask/lib/hbc/container/xz.rb
+++ b/Library/Homebrew/cask/lib/hbc/container/xz.rb
@@ -10,9 +10,7 @@ module Hbc
end
def extract
- unxz = Hbc.homebrew_prefix.join("bin", "unxz")
-
- unless unxz.exist?
+ if (unxz = which("unxz")).nil?
raise CaskError, "Expected to find unxz executable. Cask '#{@cask}' must add: depends_on formula: 'xz'"
end
diff --git a/Library/Homebrew/cask/lib/hbc/utils.rb b/Library/Homebrew/cask/lib/hbc/utils.rb
index c2c091698..38fa23463 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)