Module: Cask::Utils Private
- Defined in:
- Library/Homebrew/cask/utils.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Helper functions for various cask operations.
Class Method Summary collapse
- .error_message_with_suggestions ⇒ Object private
- .gain_permissions(path, command_args, command) ⇒ Object private
- .gain_permissions_remove(path, command: SystemCommand) ⇒ Object private
- .method_missing_message(method, token, section = nil) ⇒ Object private
- .path_occupied?(path) ⇒ Boolean private
Class Method Details
.error_message_with_suggestions ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
79 80 81 82 83 84 |
# File 'Library/Homebrew/cask/utils.rb', line 79 def self. <<~EOS Follow the instructions here: #{Formatter.url(BUG_REPORTS_URL)} EOS end |
.gain_permissions(path, command_args, command) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'Library/Homebrew/cask/utils.rb', line 32 def self.(path, command_args, command) = false tried_ownership = false begin yield path rescue # in case of permissions problems unless # TODO: Better handling for the case where path is a symlink. # The -h and -R flags cannot be combined, and behavior is # dependent on whether the file argument has a trailing # slash. This should do the right thing, but is fragile. command.run("/usr/bin/chflags", must_succeed: false, args: command_args + ["--", "000", path]) command.run("/bin/chmod", must_succeed: false, args: command_args + ["--", "u+rwx", path]) command.run("/bin/chmod", must_succeed: false, args: command_args + ["-N", path]) = true retry # rmtree end unless tried_ownership # in case of ownership problems # TODO: Further examine files to see if ownership is the problem # before using sudo+chown ohai "Using sudo to gain ownership of path '#{path}'" command.run("/usr/sbin/chown", args: command_args + ["--", User.current, path], sudo: true) tried_ownership = true # retry chflags/chmod after chown = false retry # rmtree end raise end end |
.gain_permissions_remove(path, command: SystemCommand) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'Library/Homebrew/cask/utils.rb', line 16 def self.(path, command: SystemCommand) if path.respond_to?(:rmtree) && path.exist? (path, ["-R"], command) do |p| if p.parent.writable? p.rmtree else command.run("/bin/rm", args: ["-r", "-f", "--", p], sudo: true) end end elsif File.symlink?(path) (path, ["-h"], command, &FileUtils.method(:rm_f)) end end |
.method_missing_message(method, token, section = nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
86 87 88 89 90 91 92 |
# File 'Library/Homebrew/cask/utils.rb', line 86 def self.(method, token, section = nil) = +"Unexpected method '#{method}' called " << "during #{section} " if section << "on Cask #{token}." opoo "#{}\n#{}" end |
.path_occupied?(path) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
75 76 77 |
# File 'Library/Homebrew/cask/utils.rb', line 75 def self.path_occupied?(path) File.exist?(path) || File.symlink?(path) end |