Module: OS::Mac::Cask::Quarantine::ClassMethods Private

Extended by:
T::Helpers
Includes:
Kernel, Utils::Output::Mixin
Defined in:
extend/os/mac/cask/quarantine.rb

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.

Constant Summary

Constants included from Kernel

Kernel::IGNORE_INTERRUPTS_MUTEX

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

Methods included from Kernel

#ensure_executable!, #exec_browser, #exec_editor, #ignore_interrupts, #interactive_shell, #quiet_system, #redirect_stdout, #safe_system, #which, #which_editor, #with_env, #with_homebrew_path

Instance Method Details

#cask!(cask: nil, download_path: nil, action: true) ⇒ 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:

  • cask (::Cask::Cask, nil) (defaults to: nil)
  • download_path (::Pathname, nil) (defaults to: nil)
  • action (Boolean) (defaults to: true)


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
74
75
76
77
78
79
80
81
82
83
# File 'extend/os/mac/cask/quarantine.rb', line 36

def cask!(cask: nil, download_path: nil, action: true)
  return super unless ffi_quarantine?
  return if cask.nil? || download_path.nil?

  return if ::Cask::Quarantine.detect(download_path)

  odebug "Quarantining #{download_path}"

  path_cf_string = MacOS::FFI::CoreFoundation.string_create(download_path.to_s)
  if path_cf_string.null?
    Kernel.raise ::Cask::CaskQuarantineError.new(download_path,
                                                 "Failed to create CFString for path")
  end

  path_cf_url = MacOS::FFI::CoreFoundation.url_create_with_file_system_path(path_cf_string)
  if path_cf_url.null?
    Kernel.raise ::Cask::CaskQuarantineError.new(download_path,
                                                 "Failed to create CFURL for path")
  end

  quarantine_agent_name = MacOS::FFI::CoreFoundation.string_create("Homebrew Cask")
  quarantine_data_url = MacOS::FFI::CoreFoundation.string_create(cask.url.to_s)
  quarantine_origin_url = MacOS::FFI::CoreFoundation.string_create(cask.homepage.to_s)
  if quarantine_agent_name.null? || quarantine_data_url.null? || quarantine_origin_url.null?
    Kernel.raise ::Cask::CaskQuarantineError.new(download_path,
                                                 "Failed to create CFString for quarantine properties")
  end

  quarantine_dictionary = MacOS::FFI::CoreFoundation.dictionary_create(
    MacOS::FFI::LaunchServices.quarantine_agent_name_key => quarantine_agent_name,
    MacOS::FFI::LaunchServices.quarantine_type_key       => MacOS::FFI::LaunchServices.quarantine_type_web_download,
    MacOS::FFI::LaunchServices.quarantine_data_url_key   => quarantine_data_url,
    MacOS::FFI::LaunchServices.quarantine_origin_url_key => quarantine_origin_url,
  )
  if quarantine_dictionary.null?
    Kernel.raise ::Cask::CaskQuarantineError.new(download_path, "Failed to create quarantine dictionary")
  end

  success = MacOS::FFI::CoreFoundation.url_set_resource_property_for_key(
    path_cf_url,
    MacOS::FFI::CoreFoundation.url_quarantine_properties_key,
    quarantine_dictionary,
  )

  return if success

  Kernel.raise ::Cask::CaskQuarantineError.new(download_path, "Failed to set quarantine properties for URL")
end

#check_quarantine_supportArray<(Symbol, [String, nil])>

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.

Returns:



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'extend/os/mac/cask/quarantine.rb', line 20

def check_quarantine_support
  return super unless ffi_quarantine?

  odebug "Checking quarantine support"

  status = if ::Cask::Quarantine.xattr_available?
    odebug "Quarantine is available via FFI."
    :quarantine_available
  else
    odebug "There's no working version of `xattr` on this system."
    :xattr_broken
  end
  [status, nil]
end

#copy_xattrs(from, to, command:) ⇒ 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:



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'extend/os/mac/cask/quarantine.rb', line 86

def copy_xattrs(from, to, command:)
  odebug "Copying xattrs from #{from} to #{to}"
  return super unless ffi_quarantine?

  if to.writable?
    MacOS::FFI.copy_xattrs(from.to_s, to.to_s)
    return
  end

  command.run!(
    HOMEBREW_BREW_FILE,
    args: [
      "ruby",
      "--",
      "-e",
      COPY_XATTRS_RUBY,
      from,
      to,
    ],
    sudo: true,
  )
end