diff options
Diffstat (limited to 'Library/Homebrew/cask/lib')
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/artifact/abstract_uninstall.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/artifact/installer.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/audit.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/cask_loader.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/cli.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/cli/create.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/cli/edit.rb | 11 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/cli/internal_audit_modified_casks.rb | 4 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/cli/uninstall.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/container/air.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/container/dmg.rb | 24 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/dsl/caveats.rb | 78 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/exceptions.rb | 10 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/installer.rb | 4 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/system_command.rb | 73 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/utils.rb | 2 | ||||
| -rw-r--r-- | Library/Homebrew/cask/lib/hbc/version.rb | 2 |
17 files changed, 121 insertions, 103 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/artifact/abstract_uninstall.rb b/Library/Homebrew/cask/lib/hbc/artifact/abstract_uninstall.rb index 3f63dae8f..7505ac49a 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/abstract_uninstall.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/abstract_uninstall.rb @@ -253,7 +253,7 @@ module Hbc end def trash_paths(*paths, command: nil, **_) - result = command.run!("/usr/bin/osascript", args: ["-e", <<-'EOS'.undent, *paths]) + result = command.run!("/usr/bin/osascript", args: ["-e", <<~'EOS', *paths]) on run argv repeat with i from 1 to (count argv) set item i of argv to (item i of argv as POSIX file) diff --git a/Library/Homebrew/cask/lib/hbc/artifact/installer.rb b/Library/Homebrew/cask/lib/hbc/artifact/installer.rb index 588bcabd5..5cd388c7f 100644 --- a/Library/Homebrew/cask/lib/hbc/artifact/installer.rb +++ b/Library/Homebrew/cask/lib/hbc/artifact/installer.rb @@ -10,7 +10,7 @@ module Hbc module ManualInstaller def install_phase(**) - puts <<-EOS.undent + puts <<~EOS To complete the installation of Cask #{cask}, you must also run the installer at diff --git a/Library/Homebrew/cask/lib/hbc/audit.rb b/Library/Homebrew/cask/lib/hbc/audit.rb index bd25477ac..5180c5688 100644 --- a/Library/Homebrew/cask/lib/hbc/audit.rb +++ b/Library/Homebrew/cask/lib/hbc/audit.rb @@ -174,7 +174,7 @@ module Hbc add_warning "error retrieving appcast: #{result[:command_result].stderr}" else expected = cask.appcast.checkpoint - add_warning <<-EOS.undent unless expected == actual_checkpoint + add_warning <<~EOS unless expected == actual_checkpoint appcast checkpoint mismatch Expected: #{expected} Actual: #{actual_checkpoint} diff --git a/Library/Homebrew/cask/lib/hbc/cask_loader.rb b/Library/Homebrew/cask/lib/hbc/cask_loader.rb index 08d457643..c32b35584 100644 --- a/Library/Homebrew/cask/lib/hbc/cask_loader.rb +++ b/Library/Homebrew/cask/lib/hbc/cask_loader.rb @@ -190,7 +190,7 @@ module Hbc when 2..Float::INFINITY loaders = possible_tap_casks.map(&FromTapPathLoader.method(:new)) - raise CaskError, <<-EOS.undent + raise CaskError, <<~EOS Cask #{ref} exists in multiple taps: #{loaders.map { |loader| " #{loader.tap}/#{loader.token}" }.join("\n")} EOS diff --git a/Library/Homebrew/cask/lib/hbc/cli.rb b/Library/Homebrew/cask/lib/hbc/cli.rb index 92f0333ad..e147c8280 100644 --- a/Library/Homebrew/cask/lib/hbc/cli.rb +++ b/Library/Homebrew/cask/lib/hbc/cli.rb @@ -234,7 +234,7 @@ module Hbc end def purpose - puts <<-EOS.undent + puts <<~EOS brew-cask provides a friendly homebrew-style CLI workflow for the administration of macOS applications distributed as binaries. diff --git a/Library/Homebrew/cask/lib/hbc/cli/create.rb b/Library/Homebrew/cask/lib/hbc/cli/create.rb index 8de101092..e6ca3d7bc 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/create.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/create.rb @@ -21,7 +21,7 @@ module Hbc end def self.template(cask_token) - <<-EOS.undent + <<~EOS cask '#{cask_token}' do version '' sha256 '' diff --git a/Library/Homebrew/cask/lib/hbc/cli/edit.rb b/Library/Homebrew/cask/lib/hbc/cli/edit.rb index 8bce81c52..693edcd51 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/edit.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/edit.rb @@ -8,9 +8,6 @@ module Hbc end def run - cask = casks.first - cask_path = cask.sourcefile_path - odebug "Opening editor for Cask #{cask.token}" exec_editor cask_path rescue CaskUnavailableError => e reason = e.reason.empty? ? "" : "#{e.reason} " @@ -18,6 +15,14 @@ module Hbc raise e.class.new(e.token, reason) end + def cask_path + casks.first.sourcefile_path + rescue CaskInvalidError + path = CaskLoader.path(args.first) + return path if path.file? + raise + end + def self.help "edits the given Cask" end diff --git a/Library/Homebrew/cask/lib/hbc/cli/internal_audit_modified_casks.rb b/Library/Homebrew/cask/lib/hbc/cli/internal_audit_modified_casks.rb index b83224fb1..f06e2acc5 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/internal_audit_modified_casks.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/internal_audit_modified_casks.rb @@ -16,7 +16,7 @@ module Hbc super if args.count != 1 - raise ArgumentError, <<-EOS.undent + raise ArgumentError, <<~EOS This command requires exactly one argument. #{self.class.usage} @@ -31,7 +31,7 @@ module Hbc end def self.usage - <<-EOS.undent + <<~EOS Usage: brew cask _audit_modified_casks [options...] <commit range> Given a range of Git commits, find any Casks that were modified and run `brew diff --git a/Library/Homebrew/cask/lib/hbc/cli/uninstall.rb b/Library/Homebrew/cask/lib/hbc/cli/uninstall.rb index f2059605c..c962632bc 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/uninstall.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/uninstall.rb @@ -25,7 +25,7 @@ module Hbc single = versions.count == 1 - puts <<-EOS.undent + puts <<~EOS #{cask} #{versions.join(", ")} #{single ? "is" : "are"} still installed. Remove #{single ? "it" : "them all"} with `brew cask uninstall --force #{cask}`. EOS diff --git a/Library/Homebrew/cask/lib/hbc/container/air.rb b/Library/Homebrew/cask/lib/hbc/container/air.rb index 4b083e538..f2ebb6bcd 100644 --- a/Library/Homebrew/cask/lib/hbc/container/air.rb +++ b/Library/Homebrew/cask/lib/hbc/container/air.rb @@ -13,7 +13,7 @@ module Hbc def self.installer_cmd return @installer_cmd ||= INSTALLER_PATHNAME if installer_exist? - raise CaskError, <<-EOS.undent + raise CaskError, <<~EOS Adobe AIR runtime not present, try installing it via brew cask install adobe-air diff --git a/Library/Homebrew/cask/lib/hbc/container/dmg.rb b/Library/Homebrew/cask/lib/hbc/container/dmg.rb index 1d172a4b7..c0e43f68a 100644 --- a/Library/Homebrew/cask/lib/hbc/container/dmg.rb +++ b/Library/Homebrew/cask/lib/hbc/container/dmg.rb @@ -88,7 +88,7 @@ module Hbc bomfile.close Tempfile.open(["", ".list"]) do |filelist| - filelist.write(bom_filelist_from_path(mount)) + filelist.puts(bom_filelist_from_path(mount)) filelist.close @command.run!("/usr/bin/mkbom", args: ["-s", "-i", filelist.path, "--", bomfile.path]) @@ -98,16 +98,17 @@ module Hbc end def bom_filelist_from_path(mount) - Dir.chdir(mount) do - Dir.glob("**/*", File::FNM_DOTMATCH).map do |path| - next if skip_path?(Pathname(path)) - (path == ".") ? path : path.prepend("./") - end.compact.join("\n").concat("\n") - end + # We need to use `find` here instead of Ruby in order to properly handle + # file names containing special characters, such as โeโ + โยดโ vs. โรฉโ. + @command.run("/usr/bin/find", args: [".", "-print0"], chdir: mount, print_stderr: false).stdout + .split("\0") + .reject { |path| skip_path?(mount, path) } + .join("\n") end - def skip_path?(path) - dmg_metadata?(path) || system_dir_symlink?(path) + def skip_path?(mount, path) + path = Pathname(path.sub(%r{^\./}, "")) + dmg_metadata?(path) || system_dir_symlink?(mount, path) end # unnecessary DMG metadata @@ -130,9 +131,10 @@ module Hbc DMG_METADATA_FILES.include?(relative_root.basename.to_s) end - def system_dir_symlink?(path) + def system_dir_symlink?(mount, path) + full_path = Pathname(mount).join(path) # symlinks to system directories (commonly to /Applications) - path.symlink? && MacOS.system_dir?(path.readlink) + full_path.symlink? && MacOS.system_dir?(full_path.readlink) end def mounts_from_plist(plist) diff --git a/Library/Homebrew/cask/lib/hbc/dsl/caveats.rb b/Library/Homebrew/cask/lib/hbc/dsl/caveats.rb index 7d373b5f3..45ee5d160 100644 --- a/Library/Homebrew/cask/lib/hbc/dsl/caveats.rb +++ b/Library/Homebrew/cask/lib/hbc/dsl/caveats.rb @@ -9,22 +9,22 @@ module Hbc class DSL class Caveats < Base def path_environment_variable(path) - puts <<-EOS.undent - To use #{@cask}, you may need to add the #{path} directory - to your PATH environment variable, eg (for bash shell): + puts <<~EOS + To use #{@cask}, you may need to add the #{path} directory + to your PATH environment variable, eg (for bash shell): - export PATH=#{path}:"$PATH" + export PATH=#{path}:"$PATH" EOS end def zsh_path_helper(path) - puts <<-EOS.undent - To use #{@cask}, zsh users may need to add the following line to their - ~/.zprofile. (Among other effects, #{path} will be added to the - PATH environment variable): + puts <<~EOS + To use #{@cask}, zsh users may need to add the following line to their + ~/.zprofile. (Among other effects, #{path} will be added to the + PATH environment variable): - eval `/usr/libexec/path_helper -s` + eval `/usr/libexec/path_helper -s` EOS end @@ -32,7 +32,7 @@ module Hbc def files_in_usr_local localpath = "/usr/local" return unless HOMEBREW_PREFIX.to_s.downcase.start_with?(localpath) - puts <<-EOS.undent + puts <<~EOS Cask #{@cask} installs files under "#{localpath}". The presence of such files can cause warnings when running "brew doctor", which is considered to be a bug in Homebrew-Cask. @@ -42,72 +42,72 @@ module Hbc def depends_on_java(java_version = "any") if java_version == "any" - puts <<-EOS.undent - #{@cask} requires Java. You can install the latest version with + puts <<~EOS + #{@cask} requires Java. You can install the latest version with - brew cask install java + brew cask install java EOS elsif java_version.include?("9") || java_version.include?("+") - puts <<-EOS.undent - #{@cask} requires Java #{java_version}. You can install the latest version with + puts <<~EOS + #{@cask} requires Java #{java_version}. You can install the latest version with - brew cask install java + brew cask install java EOS else - puts <<-EOS.undent - #{@cask} requires Java #{java_version}. You can install it with + puts <<~EOS + #{@cask} requires Java #{java_version}. You can install it with - brew cask install caskroom/versions/java#{java_version} + brew cask install caskroom/versions/java#{java_version} EOS end end def logout - puts <<-EOS.undent - You must log out and log back in for the installation of #{@cask} - to take effect. + puts <<~EOS + You must log out and log back in for the installation of #{@cask} + to take effect. EOS end def reboot - puts <<-EOS.undent - You must reboot for the installation of #{@cask} to take effect. + puts <<~EOS + You must reboot for the installation of #{@cask} to take effect. EOS end def discontinued - puts <<-EOS.undent - #{@cask} has been officially discontinued upstream. - It may stop working correctly (or at all) in recent versions of macOS. + puts <<~EOS + #{@cask} has been officially discontinued upstream. + It may stop working correctly (or at all) in recent versions of macOS. EOS end def free_license(web_page) - puts <<-EOS.undent - The vendor offers a free license for #{@cask} at - #{web_page} + puts <<~EOS + The vendor offers a free license for #{@cask} at + #{web_page} EOS end def malware(radar_number) - puts <<-EOS.undent - #{@cask} has been reported to bundle malware. Like with any app, use at your own risk. + puts <<~EOS + #{@cask} has been reported to bundle malware. Like with any app, use at your own risk. - A report has been made to Apple about this app. Their certificate will hopefully be revoked. - See the public report at - #{Formatter.url("https://openradar.appspot.com/#{radar_number}")} + A report has been made to Apple about this app. Their certificate will hopefully be revoked. + See the public report at + #{Formatter.url("https://openradar.appspot.com/#{radar_number}")} - If this report is accurate, please duplicate it at - #{Formatter.url("https://bugreport.apple.com/")} - If this report is a mistake, please let us know by opening an issue at - #{Formatter.url("https://github.com/caskroom/homebrew-cask/issues/new")} + If this report is accurate, please duplicate it at + #{Formatter.url("https://bugreport.apple.com/")} + If this report is a mistake, please let us know by opening an issue at + #{Formatter.url("https://github.com/caskroom/homebrew-cask/issues/new")} EOS end diff --git a/Library/Homebrew/cask/lib/hbc/exceptions.rb b/Library/Homebrew/cask/lib/hbc/exceptions.rb index f7f9e43b6..2626a467a 100644 --- a/Library/Homebrew/cask/lib/hbc/exceptions.rb +++ b/Library/Homebrew/cask/lib/hbc/exceptions.rb @@ -44,7 +44,7 @@ module Hbc class CaskAlreadyInstalledError < AbstractCaskErrorWithToken def to_s - <<-EOS.undent + <<~EOS Cask '#{token}' is already installed. To re-install #{token}, run: @@ -80,7 +80,7 @@ module Hbc class CaskX11DependencyError < AbstractCaskErrorWithToken def to_s - <<-EOS.undent + <<~EOS Cask '#{token}' requires XQuartz/X11, which can be installed using Homebrew-Cask by running #{Formatter.identifier("brew cask install xquartz")} @@ -132,7 +132,7 @@ module Hbc class CaskSha256MissingError < CaskSha256Error def to_s - <<-EOS.undent + <<~EOS Cask '#{token}' requires a checksum: #{Formatter.identifier("sha256 '#{actual}'")} EOS @@ -148,7 +148,7 @@ module Hbc end def to_s - <<-EOS.undent + <<~EOS Checksum for Cask '#{token}' does not match. Expected: #{Formatter.success(expected.to_s)} @@ -162,7 +162,7 @@ module Hbc class CaskNoShasumError < CaskSha256Error def to_s - <<-EOS.undent + <<~EOS Cask '#{token}' does not have a sha256 checksum defined and was not installed. This means you have the #{Formatter.identifier("--require-sha")} option set, perhaps in your HOMEBREW_CASK_OPTS. EOS diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb index 68b9595e1..1063f488b 100644 --- a/Library/Homebrew/cask/lib/hbc/installer.rb +++ b/Library/Homebrew/cask/lib/hbc/installer.rb @@ -326,7 +326,7 @@ module Hbc ], sudo: true) else - opoo <<-EOS.undent + opoo <<~EOS Accessibility access cannot be enabled automatically on this version of macOS. See System Preferences to enable it manually. EOS @@ -347,7 +347,7 @@ module Hbc ], sudo: true) else - opoo <<-EOS.undent + opoo <<~EOS Accessibility access cannot be disabled automatically on this version of macOS. See System Preferences to disable it manually. EOS diff --git a/Library/Homebrew/cask/lib/hbc/system_command.rb b/Library/Homebrew/cask/lib/hbc/system_command.rb index be083c29e..3c8311a3b 100644 --- a/Library/Homebrew/cask/lib/hbc/system_command.rb +++ b/Library/Homebrew/cask/lib/hbc/system_command.rb @@ -8,14 +8,14 @@ require "hbc/utils/hash_validator" module Hbc class SystemCommand - attr_reader :command + extend Predicable - def self.run(executable, options = {}) - new(executable, options).run! + def self.run(executable, **options) + new(executable, **options).run! end - def self.run!(command, options = {}) - run(command, options.merge(must_succeed: true)) + def self.run!(command, **options) + run(command, **options, must_succeed: true) end def run! @@ -26,38 +26,49 @@ module Hbc case type when :stdout processed_output[:stdout] << line - ohai line.chomp if options[:print_stdout] + ohai line.chomp if print_stdout? when :stderr processed_output[:stderr] << line - ohai line.chomp if options[:print_stderr] + ohai line.chomp if print_stderr? end end - assert_success if options[:must_succeed] + assert_success if must_succeed? result end - def initialize(executable, options) + def initialize(executable, args: [], sudo: false, input: [], print_stdout: false, print_stderr: true, must_succeed: false, **options) + executable, *args = Shellwords.shellescape(executable) if args.empty? + @executable = executable + @args = args + @sudo = sudo + @input = input + @print_stdout = print_stdout + @print_stderr = print_stderr + @must_succeed = must_succeed + options.extend(HashValidator).assert_valid_keys(:chdir) @options = options - process_options! + end + + def command + @command ||= [ + *sudo_prefix, + executable, + *args, + ].freeze end private - attr_reader :executable, :options, :processed_output, :processed_status - - def process_options! - options.extend(HashValidator) - .assert_valid_keys :input, :print_stdout, :print_stderr, :args, :must_succeed, :sudo - sudo_prefix = %w[/usr/bin/sudo -E --] - sudo_prefix = sudo_prefix.insert(1, "-A") unless ENV["SUDO_ASKPASS"].nil? - @command = [executable] - options[:print_stderr] = true unless options.key?(:print_stderr) - @command.unshift(*sudo_prefix) if options[:sudo] - @command.concat(options[:args]) if options.key?(:args) && !options[:args].empty? - @command[0] = Shellwords.shellescape(@command[0]) if @command.size == 1 - nil + attr_reader :executable, :args, :input, :options, :processed_output, :processed_status + + attr_predicate :sudo?, :print_stdout?, :print_stderr?, :must_succeed? + + def sudo_prefix + return [] unless sudo? + askpass_flags = ENV.key?("SUDO_ASKPASS") ? ["-A"] : [] + ["/usr/bin/sudo", *askpass_flags, "-E", "--"] end def assert_success @@ -77,7 +88,7 @@ module Hbc def each_output_line(&b) raw_stdin, raw_stdout, raw_stderr, raw_wait_thr = - Open3.popen3(*expanded_command) + Open3.popen3(*expanded_command, **options) write_input_to(raw_stdin) raw_stdin.close_write @@ -87,7 +98,7 @@ module Hbc end def write_input_to(raw_stdin) - [*options[:input]].each { |line| raw_stdin.print line } + [*input].each(&raw_stdin.method(:print)) end def each_line_from(sources) @@ -155,12 +166,12 @@ module Hbc _warn_plist_garbage(command, Regexp.last_match[2]) xml = Plist.parse_xml(output) unless xml.respond_to?(:keys) && !xml.keys.empty? - raise CaskError, <<-EOS - Empty result parsing plist output from command. - command was: - #{command} - output we attempted to parse: - #{output} + raise CaskError, <<~EOS + Empty result parsing plist output from command. + command was: + #{command} + output we attempted to parse: + #{output} EOS end xml diff --git a/Library/Homebrew/cask/lib/hbc/utils.rb b/Library/Homebrew/cask/lib/hbc/utils.rb index 22f826e74..0f44c0157 100644 --- a/Library/Homebrew/cask/lib/hbc/utils.rb +++ b/Library/Homebrew/cask/lib/hbc/utils.rb @@ -90,7 +90,7 @@ module Hbc end def self.error_message_with_suggestions - <<-EOS.undent + <<~EOS Follow the instructions here: #{Formatter.url(BUG_REPORTS_URL)} EOS diff --git a/Library/Homebrew/cask/lib/hbc/version.rb b/Library/Homebrew/cask/lib/hbc/version.rb index 2eb942b95..c7ce8e2d8 100644 --- a/Library/Homebrew/cask/lib/hbc/version.rb +++ b/Library/Homebrew/cask/lib/hbc/version.rb @@ -1,7 +1,7 @@ module Hbc def self.full_version @full_version ||= begin - <<-EOS.undent + <<~EOS Homebrew-Cask #{HOMEBREW_VERSION} caskroom/homebrew-cask #{Hbc.default_tap.version_string} EOS |
