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.

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_cannot_install, #pretty_deprecated, #pretty_disabled, #pretty_duration, #pretty_install_status, #pretty_installed, #pretty_uninstalled, #pretty_unmarked, #pretty_upgradable, #pretty_warning

Methods included from Kernel

#which, #with_env

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)


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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'extend/os/mac/cask/quarantine.rb', line 57

def cask!(cask: nil, download_path: nil, action: true)
  return unless ::Cask::Quarantine.available?
  return if cask.nil? || download_path.nil?

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

  odebug "Quarantining #{download_path}"

  MacOS::FFI::CoreFoundation.with_release_pool do |pool|
    path_cf_string = pool.track(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 = pool.track(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 = pool.track(MacOS::FFI::CoreFoundation.string_create("Homebrew Cask"))
    quarantine_data_url = pool.track(MacOS::FFI::CoreFoundation.string_create(cask.url.to_s))
    quarantine_origin_url = pool.track(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_properties = {
      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,
    }
    quarantine_dictionary = pool.track(MacOS::FFI::CoreFoundation.dictionary_create(quarantine_properties))
    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,
    )

    unless success
      Kernel.raise ::Cask::CaskQuarantineError.new(download_path,
                                                   "Failed to set quarantine properties for URL")
    end
  end
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:



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

def check_quarantine_support
  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:



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'extend/os/mac/cask/quarantine.rb', line 111

def copy_xattrs(from, to, command:)
  return unless ::Cask::Quarantine.available?

  odebug "Copying xattrs from #{from} to #{to}"

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

  ruby, *args = HOMEBREW_RUBY_EXEC_ARGS
  command.run!(
    ruby,
    args: args + [
      "-I",
      $LOAD_PATH.join(File::PATH_SEPARATOR),
      COPY_XATTRS_SCRIPT,
      from,
      to,
    ],
    sudo: true,
  )
end

#signing_identity(file) ⇒ ::Cask::Quarantine::SigningIdentity?

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.

Parameters:

Returns:



39
40
41
42
43
44
# File 'extend/os/mac/cask/quarantine.rb', line 39

def signing_identity(file)
  requirement = MacOS::FFI::Security.designated_requirement(file.to_s)
  return if requirement.nil?

  ::Cask::Quarantine::SigningIdentity.new(requirement:)
end

#signing_identity_match(file, identity) ⇒ Boolean?

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.

Parameters:

Returns:

  • (Boolean, nil)


52
53
54
# File 'extend/os/mac/cask/quarantine.rb', line 52

def signing_identity_match(file, identity)
  MacOS::FFI::Security.requirement_match(file.to_s, identity.requirement)
end