Merge pull request #5942 from MikeMcQuaid/system-not-exec

*cmd/*: use *system instead of exec for easier testing.
This commit is contained in:
Mike McQuaid 2019-03-28 08:30:58 +00:00 committed by GitHub
commit 9dba22f950
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 14 additions and 18 deletions

View File

@ -23,6 +23,6 @@ module Homebrew
raise "`brew cat` doesn't support multiple arguments" if args.remaining.size > 1 raise "`brew cat` doesn't support multiple arguments" if args.remaining.size > 1
cd HOMEBREW_REPOSITORY cd HOMEBREW_REPOSITORY
exec "cat", formulae.first.path, *ARGV.options_only safe_system "cat", formulae.first.path, *ARGV.options_only
end end
end end

View File

@ -46,8 +46,7 @@ module Homebrew
def list def list
list_args.parse list_args.parse
# Use of exec means we don't explicitly exit return list_unbrewed if args.unbrewed?
list_unbrewed if args.unbrewed?
# Unbrewed uses the PREFIX, which will exist # Unbrewed uses the PREFIX, which will exist
# Things below use the CELLAR, which doesn't until the first formula is installed. # Things below use the CELLAR, which doesn't until the first formula is installed.
@ -67,10 +66,10 @@ module Homebrew
puts Formatter.columns(full_names) puts Formatter.columns(full_names)
else else
ENV["CLICOLOR"] = nil ENV["CLICOLOR"] = nil
exec "ls", *ARGV.options_only << HOMEBREW_CELLAR safe_system "ls", *ARGV.options_only << HOMEBREW_CELLAR
end end
elsif args.verbose? || !$stdout.tty? elsif args.verbose? || !$stdout.tty?
exec "find", *ARGV.kegs.map(&:to_s) + %w[-not -type d -print] safe_system "find", *ARGV.kegs.map(&:to_s) + %w[-not -type d -print]
else else
ARGV.kegs.each { |keg| PrettyListing.new keg } ARGV.kegs.each { |keg| PrettyListing.new keg }
end end
@ -116,7 +115,7 @@ module Homebrew
arguments.concat %w[)] arguments.concat %w[)]
cd HOMEBREW_PREFIX cd HOMEBREW_PREFIX
exec "find", *arguments safe_system "find", *arguments
end end
def filtered_list def filtered_list

View File

@ -56,6 +56,6 @@ module Homebrew
end end
args = ARGV.options_only args = ARGV.options_only
args += ["--follow", "--", path] unless path.nil? args += ["--follow", "--", path] unless path.nil?
exec "git", "log", *args system "git", "log", *args
end end
end end

View File

@ -51,6 +51,6 @@ module Homebrew
When done, type `exit'. When done, type `exit'.
EOS EOS
$stdout.flush $stdout.flush
exec ENV["SHELL"] safe_system ENV["SHELL"]
end end
end end

View File

@ -19,6 +19,6 @@ module Homebrew
Homebrew.install_gem_setup_path! "ruby-prof" Homebrew.install_gem_setup_path! "ruby-prof"
FileUtils.mkdir_p "prof" FileUtils.mkdir_p "prof"
brew_rb = (HOMEBREW_LIBRARY_PATH/"brew.rb").resolved_path brew_rb = (HOMEBREW_LIBRARY_PATH/"brew.rb").resolved_path
exec "ruby-prof", "--printer=multi", "--file=prof", brew_rb, "--", *ARGV safe_system "ruby-prof", "--printer=multi", "--file=prof", brew_rb, "--", *ARGV
end end
end end

View File

@ -21,6 +21,9 @@ module Homebrew
def ruby def ruby
ruby_args.parse ruby_args.parse
exec ENV["HOMEBREW_RUBY_PATH"], "-I", $LOAD_PATH.join(File::PATH_SEPARATOR), "-rglobal", "-rdev-cmd/irb", *ARGV safe_system ENV["HOMEBREW_RUBY_PATH"],
"-I", $LOAD_PATH.join(File::PATH_SEPARATOR),
"-rglobal", "-rdev-cmd/irb",
*ARGV
end end
end end

View File

@ -321,7 +321,7 @@ end
def exec_editor(*args) def exec_editor(*args)
puts "Editing #{args.join "\n"}" puts "Editing #{args.join "\n"}"
with_homebrew_path { safe_exec(which_editor, *args) } with_homebrew_path { safe_system(which_editor, *args) }
end end
def exec_browser(*args) def exec_browser(*args)
@ -331,13 +331,7 @@ def exec_browser(*args)
ENV["DISPLAY"] = ENV["HOMEBREW_DISPLAY"] ENV["DISPLAY"] = ENV["HOMEBREW_DISPLAY"]
safe_exec(browser, *args) safe_system(browser, *args)
end
def safe_exec(cmd, *args)
# This buys us proper argument quoting and evaluation
# of environment variables in the cmd parameter.
exec "/bin/sh", "-c", "#{cmd} \"$@\"", "--", *args
end end
# GZips the given paths, and returns the gzipped paths # GZips the given paths, and returns the gzipped paths