feat: allow font install on linux

Apply suggestions from code review

Co-authored-by: Douglas Eichelberger <697964+dduugg@users.noreply.github.com>

feat: add linux appdir

Apply suggestions from code review

Co-authored-by: Douglas Eichelberger <697964+dduugg@users.noreply.github.com>
This commit is contained in:
Sean Molenaar 2024-12-04 22:49:14 +01:00
parent 4d3fedfd63
commit c34b71655c
15 changed files with 153 additions and 7 deletions

View File

@ -180,7 +180,7 @@ module Cask
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 @@ module Cask
Utils.gain_permissions_remove(target, command:)
end
end
def undeletable?(target); end
end
end
end
require "extend/os/cask/artifact/moved"

View File

@ -33,10 +33,10 @@ module Cask
T::Hash[Symbol, String],
)
sig { returns(T::Hash[Symbol, T.untyped]) }
sig { returns(T::Hash[Symbol, String]) }
def self.defaults
{
languages: LazyObject.new { MacOS.languages },
languages: LazyObject.new { ::OS::Mac.languages },
}.merge(DEFAULT_DIRS).freeze
end
@ -223,3 +223,5 @@ module Cask
end
end
end
require "extend/os/cask/config"

View File

@ -76,6 +76,7 @@ module Cask
satisfy_cask_and_formula_dependencies
end
sig { void }
def stage
odebug "Cask::Installer#stage"
@ -88,6 +89,7 @@ module Cask
raise e
end
sig { void }
def install
start_time = Time.now
odebug "Cask::Installer#install"
@ -152,6 +154,7 @@ on_request: true)
end
end
sig { void }
def check_conflicts
return unless @cask.conflicts_with
@ -168,6 +171,7 @@ on_request: true)
end
end
sig { void }
def uninstall_existing_cask
return unless @cask.installed?
@ -196,6 +200,7 @@ on_request: true)
timeout:)
end
sig { void }
def verify_has_sha
odebug "Checking cask has checksum"
return if @cask.sha256 != :no_check
@ -213,6 +218,12 @@ on_request: true)
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"
@ -242,7 +253,6 @@ on_request: true)
sig { params(predecessor: T.nilable(Cask)).void }
def install_artifacts(predecessor: nil)
artifacts = @cask.artifacts
already_installed_artifacts = []
odebug "Installing artifacts"
@ -301,6 +311,7 @@ on_request: true)
raise CaskError, @cask.depends_on.macos.message(type: :cask)
end
sig { void }
def check_arch_requirements
return if @cask.depends_on.arch.nil?
@ -316,6 +327,7 @@ on_request: true)
"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
@ -489,8 +501,6 @@ on_request: true)
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

View File

@ -266,3 +266,5 @@ module Cask
end
end
end
require "extend/os/cask/quarantine"

View File

@ -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?

View File

@ -0,0 +1,4 @@
# typed: strict
# frozen_string_literal: true
require "extend/os/linux/cask/config" if OS.linux?

View File

@ -0,0 +1,4 @@
# typed: strict
# frozen_string_literal: true
require "extend/os/linux/cask/quarantine" if OS.linux?

View File

@ -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)
!target.parent.writable?
end
end
end
end
end
end
Cask::Artifact::Moved.prepend(OS::Linux::Cask::Config)

View File

@ -0,0 +1,30 @@
# typed: strict
# frozen_string_literal: true
require "os/linux"
module OS
module Linux
module Cask
module Config
module ClassMethods
DEFAULT_DIRS = T.let({
vst_plugindir: "~/.vst",
vst3_plugindir: "~/.vst3",
fontdir: "#{ENV.fetch("XDG_DATA_HOME", "~/.local/share")}/fonts",
appdir: "~/.config/apps",
}.freeze, T::Hash[Symbol, String])
sig { returns(T::Hash[Symbol, String]) }
def defaults
{
languages: LazyObject.new { Linux.languages },
}.merge(DEFAULT_DIRS).freeze
end
end
end
end
end
end
Cask::Config.singleton_class.prepend(OS::Linux::Cask::Config::ClassMethods)

View File

@ -13,6 +13,8 @@ module OS
sig { void }
def check_stanza_os_requirements
return if artifacts.all?(::Cask::Artifact::Font)
raise ::Cask::CaskError, "macOS is required for this software."
end
end

View File

@ -0,0 +1,22 @@
# 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
sig { returns(T::Boolean) }
def self.available? = false
end
end
end
end
Cask::Quarantine.prepend(OS::Linux::Cask::Quarantine)

View File

@ -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::Artifact::Moved)

View File

@ -20,7 +20,7 @@ module OS
success = T.let(true, T::Boolean)
tap.cask_files.each do |file|
cask = Cask::CaskLoader.load(file)
cask = ::Cask::CaskLoader.load(file)
# Fine to have missing URLs for unsupported macOS
macos_req = cask.depends_on.macos

View File

@ -13,6 +13,8 @@ module OS
raise "Loaded OS::Linux on macOS!" if OS.mac?
# rubocop:enable Homebrew/MoveToExtendOS
@languages = T.let([], T::Array[String])
# Get the OS version.
#
# @api internal
@ -56,5 +58,15 @@ module OS
Version::NULL
end
end
sig { returns(T::Array[String]) }
def self.languages
return @languages if @languages.present?
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

View File

@ -69,6 +69,7 @@ module OS
end
end
sig { returns(T::Array[String]) }
def self.languages
return @languages if @languages