Module: Cask::Staged Private

Extended by:
T::Helpers
Includes:
Utils::Output::Mixin
Included in:
DSL::Postflight, DSL::Preflight, DSL::UninstallPreflight
Defined in:
cask/staged.rb

Overview

This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.

Helper functions for staged casks.

Constant Summary collapse

Paths =

This constant is part of a private API. This constant may only be used in the Homebrew/brew repository. Third parties should avoid using this constant if possible, as it may be removed or changed without warning.

T.type_alias { T.any(String, Pathname, T::Array[T.any(String, Pathname)]) }

Instance Method Summary collapse

Methods included from Utils::Output::Mixin

#issue_reporting_message, #odebug, #odeprecated, #odie, #odisabled, #ofail, #oh1, #oh1_title, #ohai, #ohai_title, #onoe, #opoo, #opoo_outside_github_actions, #opoo_without_github_actions_annotation, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning

Instance Method Details

#set_ownership(paths, user: T.must(User.current), group: "staff") ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:

  • paths (Paths)
  • user (String, User) (defaults to: T.must(User.current))
  • group (String) (defaults to: "staff")


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'cask/staged.rb', line 28

def set_ownership(paths, user: T.must(User.current), group: "staff")
  full_paths = remove_nonexistent(paths)
  return if full_paths.empty?

  # On macOS Ventura or later, modifying the contents of an app bundle
  # requires App Management permissions, even when using `sudo`. Without
  # them, every `chown` fails with `Operation not permitted`, so check
  # upfront: this triggers the system permission prompt (which a plain
  # `chown` does not) and allows giving the user an actionable error
  # message instead of a wall of `chown` errors.
  full_paths.each do |path|
    next if Quarantine.app_management_permissions_granted?(app: path, command:)

    raise CaskError, <<~EOS
      Cannot change the ownership of '#{path}' because your terminal does not have App Management permissions.
      macOS prevents modifying apps without these permissions, even when using `sudo`.
      To fix this, approve the permissions prompt (if one was just shown) or go to
      System Settings → Privacy & Security → App Management and add or enable your terminal.
      Then run this command again.
    EOS
  end

  ohai "Changing ownership of paths required by #{cask} with `sudo` (which may request your password)..."
  command.run!("chown", args: ["-R", "--", "#{user}:#{group}", *full_paths],
                        sudo: true)
end

#set_permissions(paths, permissions_str) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:



19
20
21
22
23
24
25
# File 'cask/staged.rb', line 19

def set_permissions(paths, permissions_str)
  full_paths = remove_nonexistent(paths)
  return if full_paths.empty?

  command.run!("chmod", args: ["-R", "--", permissions_str, *full_paths],
                        sudo: false)
end