diff --git a/Library/Homebrew/cask/artifact/moved.rb b/Library/Homebrew/cask/artifact/moved.rb index d3c5331639b95f..b80e0a6ef7538c 100644 --- a/Library/Homebrew/cask/artifact/moved.rb +++ b/Library/Homebrew/cask/artifact/moved.rb @@ -180,7 +180,7 @@ def move_back(skip: false, force: false, adopt: false, command: nil, **options) def delete(target, force: false, successor: nil, command: nil, **_) ohai "Removing #{self.class.english_name} '#{target}'" - raise CaskError, "Cannot remove undeletable #{self.class.english_name}." if MacOS.undeletable?(target) + raise CaskError, "Cannot remove undeletable #{self.class.english_name}." if undeletable?(target) return unless Utils.path_occupied?(target) @@ -196,6 +196,10 @@ def delete(target, force: false, successor: nil, command: nil, **_) Utils.gain_permissions_remove(target, command:) end end + + def undeletable?(target); end end end end + +require "extend/os/cask/artifact/moved" diff --git a/Library/Homebrew/cask/config.rb b/Library/Homebrew/cask/config.rb index ae8c2539fb0aa3..8a53c7561003a6 100644 --- a/Library/Homebrew/cask/config.rb +++ b/Library/Homebrew/cask/config.rb @@ -30,14 +30,12 @@ class Config vst3_plugindir: "~/Library/Audio/Plug-Ins/VST3", screen_saverdir: "~/Library/Screen Savers", }.freeze, - T::Hash[Symbol, String], + T::Hash[Symbol, T.nilable(String)], ) sig { returns(T::Hash[Symbol, T.untyped]) } def self.defaults - { - languages: LazyObject.new { MacOS.languages }, - }.merge(DEFAULT_DIRS).freeze + DEFAULT_DIRS.freeze end sig { params(args: Homebrew::CLI::Args).returns(T.attached_class) } @@ -223,3 +221,5 @@ def to_json(*options) end end end + +require "extend/os/cask/config" diff --git a/Library/Homebrew/cask/installer.rb b/Library/Homebrew/cask/installer.rb index a0cdf8b74a6443..b28851bb72d161 100644 --- a/Library/Homebrew/cask/installer.rb +++ b/Library/Homebrew/cask/installer.rb @@ -76,6 +76,7 @@ def fetch(quiet: nil, timeout: nil) satisfy_cask_and_formula_dependencies end + sig { void } def stage odebug "Cask::Installer#stage" @@ -88,6 +89,7 @@ def stage raise e end + sig { void } def install start_time = Time.now odebug "Cask::Installer#install" @@ -134,6 +136,7 @@ def install raise end + sig { void } def check_deprecate_disable deprecate_disable_type = DeprecateDisable.type(@cask) return if deprecate_disable_type.nil? @@ -150,6 +153,7 @@ def check_deprecate_disable end end + sig { void } def check_conflicts return unless @cask.conflicts_with @@ -166,6 +170,7 @@ def check_conflicts end end + sig { void } def uninstall_existing_cask return unless @cask.installed? @@ -194,6 +199,7 @@ def download(quiet: nil, timeout: nil) timeout:) end + sig { void } def verify_has_sha odebug "Checking cask has checksum" return if @cask.sha256 != :no_check @@ -211,6 +217,12 @@ def primary_container end end + sig { returns(ArtifactSet) } + def artifacts + @cask.artifacts + end + + sig { params(to: Pathname).void } def extract_primary_container(to: @cask.staged_path) odebug "Extracting primary container" @@ -240,7 +252,6 @@ def extract_primary_container(to: @cask.staged_path) sig { params(predecessor: T.nilable(Cask)).void } def install_artifacts(predecessor: nil) - artifacts = @cask.artifacts already_installed_artifacts = [] odebug "Installing artifacts" @@ -299,6 +310,7 @@ def check_macos_requirements raise CaskError, @cask.depends_on.macos.message(type: :cask) end + sig { void } def check_arch_requirements return if @cask.depends_on.arch.nil? @@ -314,6 +326,7 @@ def check_arch_requirements "but you are running #{@current_arch}." end + sig { returns(T::Array[T.untyped]) } def cask_and_formula_dependencies return @cask_and_formula_dependencies if @cask_and_formula_dependencies @@ -487,8 +500,6 @@ def finalize_upgrade sig { params(clear: T::Boolean, successor: T.nilable(Cask)).void } def uninstall_artifacts(clear: false, successor: nil) - artifacts = @cask.artifacts - odebug "Uninstalling artifacts" odebug "#{::Utils.pluralize("artifact", artifacts.length, include_count: true)} defined", artifacts diff --git a/Library/Homebrew/cask/quarantine.rb b/Library/Homebrew/cask/quarantine.rb index 4a36a5128edac7..ae680b0d2321a6 100644 --- a/Library/Homebrew/cask/quarantine.rb +++ b/Library/Homebrew/cask/quarantine.rb @@ -266,3 +266,5 @@ def self.app_management_permissions_granted?(app:, command:) end end end + +require "extend/os/cask/quarantine" diff --git a/Library/Homebrew/extend/os/cask/artifact/moved.rb b/Library/Homebrew/extend/os/cask/artifact/moved.rb new file mode 100644 index 00000000000000..98d49e5904cbc1 --- /dev/null +++ b/Library/Homebrew/extend/os/cask/artifact/moved.rb @@ -0,0 +1,5 @@ +# typed: strict +# frozen_string_literal: true + +require "extend/os/mac/cask/artifact/moved" if OS.mac? +require "extend/os/linux/cask/artifact/moved" if OS.linux? diff --git a/Library/Homebrew/extend/os/cask/config.rb b/Library/Homebrew/extend/os/cask/config.rb new file mode 100644 index 00000000000000..300aef685dba1c --- /dev/null +++ b/Library/Homebrew/extend/os/cask/config.rb @@ -0,0 +1,5 @@ +# typed: strict +# frozen_string_literal: true + +require "extend/os/mac/cask/config" if OS.mac? +require "extend/os/linux/cask/config" if OS.linux? diff --git a/Library/Homebrew/extend/os/cask/quarantine.rb b/Library/Homebrew/extend/os/cask/quarantine.rb new file mode 100644 index 00000000000000..31671b65e5d352 --- /dev/null +++ b/Library/Homebrew/extend/os/cask/quarantine.rb @@ -0,0 +1,4 @@ +# typed: strict +# frozen_string_literal: true + +require "extend/os/linux/cask/quarantine" if OS.linux? diff --git a/Library/Homebrew/extend/os/linux/cask/artifact/moved.rb b/Library/Homebrew/extend/os/linux/cask/artifact/moved.rb new file mode 100644 index 00000000000000..9c2313f4a82669 --- /dev/null +++ b/Library/Homebrew/extend/os/linux/cask/artifact/moved.rb @@ -0,0 +1,23 @@ +# typed: strict +# frozen_string_literal: true + +module OS + module Linux + module Cask + module Artifact + module Moved + extend T::Helpers + + requires_ancestor { ::Cask::Artifact::Moved } + + sig { params(target: Pathname).returns(T::Boolean) } + def undeletable?(_target) + false + end + end + end + end + end +end + +Cask::Artifact::Moved.prepend(OS::Linux::Cask::Config) diff --git a/Library/Homebrew/extend/os/linux/cask/config.rb b/Library/Homebrew/extend/os/linux/cask/config.rb new file mode 100644 index 00000000000000..3f61727e875cad --- /dev/null +++ b/Library/Homebrew/extend/os/linux/cask/config.rb @@ -0,0 +1,43 @@ +# typed: strict +# frozen_string_literal: true + +require "os/linux" + +module OS + module Linux + module Cask + module Config + extend T::Helpers + + requires_ancestor { ::Cask::Config } + + DEFAULT_DIRS = T.let({ + vst_plugindir: "~/.vst", + vst3_plugindir: "~/.vst3", + fontdir: "#{ENV.fetch("XDG_DATA_HOME", "~/.local/share")}/fonts", + appdir: nil, + keyboard_layoutdir: nil, + colorpickerdir: nil, + prefpanedir: nil, + qlplugindir: nil, + mdimporterdir: nil, + servicedir: nil, + dictionarydir: nil, + screen_saverdir: nil, + input_methoddir: nil, + internet_plugindir: nil, + audio_unit_plugindir: nil, + }.freeze, T::Hash[Symbol, T.nilable(String)]) + + sig { returns(T::Hash[Symbol, T.untyped]) } + def self.defaults + { + languages: LazyObject.new { Linux.languages }, + }.merge(DEFAULT_DIRS).freeze + end + end + end + end +end + +Cask::Config.prepend(OS::Linux::Cask::Config) diff --git a/Library/Homebrew/extend/os/linux/cask/installer.rb b/Library/Homebrew/extend/os/linux/cask/installer.rb index 536a08b1f5590e..635f40bf39070d 100644 --- a/Library/Homebrew/extend/os/linux/cask/installer.rb +++ b/Library/Homebrew/extend/os/linux/cask/installer.rb @@ -13,7 +13,9 @@ module Installer sig { void } def check_stanza_os_requirements - raise ::Cask::CaskError, "macOS is required for this software." + raise ::Cask::CaskError, "macOS is required for this software." unless artifacts.reject do |k| + k.is_a?(::Cask::Artifact::Font) + end.empty? end end end diff --git a/Library/Homebrew/extend/os/linux/cask/quarantine.rb b/Library/Homebrew/extend/os/linux/cask/quarantine.rb new file mode 100644 index 00000000000000..0fbed2ac4d2244 --- /dev/null +++ b/Library/Homebrew/extend/os/linux/cask/quarantine.rb @@ -0,0 +1,26 @@ +# typed: strict +# frozen_string_literal: true + +module OS + module Linux + module Cask + module Quarantine + extend T::Helpers + + requires_ancestor { ::Cask::Quarantine } + + sig { returns(Symbol) } + def self.check_quarantine_support + :linux + end + + sig { returns(T::Boolean) } + def self.available? + false + end + end + end + end +end + +Cask::Quarantine.prepend(OS::Linux::Cask::Quarantine) diff --git a/Library/Homebrew/extend/os/mac/cask/artifact/moved.rb b/Library/Homebrew/extend/os/mac/cask/artifact/moved.rb new file mode 100644 index 00000000000000..f235220788779c --- /dev/null +++ b/Library/Homebrew/extend/os/mac/cask/artifact/moved.rb @@ -0,0 +1,25 @@ +# typed: strict +# frozen_string_literal: true + +require "cask/macos" + +module OS + module Mac + module Cask + module Artifact + module Moved + extend T::Helpers + + requires_ancestor { ::Cask::Artifact::Moved } + + sig { params(target: Pathname).returns(T::Boolean) } + def undeletable?(target) + MacOS.undeletable?(target) + end + end + end + end + end +end + +Cask::Artifact::Moved.prepend(OS::Mac::Cask::Config) diff --git a/Library/Homebrew/extend/os/mac/cask/config.rb b/Library/Homebrew/extend/os/mac/cask/config.rb new file mode 100644 index 00000000000000..9fe386bdd457ae --- /dev/null +++ b/Library/Homebrew/extend/os/mac/cask/config.rb @@ -0,0 +1,46 @@ +# typed: strict +# frozen_string_literal: true + +require "cask/macos" + +module OS + module Mac + module Cask + module Config + extend T::Helpers + + requires_ancestor { ::Cask::Config } + + DEFAULT_DIRS = T.let( + { + appdir: "/Applications", + keyboard_layoutdir: "/Library/Keyboard Layouts", + colorpickerdir: "~/Library/ColorPickers", + prefpanedir: "~/Library/PreferencePanes", + qlplugindir: "~/Library/QuickLook", + mdimporterdir: "~/Library/Spotlight", + dictionarydir: "~/Library/Dictionaries", + fontdir: "~/Library/Fonts", + servicedir: "~/Library/Services", + input_methoddir: "~/Library/Input Methods", + internet_plugindir: "~/Library/Internet Plug-Ins", + audio_unit_plugindir: "~/Library/Audio/Plug-Ins/Components", + vst_plugindir: "~/Library/Audio/Plug-Ins/VST", + vst3_plugindir: "~/Library/Audio/Plug-Ins/VST3", + screen_saverdir: "~/Library/Screen Savers", + }.freeze, + T::Hash[Symbol, String], + ) + + sig { returns(T::Hash[Symbol, T.untyped]) } + def self.defaults + { + languages: LazyObject.new { MacOS.languages }, + }.merge(DEFAULT_DIRS).freeze + end + end + end + end +end + +Cask::Config.prepend(OS::Mac::Cask::Config) diff --git a/Library/Homebrew/os/linux.rb b/Library/Homebrew/os/linux.rb index e8f48328437070..dc10cc8658af49 100644 --- a/Library/Homebrew/os/linux.rb +++ b/Library/Homebrew/os/linux.rb @@ -56,5 +56,14 @@ def self.wsl_version Version::NULL end end + + def self.languages + return @languages if @languages + + os_langs = Utils.popen_read("localectl", "list-locales") + os_langs = os_langs.scan(/[^ \n"(),]+/).map { |item| item.split(".").first.tr("_", "-") } + + @languages = os_langs + end end end