Class: Cask::Audit Private

Inherits:
Object show all
Includes:
SystemCommand::Mixin, Utils::Curl, Utils::Output::Mixin
Defined in:
cask/audit.rb

Overview

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

Audit a cask for various problems.

Constant Summary collapse

DOWNLOAD_TIMEOUT =

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.

600
Error =

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 do
  {
    message:   T.nilable(String),
    location:  T.nilable(Homebrew::SourceLocation),
    corrected: T::Boolean,
  }
end

Instance Attribute Summary collapse

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_once, #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 Utils::Curl

clear_path_cache, curl, curl_args, curl_check_http_content, curl_download, curl_executable, curl_headers, curl_http_content_headers_and_checksum, curl_output, curl_path, curl_response_follow_redirections, curl_response_last_location, curl_supports_fail_with_body?, curl_supports_tls13?, curl_version, curl_with_workarounds, http_status_ok?, https_redirect_curl_args, insecure_redirect?, no_insecure_redirect_curl_args, parse_curl_output, parse_curl_response, strip_progress_bar, url_protected_by_cloudflare?, url_protected_by_incapsula?

Methods included from SystemCommand::Mixin

#command_sandbox, #system_command, #system_command!

Constructor Details

#initialize(cask, download: false, online: nil, strict: nil, signing: nil, new_cask: nil, fix: nil, only: [], except: []) ⇒ 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.

Parameters:

  • cask (::Cask::Cask)
  • download (Boolean) (defaults to: false)
  • online (Boolean, nil) (defaults to: nil)
  • strict (Boolean, nil) (defaults to: nil)
  • signing (Boolean, nil) (defaults to: nil)
  • new_cask (Boolean, nil) (defaults to: nil)
  • fix (Boolean, nil) (defaults to: nil)
  • only (Array<String>) (defaults to: [])
  • except (Array<String>) (defaults to: [])


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
# File 'cask/audit.rb', line 58

def initialize(
  cask,
  download: false,
  online: nil, strict: nil, signing: nil,
  new_cask: nil, fix: nil, only: [], except: []
)
  # `new_cask` implies `online`, `strict` and `signing`
  online = new_cask if online.nil?
  strict = new_cask if strict.nil?
  signing = new_cask if signing.nil?

  # `online` and `signing` imply `download`
  download ||= online || signing

  @cask = cask
  @download = T.let(nil, T.nilable(Download))
  @download = Download.new(cask) if download
  @download_failed = T.let(false, T::Boolean)
  @online = online
  @strict = strict
  @signing = signing
  @new_cask = new_cask
  @fix = fix
  @only = only
  @except = except
  @livecheck_result = T.let(nil, T.nilable(T.any(T::Boolean, Symbol)))
end

Instance Attribute Details

#cask ⇒ Cask (readonly)

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:



42
43
44
# File 'cask/audit.rb', line 42

def cask
  @cask
end

#download ⇒ Download? (readonly)

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:



45
46
47
# File 'cask/audit.rb', line 45

def download
  @download
end

#livecheck_result=(value) ⇒ void (writeonly)

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.



48
49
50
# File 'cask/audit.rb', line 48

def livecheck_result=(value)
  @livecheck_result = value
end

Instance Method Details

#add_error(message, location: nil, strict_only: false, corrected: false) ⇒ 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:

  • message (String, nil)
  • location (Homebrew::SourceLocation, nil) (defaults to: nil)
  • strict_only (Boolean) (defaults to: false)
  • corrected (Boolean) (defaults to: false)


144
145
146
147
148
149
# File 'cask/audit.rb', line 144

def add_error(message, location: nil, strict_only: false, corrected: false)
  # Only raise non-critical audits if the user specified `--strict`.
  return if strict_only && !@strict

  errors << { message:, location:, corrected: }
end

#audit_appimage_versioned_target ⇒ 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.



372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
# File 'cask/audit.rb', line 372

def audit_appimage_versioned_target
  # `app_image` artifacts live inside `on_linux` blocks,
  # so an audit running on another OS would not materialize them.
  # Evaluate every tag (restoring the default afterwards)
  # so the check runs regardless of the audit host.
  basenames = if cask.on_system_blocks_exist?
    begin
      OnSystem::VALID_OS_ARCH_TAGS.flat_map do |tag|
        cask.refresh_for_tag(tag) { appimage_target_basenames } || []
      end
    ensure
      cask.refresh
    end
  else
    appimage_target_basenames
  end

  basenames.uniq.each do |basename|
    # electron-updater renames the AppImage on self-update
    # if its basename contains an `X.Y.Z` version,
    # which leaves the Caskroom back-symlink dangling.
    # A version-less target is overwritten in place instead.
    next unless basename.match?(/\d+\.\d+\.\d+/)

    add_error "app_image target '#{basename}' should not embed a version; " \
              "use a version-less `target:` so self-updaters overwrite it in place"
  end
end

#audit_artifact_case ⇒ 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.



710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
# File 'cask/audit.rb', line 710

def audit_artifact_case
  return if (url = cask.url).nil?
  return unless online?

  odebug "Auditing artifact case"

  extract_artifacts(include_manual_installers: true) do |artifacts, tmpdir|
    artifacts.each do |artifact|
      source = case artifact
      when Artifact::Pkg, Artifact::Installer
        artifact.path
      else
        artifact.source
      end

      source = if source.to_s.start_with?("#{cask.appdir}/")
        Pathname(source.to_s.delete_prefix("#{cask.appdir}/"))
      elsif source.absolute?
        source.relative_path_from(cask.staged_path)
      else
        source
      end

      components = source.each_filename.to_a
      current = tmpdir
      on_disk = []
      components.each do |component|
        break unless current.directory?

        children = current.children.map { |child| child.basename.to_s }
        match = children.find { |name| name == component } ||
                children.find { |name| name.casecmp?(component) }
        break if match.nil?

        on_disk << match
        current /= match
      end

      next if on_disk.length != components.length
      next if on_disk == components

      message = "Artifact #{source} does not match the case of the extracted " \
                "#{File.join(on_disk)}; this fails on case-sensitive filesystems"
      dsl_key = artifact.class.dsl_key

      fixed = correct_error("#{message}; corrected the `#{dsl_key}` stanza", location: url.location) do |cask_ast|
        cask_ast.replace_stanza_value(dsl_key, source.to_s, File.join(on_disk)).positive?
      end
      next if fixed

      add_error "#{message}.", location: url.location
    end
  end
end

#audit_bitbucket_repository ⇒ 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.



1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
# File 'cask/audit.rb', line 1075

def audit_bitbucket_repository
  return unless new_cask?
  return if (url = cask.url).nil?

  user, repo = get_repo_data(%r{https?://bitbucket\.org/([^/]+)/([^/]+)/?.*})
  return if user.nil? || repo.nil?

  odebug "Auditing Bitbucket repo"

  self_submission = self_submission?(user)
  error = SharedAudits.bitbucket(user, repo, self_submission:)
  add_error error, location: url.location if error
end

#audit_cask_path ⇒ 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.



1203
1204
1205
1206
1207
1208
1209
1210
1211
# File 'cask/audit.rb', line 1203

def audit_cask_path
  return unless (tap = cask.tap)&.core_cask_tap?

  expected_path = tap.new_cask_path(cask.token)

  return if cask.sourcefile_path.to_s.end_with?(expected_path.to_s)

  add_error "Cask should be located in '#{expected_path}'"
end

#audit_conflicts_with ⇒ 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.



1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
# File 'cask/audit.rb', line 1105

def audit_conflicts_with
  return if !cask.tap&.official? || cask.conflicts_with.nil?

  Homebrew::API.with_no_api_env do
    nonexisting_conflicting_casks = cask.conflicts_with.fetch(:cask, Set.new) - core_cask_tokens
    nonexisting_conflicting_casks.each do |c|
      add_error("cask conflicts with non-existing cask `#{c}`")
    end
  end
end

#audit_denylist ⇒ 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.



1117
1118
1119
1120
1121
1122
# File 'cask/audit.rb', line 1117

def audit_denylist
  return unless cask.tap&.official?
  return unless (reason = Denylist.reason(cask.token))

  add_error "#{cask.token} is not allowed: #{reason}"
end

#audit_deprecate_disable ⇒ 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.



1214
1215
1216
1217
# File 'cask/audit.rb', line 1214

def audit_deprecate_disable
  error = SharedAudits.check_deprecate_disable_reason(cask)
  add_error error if error
end

#audit_description ⇒ 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.



351
352
353
354
355
356
357
# File 'cask/audit.rb', line 351

def audit_description
  # Fonts seldom benefit from descriptions and requiring them disproportionately
  # increases the maintenance burden.
  return if cask.tap == "homebrew/cask" && cask.token.include?("font-")

  add_error("Cask should have a description. Please add a `desc` stanza.", strict_only: true) if cask.desc.blank?
end

#audit_download ⇒ 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.



582
583
584
# File 'cask/audit.rb', line 582

def audit_download
  fetch_download
end

#audit_download_url_format ⇒ 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.



499
500
501
502
503
504
505
506
507
# File 'cask/audit.rb', line 499

def audit_download_url_format
  return if (url = cask.url).nil?

  odebug "Auditing URL format"
  return unless bad_sourceforge_url?

  add_error "SourceForge URL format incorrect. See #{Formatter.url(SOURCEFORGE_REFERENCE_URL)}",
            location: url.location
end

#audit_download_url_is_osdn ⇒ 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.



510
511
512
513
514
515
# File 'cask/audit.rb', line 510

def audit_download_url_is_osdn
  return if (url = cask.url).nil?
  return unless bad_osdn_url?

  add_error "OSDN download urls are disabled.", location: url.location, strict_only: true
end

#audit_forgejo_prerelease_version ⇒ 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.



982
983
984
985
986
987
988
989
990
991
992
993
# File 'cask/audit.rb', line 982

def audit_forgejo_prerelease_version
  return if (url = cask.url).nil?

  odebug "Auditing Forgejo prerelease"
  user, repo = get_repo_data(%r{https?://codeberg\.org/([^/]+)/([^/]+)/?.*}) if online?
  return if user.nil? || repo.nil?

  tag = SharedAudits.forgejo_tag_from_url(url.to_s)
  tag ||= cask.version
  error = SharedAudits.forgejo_release(user, repo, tag, cask:)
  add_error error, location: url.location if error
end

#audit_forgejo_repository ⇒ 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.



1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
# File 'cask/audit.rb', line 1090

def audit_forgejo_repository
  return unless new_cask?
  return if (url = cask.url).nil?

  user, repo = get_repo_data(%r{https?://codeberg\.org/([^/]+)/([^/]+)/?.*})
  return if user.nil? || repo.nil?

  odebug "Auditing Forgejo repo"

  self_submission = self_submission?(user)
  error = SharedAudits.forgejo(user, repo, self_submission:)
  add_error error, location: url.location if error
end

#audit_forgejo_repository_archived ⇒ 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.



1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
# File 'cask/audit.rb', line 1028

def audit_forgejo_repository_archived
  return if cask.deprecated? || cask.disabled?
  return if (url = cask.url).nil?

  user, repo = get_repo_data(%r{https?://codeberg\.org/([^/]+)/([^/]+)/?.*}) if online?
  return if user.nil? || repo.nil?

   = SharedAudits.forgejo_repo_data(user, repo)
  return if .nil?

  return unless ["archived"]

  add_error "Forgejo repository is archived since #{["archived_at"]}",
            location: url.location
end

#audit_generic_artifacts ⇒ 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.



518
519
520
521
522
523
524
# File 'cask/audit.rb', line 518

def audit_generic_artifacts
  cask.artifacts.grep(Artifact::Artifact).each do |artifact|
    unless artifact.target.absolute?
      add_error "target must be absolute path for #{artifact.class.english_name} #{artifact.source}"
    end
  end
end

#audit_github_prerelease_version ⇒ 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.



953
954
955
956
957
958
959
960
961
962
963
964
# File 'cask/audit.rb', line 953

def audit_github_prerelease_version
  return if (url = cask.url).nil?

  odebug "Auditing GitHub prerelease"
  user, repo = get_repo_data(%r{https?://github\.com/([^/]+)/([^/]+)/?.*}) if online?
  return if user.nil? || repo.nil?

  tag = SharedAudits.github_tag_from_url(url.to_s)
  tag ||= cask.version
  error = SharedAudits.github_release(user, repo, tag, cask:)
  add_error error, location: url.location if error
end

#audit_github_repository ⇒ 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.



1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
# File 'cask/audit.rb', line 1045

def audit_github_repository
  return unless new_cask?
  return if (url = cask.url).nil?

  user, repo = get_repo_data(%r{https?://github\.com/([^/]+)/([^/]+)/?.*})
  return if user.nil? || repo.nil?

  odebug "Auditing GitHub repo"

  self_submission = self_submission?(user)
  error = SharedAudits.github(user, repo, self_submission:)
  add_error error, location: url.location if error
end

#audit_github_repository_archived ⇒ 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.



996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
# File 'cask/audit.rb', line 996

def audit_github_repository_archived
  # Deprecated/disabled casks may have an archived repository.
  return if cask.deprecated? || cask.disabled?
  return if (url = cask.url).nil?

  user, repo = get_repo_data(%r{https?://github\.com/([^/]+)/([^/]+)/?.*}) if online?
  return if user.nil? || repo.nil?

   = SharedAudits.github_repo_data(user, repo)
  return if .nil?

  add_error "GitHub repo is archived", location: url.location if ["archived"]
end

#audit_gitlab_prerelease_version ⇒ 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.



967
968
969
970
971
972
973
974
975
976
977
978
979
# File 'cask/audit.rb', line 967

def audit_gitlab_prerelease_version
  return if (url = cask.url).nil?

  user, repo = get_repo_data(%r{https?://gitlab\.com/([^/]+)/([^/]+)/?.*}) if online?
  return if user.nil? || repo.nil?

  odebug "Auditing GitLab prerelease"

  tag = SharedAudits.gitlab_tag_from_url(url.to_s)
  tag ||= cask.version
  error = SharedAudits.gitlab_release(user, repo, tag, cask:)
  add_error error, location: url.location if error
end

#audit_gitlab_repository ⇒ 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.



1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
# File 'cask/audit.rb', line 1060

def audit_gitlab_repository
  return unless new_cask?
  return if (url = cask.url).nil?

  user, repo = get_repo_data(%r{https?://gitlab\.com/([^/]+)/([^/]+)/?.*})
  return if user.nil? || repo.nil?

  odebug "Auditing GitLab repo"

  self_submission = self_submission?(user)
  error = SharedAudits.gitlab(user, repo, self_submission:)
  add_error error, location: url.location if error
end

#audit_gitlab_repository_archived ⇒ 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.



1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
# File 'cask/audit.rb', line 1011

def audit_gitlab_repository_archived
  # Deprecated/disabled casks may have an archived repository.
  return if cask.deprecated? || cask.disabled?
  return if (url = cask.url).nil?

  user, repo = get_repo_data(%r{https?://gitlab\.com/([^/]+)/([^/]+)/?.*}) if online?
  return if user.nil? || repo.nil?

  odebug "Auditing GitLab repo archived"

   = SharedAudits.gitlab_repo_data(user, repo)
  return if .nil?

  add_error "GitLab repo is archived", location: url.location if ["archived"]
end

#audit_homepage_domain_age ⇒ 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.



1154
1155
1156
1157
1158
1159
1160
1161
# File 'cask/audit.rb', line 1154

def audit_homepage_domain_age
  return unless new_cask?
  return unless cask.tap&.official?
  return unless (homepage = cask.homepage)

  new_domain_problem = SharedAudits.new_domain_problem(homepage)
  add_error new_domain_problem if new_domain_problem
end

#audit_homepage_https_availability ⇒ 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.



1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
# File 'cask/audit.rb', line 1134

def audit_homepage_https_availability
  return unless online?
  return unless (homepage = cask.homepage)
  return if SharedAudits.homepage_browsed_recently?(cask.homepage_browsed)

  user_agents = if cask.tap&.audit_exception(:simple_user_agent_for_homepage, cask.token)
    ["curl"]
  else
    [:browser, :default]
  end

  validate_url_for_https_availability(
    homepage, SharedAudits::URL_TYPE_HOMEPAGE,
    user_agents:,
    check_content: true,
    strict:        strict?
  )
end

#audit_hosting_with_livecheck ⇒ 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.



476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
# File 'cask/audit.rb', line 476

def audit_hosting_with_livecheck
  return if cask.deprecated? || cask.disabled?
  return if cask.version&.latest?
  return if (url = cask.url).nil?
  return if cask.livecheck_defined?
  return if audit_livecheck_version == :auto_detected

  add_livecheck = "please add a livecheck. See #{Formatter.url(LIVECHECK_REFERENCE_URL)}"

  case url.uri.host
  when /(?:\A|\.)sourceforge\.net\z/
    return unless online?

    add_error "Download is hosted on SourceForge, #{add_livecheck}", location: url.location
  when "dl.devmate.com"
    add_error "Download is hosted on DevMate, #{add_livecheck}", location: url.location
  end
end

#audit_languages ⇒ 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.



527
528
529
530
531
532
533
# File 'cask/audit.rb', line 527

def audit_languages
  @cask.languages.each do |language|
    Locale.parse(language)
  rescue Locale::ParserError
    add_error "Locale '#{language}' is invalid."
  end
end

#audit_latest_with_auto_updates ⇒ 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.



465
466
467
468
469
470
# File 'cask/audit.rb', line 465

def audit_latest_with_auto_updates
  return unless cask.version&.latest?
  return unless cask.auto_updates

  add_error "Casks with `version :latest` should not use `auto_updates`."
end

#audit_latest_with_livecheck ⇒ 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.



456
457
458
459
460
461
462
# File 'cask/audit.rb', line 456

def audit_latest_with_livecheck
  return unless cask.version&.latest?
  return unless cask.livecheck_defined?
  return if cask.livecheck.skip?

  add_error "Casks with a `livecheck` should not use `version :latest`."
end

#audit_livecheck_https_availability ⇒ 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.



1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
# File 'cask/audit.rb', line 1178

def audit_livecheck_https_availability
  return unless online?
  return unless cask.livecheck_defined?
  return unless (url = cask.livecheck.url)
  return if url.is_a?(Symbol)

  options = cask.livecheck.options
  return if options.post_form || options.post_json

  # Validating HTTPS availability is unnecessary if the check uses HTTPS
  # and does not fail.
  if url.start_with?("https:") && audit_livecheck_version != false
    odebug "Skipping livecheck_https_availability audit (working HTTPS livecheck)"
    return
  end

  odebug "Auditing livecheck HTTPS availability"
  validate_url_for_https_availability(
    url, "livecheck URL",
    check_content: true,
    user_agents:   [:default, :browser]
  )
end

#audit_livecheck_unneeded_long_version ⇒ 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.



587
588
589
590
591
592
593
594
595
596
597
# File 'cask/audit.rb', line 587

def audit_livecheck_unneeded_long_version
  return if cask.version.nil? || (url = cask.url).nil?
  return if cask.livecheck.strategy != :sparkle
  return unless cask.version.csv.second
  return if cask.url.to_s.include? cask.version.csv.second
  return if cask.version.csv.third.present? && cask.url.to_s.include?(cask.version.csv.third)

  add_error "Download does not require additional version components. Use `&:short_version` in the livecheck",
            location:    url.location,
            strict_only: true
end

#audit_livecheck_version ⇒ 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.

Returns:



841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
# File 'cask/audit.rb', line 841

def audit_livecheck_version
  return @livecheck_result unless @livecheck_result.nil?
  return unless online?
  return unless cask.version

  odebug "Auditing livecheck version"

  referenced_cask, = Homebrew::Livecheck.resolve_livecheck_reference(cask)

  # Respect skip conditions for a referenced cask
  if referenced_cask
    skip_info = Homebrew::Livecheck::SkipConditions.referenced_skip_information(
      referenced_cask,
      Homebrew::Livecheck.package_or_resource_name(cask),
    )
  end

  # Respect cask skip conditions (e.g. deprecated, disabled, latest, unversioned)
  skip_info ||= Homebrew::Livecheck::SkipConditions.skip_information(cask)
  if skip_info.present?
    @livecheck_result = :skip
    return @livecheck_result
  end

  result = Homebrew::Livecheck.latest_version(
    cask,
    referenced_formula_or_cask: referenced_cask,
  )
  if result
    throttle = cask.livecheck.throttle
    throttle_days = cask.livecheck.throttle_days
    if referenced_cask
      throttle ||= referenced_cask.livecheck.throttle
      throttle_days ||= referenced_cask.livecheck.throttle_days
    end

    latest_version = (throttle || throttle_days) ? result[:latest_throttled] : result[:latest]
  end

  if latest_version && (cask.version.to_s == latest_version.to_s)
    @livecheck_result = :auto_detected
    return @livecheck_result
  end

  add_error "Version '#{cask.version}' differs from '#{latest_version}' retrieved by livecheck."

  @livecheck_result = false
end

#audit_min_os ⇒ 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.



891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
# File 'cask/audit.rb', line 891

def audit_min_os
  return unless online?

  odebug "Auditing minimum macOS version"

  bundle_min_os = cask_bundle_min_os
  sparkle_min_os = cask_sparkle_min_os

  app_min_os = [bundle_min_os, sparkle_min_os].compact.max
  debug_messages = []
  debug_messages << "from artifact: #{bundle_min_os.to_sym}" if bundle_min_os
  debug_messages << "from upstream: #{sparkle_min_os.to_sym}" if sparkle_min_os
  odebug "Detected minimum macOS: #{app_min_os.to_sym} (#{debug_messages.join(" | ")})" if app_min_os
  return if app_min_os.nil? || app_min_os <= HOMEBREW_MACOS_OLDEST_ALLOWED

  on_system_block_min_os = cask.on_system_block_min_os
  depends_on_min_os = cask.depends_on.macos&.minimum_version

  cask_min_os = [on_system_block_min_os, depends_on_min_os].compact.max
  debug_messages = []
  debug_messages << "from on_system block: #{on_system_block_min_os.to_sym}" if on_system_block_min_os
  if depends_on_min_os && depends_on_min_os > HOMEBREW_MACOS_OLDEST_ALLOWED
    debug_messages << "from depends_on stanza: #{depends_on_min_os.to_sym}"
  end
  odebug "Declared minimum macOS: #{cask_min_os&.to_sym} (#{debug_messages.join(" | ").presence || "default"})"
  return if cask_min_os&.to_sym == app_min_os.to_sym
  # ignore declared minimum OS < 11.x when auditing as ARM a cask with arch-specific artifacts
  return if OnSystem.arch_condition_met?(:arm) &&
            cask.on_system_blocks_exist? &&
            cask_min_os.present? &&
            app_min_os < MacOSVersion.new("11") &&
            app_min_os < cask_min_os

  min_os_definition = if cask_min_os && cask_min_os > HOMEBREW_MACOS_OLDEST_ALLOWED
    definition = if on_system_block_min_os.to_s > depends_on_min_os.to_s
      "an on_system block"
    else
      "a depends_on stanza"
    end
    "#{definition} with a minimum macOS version of #{cask_min_os.to_sym.inspect}"
  else
    "no minimum macOS version"
  end
  source = (bundle_min_os.to_s > sparkle_min_os.to_s) ? "Artifact" : "Upstream"
  message = "#{source} defined #{app_min_os.to_sym.inspect} as the minimum macOS version " \
            "but the cask declared #{min_os_definition}"

  # A cask with `on_system` blocks may have a different minimum per OS or
  # arch, so a top-level `depends_on macos:` stanza would be wrong.
  maximum_macos = cask.depends_on.maximum_macos&.maximum_version
  unsatisfiable_minimum = maximum_macos.present? && app_min_os > maximum_macos
  if !cask.on_system_blocks_exist? && !unsatisfiable_minimum
    fixed = correct_error("#{message}; set `depends_on macos:` to #{app_min_os.to_sym.inspect}") do |cask_ast|
      cask_ast.update_depends_on_macos_minimum!(app_min_os.to_sym)
    end
    return if fixed
  end

  add_error message
end

#audit_no_string_version_latest ⇒ 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.



402
403
404
405
406
407
408
409
# File 'cask/audit.rb', line 402

def audit_no_string_version_latest
  return unless cask.version

  odebug "Auditing version :latest does not appear as a string ('latest')"
  return if cask.version.raw_version != "latest"

  add_error "you should use version :latest instead of version 'latest'"
end

#audit_required_stanzas ⇒ 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.



329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
# File 'cask/audit.rb', line 329

def audit_required_stanzas
  odebug "Auditing required stanzas"
  [:version, :sha256, :url, :homepage].each do |sym|
    add_error "a #{sym} stanza is required" unless cask.public_send(sym)
  end
  add_error "at least one name stanza is required" if cask.name.empty?

  installable_artifact = if cask.on_system_blocks_exist?
    begin
      OnSystem::VALID_OS_ARCH_TAGS.any? do |tag|
        cask.refresh_for_tag(tag) { cask.installable_artifact? }
      end
    ensure
      cask.refresh
    end
  else
    cask.installable_artifact?
  end
  add_error "at least one installable artifact stanza is required" unless installable_artifact
end

#audit_reverse_migration ⇒ 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.



1125
1126
1127
1128
1129
1130
1131
# File 'cask/audit.rb', line 1125

def audit_reverse_migration
  return unless new_cask?
  return unless cask.tap&.official?
  return unless cask.tap&.tap_migrations&.key?(cask.token)

  add_error "#{cask.token} is listed in tap_migrations.json"
end

#audit_rosetta ⇒ 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.



766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
# File 'cask/audit.rb', line 766

def audit_rosetta
  return if (url = cask.url).nil?
  return unless online?
  # Rosetta 2 is only for ARM-capable macOS versions, which are Big Sur (11.x) and later
  return if Homebrew::SimulateSystem.current_arch != :arm
  return if MacOSVersion::SYMBOLS.fetch(Homebrew::SimulateSystem.current_os, "10") < "11"
  return if cask.depends_on.macos&.maximum_version.to_s < "11"

  odebug "Auditing Rosetta 2 requirement"

  extract_artifacts do |artifacts, tmpdir|
    is_container = artifacts.any? { |a| a.is_a?(Artifact::App) || a.is_a?(Artifact::Pkg) }

    mentions_rosetta = cask.caveats_object.invoked?(:requires_rosetta) ||
                       cask.caveats.include?("requires Rosetta 2")
    requires_intel = cask.depends_on.arch&.any? { |arch| arch[:type] == :intel }

    artifacts_to_test = artifacts.filter do |artifact|
      next false if !artifact.is_a?(Artifact::App) && !artifact.is_a?(Artifact::Binary)
      next false if artifact.is_a?(Artifact::Binary) && is_container

      true
    end

    next if artifacts_to_test.blank?

    any_requires_rosetta = artifacts_to_test.any? do |artifact|
      artifact = T.cast(artifact, T.any(Artifact::App, Artifact::Binary))
      path = tmpdir/artifact.source.relative_path_from(cask.staged_path)

      result = case artifact
      when Artifact::App
        files = Dir[path/"Contents/MacOS/*"].select do |f|
          File.executable?(f) && !File.directory?(f) && !f.end_with?(".dylib")
        end
        add_error "No binaries in App: #{artifact.source}", location: url.location if files.empty?

        main_binary = get_plist_main_binary(path)
        main_binary ||= files.fetch(0)

        system_command("lipo", args: ["-archs", main_binary], print_stderr: false)
      when Artifact::Binary
        binary_path = path.to_s.gsub(cask.appdir, tmpdir.to_s)
        system_command("lipo", args: ["-archs", binary_path], print_stderr: true)
      else
        T.absurd(artifact)
      end

      # binary stanza can contain shell scripts, so we just continue if lipo fails.
      next false unless result.success?

      odebug "Architectures: #{result.merged_output}"

      unless /arm64|x86_64/.match?(result.merged_output)
        add_error "Artifacts architecture is no longer supported by macOS!",
                  location: url.location
        next
      end

      result.merged_output.exclude?("arm64") && result.merged_output.include?("x86_64")
    end

    if any_requires_rosetta
      if !mentions_rosetta && !requires_intel
        add_error "At least one artifact requires Rosetta 2 but this is not indicated by the caveats!",
                  location: url.location
      end
    elsif mentions_rosetta
      add_error "No artifacts require Rosetta 2 but the caveats say otherwise!",
                location: url.location
    end
  end
end

#audit_sha256_actually_256 ⇒ 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.



434
435
436
437
438
439
440
441
442
# File 'cask/audit.rb', line 434

def audit_sha256_actually_256
  return unless cask.sha256

  odebug "Auditing sha256 string is a legal SHA-256 digest"
  return unless cask.sha256.is_a?(Checksum)
  return if cask.sha256.to_s.match?(/\A[0-9a-f]{64}\z/i)

  add_error "sha256 string must be of 64 hexadecimal characters"
end

#audit_sha256_invalid ⇒ 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.



445
446
447
448
449
450
451
452
453
# File 'cask/audit.rb', line 445

def audit_sha256_invalid
  return unless cask.sha256

  odebug "Auditing sha256 is not a known invalid value"
  empty_sha256 = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
  return if cask.sha256 != empty_sha256

  add_error "cannot use the sha256 for an empty string: #{empty_sha256}"
end

#audit_sha256_no_check_if_latest ⇒ 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.



412
413
414
415
416
417
418
419
420
421
# File 'cask/audit.rb', line 412

def audit_sha256_no_check_if_latest
  return unless cask.sha256
  return unless cask.version

  odebug "Auditing sha256 :no_check with version :latest"
  return unless cask.version.latest?
  return if cask.sha256 == :no_check

  add_error "you should use sha256 :no_check when version is :latest"
end

#audit_sha256_no_check_if_unversioned ⇒ 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.



424
425
426
427
428
429
430
431
# File 'cask/audit.rb', line 424

def audit_sha256_no_check_if_unversioned
  return unless cask.sha256
  return if cask.sha256 == :no_check

  return unless cask.url&.unversioned?

  add_error "Use `sha256 :no_check` when URL is unversioned."
end

#audit_signing ⇒ 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.



600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
# File 'cask/audit.rb', line 600

def audit_signing
  return if download.blank?

  url = cask.url
  return if url.nil?

  return if !cask.tap&.official? && !signing?

  deprecated_or_disabled = cask.deprecated? || cask.disabled?
  deprecate_disable_reason = cask.disabled? ? cask.disable_reason : cask.deprecation_reason
  gatekeeper_failure_expected = deprecate_disable_reason == :fails_gatekeeper_check
  return if deprecated_or_disabled && !gatekeeper_failure_expected

  unless Quarantine.available?
    odebug "Quarantine support is not available, skipping signing audit"
    return
  end

  odebug "Auditing signing"
  is_in_skiplist = cask.tap&.audit_exception(:signing_audit_skiplist, cask.token,
                                             Homebrew::SimulateSystem.current_arch.to_s) ||
                   cask.tap&.audit_exception(:signing_audit_skiplist, cask.token, "all")

  extract_artifacts(include_manual_installers: true) do |artifacts, tmpdir|
    is_container = artifacts.any? do |artifact|
      artifact.is_a?(Artifact::App) || artifact.is_a?(Artifact::Pkg) ||
        (artifact.is_a?(Artifact::Installer) && [".app", ".pkg"].include?(artifact.path.extname.downcase))
    end

    any_signing_failure = artifacts.any? do |artifact|
      next false if artifact.is_a?(Artifact::Binary) && is_container == true

      artifact_path = case artifact
      when Artifact::Pkg, Artifact::Installer
        artifact.path
      else
        artifact.source
      end

      artifact_path = artifact_path.relative_path_from(cask.staged_path) if artifact_path.absolute?
      path = tmpdir/artifact_path

      unless Quarantine.detect(path)
        odebug "#{path} does not have quarantine attributes, skipping signing audit"
        next false
      end

      result = case artifact
      when Artifact::Pkg
        system_command("spctl", args: ["--assess", "--type", "install", path], print_stderr: false)
      when Artifact::App
        next opoo "gktool not found, skipping app signing audit" unless which("gktool")

        system_command("gktool", args: ["scan", path], print_stderr: false)
      when Artifact::Installer
        if artifact.path.extname.downcase == ".app"
          next opoo "gktool not found, skipping app signing audit" unless which("gktool")

          system_command("gktool", args: ["scan", path], print_stderr: false)
        elsif artifact.path.extname.downcase == ".pkg"
          system_command("spctl", args: ["--assess", "--type", "install", path], print_stderr: false)
        else
          next false
        end
      when Artifact::Binary
        # Shell scripts cannot be signed, so we skip them
        next false if ::Utils::Path.text_executable?(path)

        system_command("codesign", args:         ["--verify", "-R=notarized", "--check-notarization", path],
                                   print_stderr: false)
      else
        add_error "Unknown artifact type: #{artifact.class}", location: url.location
        next
      end

      next false if result.success?
      next true if gatekeeper_failure_expected
      next true if is_in_skiplist

      signing_failure_message = <<~EOS
        Signature verification failed:
        #{result.merged_output}
      EOS

      if cask.tap&.official?
        signing_failure_message += <<~EOS
          The homebrew/cask tap requires all casks to be signed and notarized by Apple.
          Please contact the upstream developer and ask them to sign and notarize their software.
        EOS
      end

      add_error signing_failure_message

      true
    end

    return if any_signing_failure

    add_error "Cask is in the signing audit skiplist, but does not need to be skipped!" if is_in_skiplist

    return unless gatekeeper_failure_expected

    add_error <<~EOS
      Cask is deprecated/disabled because it failed Gatekeeper checks but all artifacts now pass!
      Remove the deprecate/disable stanza or update the deprecate/disable reason.
    EOS
  end
end

#audit_single_zap ⇒ 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.



321
322
323
324
325
326
# File 'cask/audit.rb', line 321

def audit_single_zap
  odebug "Auditing single zap stanzas"
  return if cask.artifacts.count { |k| k.is_a?(Artifact::Zap) } <= 1

  add_error "only a single zap stanza is allowed"
end

#audit_stanza_requires_uninstall ⇒ 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.



311
312
313
314
315
316
317
318
# File 'cask/audit.rb', line 311

def audit_stanza_requires_uninstall
  odebug "Auditing stanzas which require an uninstall"

  return if cask.artifacts.none? { |k| k.is_a?(Artifact::Pkg) || k.is_a?(Artifact::Installer) }
  return if cask.artifacts.any?(Artifact::Uninstall)

  add_error "installer and pkg stanzas require an uninstall stanza"
end

#audit_token ⇒ 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.



536
537
538
539
540
541
542
# File 'cask/audit.rb', line 536

def audit_token
  token_auditor = Homebrew::FormulaNameCaskTokenAuditor.new(cask.token)
  return if (errors = token_auditor.errors).none?

  add_error "Cask token '#{cask.token}' must not contain " \
            "#{::Utils::Text.to_sentence(errors, conjunction: "or")}."
end

#audit_token_bad_words ⇒ 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.



554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
# File 'cask/audit.rb', line 554

def audit_token_bad_words
  return unless new_cask?

  token = cask.token

  add_error "cask token contains .app" if token.end_with? ".app"

  match_data = /-(?<designation>alpha|beta|rc|release-candidate)$/.match(cask.token)
  if match_data && cask.tap&.official?
    add_error "cask token contains version designation '#{match_data[:designation]}'"
  end

  add_error("cask token mentions launcher", strict_only: true) if token.end_with? "launcher"

  add_error("cask token mentions desktop", strict_only: true) if token.end_with? "desktop"

  add_error("cask token mentions platform", strict_only: true) if token.end_with? "mac", "osx", "macos"

  add_error("cask token mentions architecture", strict_only: true) if token.end_with? "x86", "32_bit", "x86_64",
                                                                                      "64_bit"

  frameworks = %w[cocoa qt gtk wx java]
  return if frameworks.include?(token) || !token.end_with?(*frameworks)

  add_error("cask token mentions framework", strict_only: true)
end

#audit_token_conflicts ⇒ 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.



545
546
547
548
549
550
551
# File 'cask/audit.rb', line 545

def audit_token_conflicts
  Homebrew::API.with_no_api_env do
    return unless core_formula_names.include?(cask.token)

    add_error("cask token conflicts with an existing homebrew/core formula: #{Formatter.url(core_formula_url)}")
  end
end

#audit_url_https_availability ⇒ 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.



1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
# File 'cask/audit.rb', line 1164

def audit_url_https_availability
  return unless online?
  return unless (url = cask.url)
  return if url.using

  validate_url_for_https_availability(
    url, "binary URL",
    location:    url.location,
    user_agents: [url.user_agent],
    referer:     url.referer
  )
end

#audit_version_special_characters ⇒ 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.



360
361
362
363
364
365
366
367
368
369
# File 'cask/audit.rb', line 360

def audit_version_special_characters
  return unless cask.version

  return if cask.version.latest?

  raw_version = cask.version.raw_version
  return if raw_version.exclude?(":") && raw_version.exclude?("/")

  add_error "version should not contain colons or slashes"
end

#cask_sparkle_min_os ⇒ MacOSVersion?

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:



280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'cask/audit.rb', line 280

def cask_sparkle_min_os
  return unless online?
  return unless cask.livecheck_defined?
  return if (livecheck = cask.livecheck).strategy != :sparkle
  return unless (livecheck_url = livecheck.url)

  # `Sparkle` strategy blocks that use the `items` argument (instead of
  # `item`) contain arbitrary logic that ignores/overrides the strategy's
  # sorting, so we can't identify which item would be first/newest here.
  return if livecheck.strategy_block.present? &&
            livecheck.strategy_block.parameters[0] == [:opt, :items]

  url = Homebrew::Livecheck.livecheck_url_to_string(livecheck_url, cask)
  content = Homebrew::Livecheck::Strategy.page_content(url, options: livecheck.options)[:content]
  return if content.blank?

  begin
    items = Homebrew::Livecheck::Strategy::Sparkle.sort_items(
      Homebrew::Livecheck::Strategy::Sparkle.filter_items(
        Homebrew::Livecheck::Strategy::Sparkle.items_from_content(content),
      ),
    )
  rescue
    return
  end
  return if items.blank?

  normalize_min_os(items.fetch(0).minimum_system_version)
end

#errors ⇒ Array<Error>

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:



122
123
124
# File 'cask/audit.rb', line 122

def errors
  @errors ||= T.let([], T.nilable(T::Array[Error]))
end

#errors? ⇒ 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.

Returns:

  • (Boolean)


127
128
129
# File 'cask/audit.rb', line 127

def errors?
  errors.any?
end

#extract_artifacts(include_manual_installers: false, &_block) {|artifacts, @tmpdir| ... } ⇒ 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:

Yields:

  • (artifacts, @tmpdir)


178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
# File 'cask/audit.rb', line 178

def extract_artifacts(include_manual_installers: false, &_block)
  return unless online?
  return if download.nil? || @download_failed

  artifacts = cask.artifacts.select do |artifact|
    artifact.is_a?(Artifact::Pkg) ||
      artifact.is_a?(Artifact::App) ||
      artifact.is_a?(Artifact::Binary) ||
      (include_manual_installers &&
        artifact.is_a?(Artifact::Installer) &&
        artifact.manual_install &&
        [".app", ".pkg"].include?(artifact.path.extname.downcase))
  end

  if @artifacts_extracted && @tmpdir
    yield artifacts, @tmpdir if block_given?
    return
  end

  return if artifacts.empty?

  @tmpdir ||= T.let(Pathname(Dir.mktmpdir("cask-audit", HOMEBREW_TEMP)), T.nilable(Pathname))

  # Clean up tmp dir when @tmpdir object is destroyed
  ObjectSpace.define_finalizer(
    @tmpdir,
    proc { FileUtils.remove_entry(@tmpdir) },
  )

  ohai "Downloading and extracting artifacts"

  return unless (downloaded_path = fetch_download)

  primary_container = UnpackStrategy.detect(downloaded_path, type: @cask.container&.type, merge_xattrs: true)
  return if primary_container.nil?

  # If the container has any dependencies we need to install them or unpacking will fail.
  if primary_container.dependencies.any?

    install_options = {
      show_header:          true,
      installed_on_request: false,
      verbose:              false,
    }.compact

    Homebrew::Install.perform_preinstall_checks_once
    formula_installers = primary_container.dependencies.filter_map do |dep|
      next unless dep.is_a?(Formula)
      next if dep.linked?

      FormulaInstaller.new(
        dep,
        **install_options,
      )
    end
    valid_formula_installers = Homebrew::Install.fetch_formulae(formula_installers)

    formula_installers.each do |fi|
      next unless valid_formula_installers.include?(fi)

      fi.install
      fi.finish
    end
  end

  # Extract the container to the temporary directory.
  primary_container.extract_nestedly(to: @tmpdir, basename: downloaded_path.basename, verbose: false)

  if (nested_container = @cask.container&.nested)
    FileUtils.chmod_R "+rw", @tmpdir/nested_container, force: true, verbose: false
    UnpackStrategy.detect(@tmpdir/nested_container, merge_xattrs: true)
                  .extract_nestedly(to: @tmpdir, verbose: false)
  end

  # Propagate quarantine attributes from the downloaded file to extracted contents.
  # This is necessary because some extraction tools (like 7zr) don't preserve xattrs.
  Quarantine.propagate(from: downloaded_path, to: @tmpdir)

  # Process rename operations after extraction
  # Create a temporary installer to process renames in the audit directory
  temp_installer = Installer.new(@cask)
  temp_installer.process_rename_operations(target_dir: @tmpdir)

  # Set the flag to indicate that extraction has occurred.
  @artifacts_extracted = T.let(true, T.nilable(TrueClass))

  # Yield the artifacts and temp directory to the block if provided.
  yield artifacts, @tmpdir if block_given?
end

#fix? ⇒ 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.

Returns:

  • (Boolean)


99
# File 'cask/audit.rb', line 99

def fix? = !!@fix

#new_cask? ⇒ 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.

Returns:

  • (Boolean)


87
# File 'cask/audit.rb', line 87

def new_cask? = !!@new_cask

#normalize_min_os(min_os) ⇒ MacOSVersion?

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:



269
270
271
272
273
274
275
276
277
# File 'cask/audit.rb', line 269

def normalize_min_os(min_os)
  return if min_os.nil?
  return if min_os.is_a?(String) && min_os.blank?

  min_os = MacOSVersion.new(min_os) unless min_os.is_a?(MacOSVersion)
  MacOSVersion.new(min_os.release_version)
rescue MacOSVersion::Error
  nil
end

#online? ⇒ 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.

Returns:

  • (Boolean)


90
# File 'cask/audit.rb', line 90

def online? =!!@online

#result ⇒ String?

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:



152
153
154
# File 'cask/audit.rb', line 152

def result
  Formatter.error("failed") if errors?
end

#run! ⇒ ::Cask::Audit

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:



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'cask/audit.rb', line 102

def run!
  only_audits = @only
  except_audits = @except

  public_methods.map(&:to_s).grep(/^audit_/).each do |audit_method_name|
    name = audit_method_name.delete_prefix("audit_")
    next if !only_audits.empty? && only_audits.exclude?(name)
    next if except_audits.include?(name)

    public_send(audit_method_name)
  end

  self
rescue => e
  odebug e, ::Utils::Backtrace.clean(e)
  add_error "exception while auditing #{cask}: #{e.message}"
  self
end

#signing? ⇒ 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.

Returns:

  • (Boolean)


93
# File 'cask/audit.rb', line 93

def signing? = !!@signing

#strict? ⇒ 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.

Returns:

  • (Boolean)


96
# File 'cask/audit.rb', line 96

def strict? = !!@strict

#success? ⇒ 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.

Returns:

  • (Boolean)


132
133
134
# File 'cask/audit.rb', line 132

def success?
  !errors?
end

#summary ⇒ String?

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:



157
158
159
160
161
162
163
164
165
166
167
# File 'cask/audit.rb', line 157

def summary
  return if success?

  summary = ["audit for #{cask}: #{result}"]

  errors.each do |error|
    summary << " #{Formatter.error("-")} #{error[:message]}"
  end

  summary.join("\n")
end