From 76c64f9bbf54c9f3b6915469f170d1f8c02be208 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 1 Dec 2017 22:07:21 +0100 Subject: [PATCH 1/3] =?UTF-8?q?Fix=20SystemCommand=20escaping=20=E2=80=A6?= =?UTF-8?q?=20again.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Library/Homebrew/cask/lib/hbc/system_command.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/system_command.rb b/Library/Homebrew/cask/lib/hbc/system_command.rb index f64d85c075..86e4d2268c 100644 --- a/Library/Homebrew/cask/lib/hbc/system_command.rb +++ b/Library/Homebrew/cask/lib/hbc/system_command.rb @@ -50,11 +50,7 @@ module Hbc end def command - @command ||= if sudo? - [*sudo_prefix, executable, *args] - else - [Shellwords.shellescape(executable), *args] - end + [*sudo_prefix, executable, *args] end private @@ -85,8 +81,10 @@ module Hbc end def each_output_line(&b) + executable, *args = expanded_command + raw_stdin, raw_stdout, raw_stderr, raw_wait_thr = - Open3.popen3(*expanded_command, **options) + Open3.popen3([executable, executable], *args, **options) write_input_to(raw_stdin) raw_stdin.close_write From 96733bcb2e6836c55bb2e3fea4324c5f38061355 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Fri, 1 Dec 2017 23:59:04 +0100 Subject: [PATCH 2/3] Support environment filtering in Casks. --- Library/Homebrew/cask/lib/hbc/cli.rb | 2 +- Library/Homebrew/cask/lib/hbc/container/cab.rb | 2 +- .../cask/lib/hbc/container/generic_unar.rb | 10 +++++----- Library/Homebrew/cask/lib/hbc/container/gpg.rb | 2 +- .../Homebrew/cask/lib/hbc/container/lzma.rb | 2 +- Library/Homebrew/cask/lib/hbc/container/xz.rb | 2 +- .../Homebrew/cask/lib/hbc/system_command.rb | 4 ++++ Library/Homebrew/compat/hbc.rb | 1 - Library/Homebrew/compat/hbc/system_command.rb | 18 ------------------ 9 files changed, 14 insertions(+), 29 deletions(-) delete mode 100644 Library/Homebrew/compat/hbc/system_command.rb diff --git a/Library/Homebrew/cask/lib/hbc/cli.rb b/Library/Homebrew/cask/lib/hbc/cli.rb index e2deb6f671..7197303a8f 100644 --- a/Library/Homebrew/cask/lib/hbc/cli.rb +++ b/Library/Homebrew/cask/lib/hbc/cli.rb @@ -96,7 +96,7 @@ module Hbc if command.respond_to?(:run) # usual case: built-in command verb command.run(*args) - elsif require?(which("brewcask-#{command}.rb")) + elsif require?(which("brewcask-#{command}.rb"), ENV["HOMEBREW_PATH"]) # 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 diff --git a/Library/Homebrew/cask/lib/hbc/container/cab.rb b/Library/Homebrew/cask/lib/hbc/container/cab.rb index 010fccbc40..327aece6ea 100644 --- a/Library/Homebrew/cask/lib/hbc/container/cab.rb +++ b/Library/Homebrew/cask/lib/hbc/container/cab.rb @@ -10,7 +10,7 @@ module Hbc end def extract - if (cabextract = which("cabextract")).nil? + unless cabextract = which("cabextract", PATH.new(ENV["PATH"], HOMEBREW_PREFIX/"bin")) 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 7a465e12e0..63ab917ea2 100644 --- a/Library/Homebrew/cask/lib/hbc/container/generic_unar.rb +++ b/Library/Homebrew/cask/lib/hbc/container/generic_unar.rb @@ -6,14 +6,14 @@ module Hbc class Container class GenericUnar < Base def self.me?(criteria) - !(lsar = which("lsar")).nil? && - criteria.command.run(lsar, - args: ["-l", "-t", "--", criteria.path], - print_stderr: false).stdout.chomp.end_with?("passed, 0 failed.") + return false unless lsar = which("lsar", PATH.new(ENV["PATH"], HOMEBREW_PREFIX/"bin")) + criteria.command.run(lsar, + args: ["-l", "-t", "--", criteria.path], + print_stderr: false).stdout.chomp.end_with?("passed, 0 failed.") end def extract - if (unar = which("unar")).nil? + unless unar = which("unar", PATH.new(ENV["PATH"], HOMEBREW_PREFIX/"bin")) 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/gpg.rb b/Library/Homebrew/cask/lib/hbc/container/gpg.rb index 3f37b5aa66..09c75468ac 100644 --- a/Library/Homebrew/cask/lib/hbc/container/gpg.rb +++ b/Library/Homebrew/cask/lib/hbc/container/gpg.rb @@ -24,7 +24,7 @@ module Hbc end def extract - if (gpg = which("gpg")).nil? + unless gpg = which("gpg", PATH.new(ENV["PATH"], HOMEBREW_PREFIX/"bin")) raise CaskError, "Expected to find gpg executable. Cask '#{@cask}' must add: depends_on formula: 'gpg'" end diff --git a/Library/Homebrew/cask/lib/hbc/container/lzma.rb b/Library/Homebrew/cask/lib/hbc/container/lzma.rb index 1221acfbc0..1e165ba2a7 100644 --- a/Library/Homebrew/cask/lib/hbc/container/lzma.rb +++ b/Library/Homebrew/cask/lib/hbc/container/lzma.rb @@ -10,7 +10,7 @@ module Hbc end def extract - if (unlzma = which("unlzma")).nil? + unless unlzma = which("unlzma", PATH.new(ENV["PATH"], HOMEBREW_PREFIX/"bin")) 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 cd9f9aee2f..4086ae1886 100644 --- a/Library/Homebrew/cask/lib/hbc/container/xz.rb +++ b/Library/Homebrew/cask/lib/hbc/container/xz.rb @@ -10,7 +10,7 @@ module Hbc end def extract - if (unxz = which("unxz")).nil? + unless unxz = which("unxz", PATH.new(ENV["PATH"], HOMEBREW_PREFIX/"bin")) raise CaskError, "Expected to find unxz executable. Cask '#{@cask}' must add: depends_on formula: 'xz'" end diff --git a/Library/Homebrew/cask/lib/hbc/system_command.rb b/Library/Homebrew/cask/lib/hbc/system_command.rb index 86e4d2268c..a890c42e41 100644 --- a/Library/Homebrew/cask/lib/hbc/system_command.rb +++ b/Library/Homebrew/cask/lib/hbc/system_command.rb @@ -83,6 +83,10 @@ module Hbc def each_output_line(&b) executable, *args = expanded_command + unless File.exist?(executable) + executable = which(executable, PATH.new(ENV["PATH"], HOMEBREW_PREFIX/"bin")) + end + raw_stdin, raw_stdout, raw_stderr, raw_wait_thr = Open3.popen3([executable, executable], *args, **options) diff --git a/Library/Homebrew/compat/hbc.rb b/Library/Homebrew/compat/hbc.rb index ebf8a9874f..608d46e376 100644 --- a/Library/Homebrew/compat/hbc.rb +++ b/Library/Homebrew/compat/hbc.rb @@ -4,7 +4,6 @@ require "compat/hbc/cache" require "compat/hbc/caskroom" require "compat/hbc/cli" require "compat/hbc/dsl" -require "compat/hbc/system_command" module Hbc class << self diff --git a/Library/Homebrew/compat/hbc/system_command.rb b/Library/Homebrew/compat/hbc/system_command.rb deleted file mode 100644 index bb9187db37..0000000000 --- a/Library/Homebrew/compat/hbc/system_command.rb +++ /dev/null @@ -1,18 +0,0 @@ -require "shellwords" - -module SystemCommandCompatibilityLayer - def initialize(executable, args: [], **options) - if args.empty? && !File.exist?(executable) - odeprecated "`system_command` with a shell string", "`system_command` with the `args` parameter" - executable, *args = Shellwords.shellsplit(executable) - end - - super(executable, args: args, **options) - end -end - -module Hbc - class SystemCommand - prepend SystemCommandCompatibilityLayer - end -end From 36c0dbfe13d6185d34a35a1a386d95a3a4046a30 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sat, 2 Dec 2017 00:12:21 +0100 Subject: [PATCH 3/3] Simplify `PATH` usage in `Formula`. --- Library/Homebrew/formula.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 4ac66ffc45..f3b6c1db12 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -1622,7 +1622,7 @@ class Formula TEMP: HOMEBREW_TEMP, TMP: HOMEBREW_TEMP, TERM: "dumb", - PATH: PATH.new(ENV["PATH"]).append(HOMEBREW_PREFIX/"bin"), + PATH: PATH.new(ENV["PATH"], HOMEBREW_PREFIX/"bin"), HOMEBREW_PATH: nil, _JAVA_OPTIONS: "#{ENV["_JAVA_OPTIONS"]} -Duser.home=#{HOMEBREW_CACHE}/java_cache", }