unpack_strategy/*: Convert to Sorbet typed: strict

This commit is contained in:
Issy Long 2024-07-11 19:57:12 +01:00
parent bffb470c57
commit edb8055c76
No known key found for this signature in database
33 changed files with 92 additions and 47 deletions

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
module UnpackStrategy
@ -11,13 +11,15 @@ module UnpackStrategy
[".air"]
end
sig { override.params(path: Pathname).returns(T::Boolean) }
def self.can_extract?(path)
mime_type = "application/vnd.adobe.air-application-installer-package+zip"
path.magic_number.match?(/.{59}#{Regexp.escape(mime_type)}/)
end
sig { returns(T.nilable(T::Array[Cask::Cask])) }
def dependencies
@dependencies ||= [Cask::CaskLoader.load("adobe-air")]
@dependencies ||= T.let([Cask::CaskLoader.load("adobe-air")], T.nilable(T::Array[Cask::Cask]))
end
AIR_APPLICATION_INSTALLER =

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
require_relative "directory"
@ -6,8 +6,9 @@ require_relative "directory"
module UnpackStrategy
# Strategy for unpacking Bazaar archives.
class Bazaar < Directory
sig { override.params(path: Pathname).returns(T::Boolean) }
def self.can_extract?(path)
super && (path/".bzr").directory?
!!(super && (path/".bzr").directory?)
end
private

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
module UnpackStrategy
@ -11,6 +11,7 @@ module UnpackStrategy
[".bz2"]
end
sig { override.params(path: Pathname).returns(T::Boolean) }
def self.can_extract?(path)
path.magic_number.match?(/\ABZh/n)
end

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
module UnpackStrategy
@ -11,6 +11,7 @@ module UnpackStrategy
[".cab"]
end
sig { override.params(path: Pathname).returns(T::Boolean) }
def self.can_extract?(path)
path.magic_number.match?(/\AMSCF/n)
end
@ -23,8 +24,9 @@ module UnpackStrategy
verbose:
end
sig { returns(T.nilable(T::Array[Formula])) }
def dependencies
@dependencies ||= [Formula["cabextract"]]
@dependencies ||= T.let([Formula["cabextract"]], T.nilable(T::Array[Formula]))
end
end
end

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
require_relative "tar"
@ -11,6 +11,7 @@ module UnpackStrategy
[".Z"]
end
sig { override.params(path: Pathname).returns(T::Boolean) }
def self.can_extract?(path)
path.magic_number.match?(/\A\037\235/n)
end

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
require_relative "directory"
@ -6,8 +6,9 @@ require_relative "directory"
module UnpackStrategy
# Strategy for unpacking CVS repositories.
class Cvs < Directory
sig { override.params(path: Pathname).returns(T::Boolean) }
def self.can_extract?(path)
super && (path/"CVS").directory?
!!(super && (path/"CVS").directory?)
end
end
end

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
module UnpackStrategy
@ -11,6 +11,7 @@ module UnpackStrategy
[]
end
sig { override.params(path: Pathname).returns(T::Boolean) }
def self.can_extract?(path)
path.directory?
end

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
require_relative "uncompressed"
@ -11,6 +11,7 @@ module UnpackStrategy
[".sh", ".bash"]
end
sig { override.params(path: Pathname).returns(T::Boolean) }
def self.can_extract?(path)
path.magic_number.match?(/\A#!\s*\S+/n) ||
path.magic_number.match?(/\AMZ/n)

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
require "system_command"
@ -14,6 +14,7 @@ module UnpackStrategy
[]
end
sig { override.params(path: Pathname).returns(T::Boolean) }
def self.can_extract?(path)
return false unless path.magic_number.match?(/\ASQLite format 3\000/n)

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
module UnpackStrategy
@ -11,12 +11,14 @@ module UnpackStrategy
[]
end
sig { override.params(_path: Pathname).returns(T::Boolean) }
def self.can_extract?(_path)
false
end
sig { returns(T.nilable(T::Array[Formula])) }
def dependencies
@dependencies ||= [Formula["unar"]]
@dependencies ||= T.let([Formula["unar"]], T.nilable(T::Array[Formula]))
end
private

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
require_relative "directory"
@ -6,8 +6,9 @@ require_relative "directory"
module UnpackStrategy
# Strategy for unpacking Git repositories.
class Git < Directory
sig { override.params(path: Pathname).returns(T::Boolean) }
def self.can_extract?(path)
super && (path/".git").directory?
!!(super && (path/".git").directory?)
end
end
end

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
module UnpackStrategy
@ -11,6 +11,7 @@ module UnpackStrategy
[".gz"]
end
sig { override.params(path: Pathname).returns(T::Boolean) }
def self.can_extract?(path)
path.magic_number.match?(/\A\037\213/n)
end

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
require_relative "uncompressed"
@ -11,6 +11,7 @@ module UnpackStrategy
[".apk", ".jar"]
end
sig { override.params(path: Pathname).returns(T::Boolean) }
def self.can_extract?(path)
return false unless Zip.can_extract?(path)

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
module UnpackStrategy
@ -11,12 +11,14 @@ module UnpackStrategy
[".lha", ".lzh"]
end
sig { override.params(path: Pathname).returns(T::Boolean) }
def self.can_extract?(path)
path.magic_number.match?(/\A..-(lh0|lh1|lz4|lz5|lzs|lh\\40|lhd|lh2|lh3|lh4|lh5)-/n)
end
sig { returns(T.nilable(T::Array[Formula])) }
def dependencies
@dependencies ||= [Formula["lha"]]
@dependencies ||= T.let([Formula["lha"]], T.nilable(T::Array[Formula]))
end
private

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
require_relative "uncompressed"
@ -11,6 +11,7 @@ module UnpackStrategy
[".rock"]
end
sig { override.params(path: Pathname).returns(T::Boolean) }
def self.can_extract?(path)
return false unless Zip.can_extract?(path)

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
module UnpackStrategy
@ -11,12 +11,14 @@ module UnpackStrategy
[".lz"]
end
sig { override.params(path: Pathname).returns(T::Boolean) }
def self.can_extract?(path)
path.magic_number.match?(/\ALZIP/n)
end
sig { returns(T.nilable(T::Array[Formula])) }
def dependencies
@dependencies ||= [Formula["lzip"]]
@dependencies ||= T.let([Formula["lzip"]], T.nilable(T::Array[Formula]))
end
private

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
module UnpackStrategy
@ -11,12 +11,14 @@ module UnpackStrategy
[".lzma"]
end
sig { override.params(path: Pathname).returns(T::Boolean) }
def self.can_extract?(path)
path.magic_number.match?(/\A\]\000\000\200\000/n)
end
sig { returns(T.nilable(T::Array[Formula])) }
def dependencies
@dependencies ||= [Formula["xz"]]
@dependencies ||= T.let([Formula["xz"]], T.nilable(T::Array[Formula]))
end
private

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
require_relative "directory"
@ -6,12 +6,14 @@ require_relative "directory"
module UnpackStrategy
# Strategy for unpacking Mercurial repositories.
class Mercurial < Directory
sig { override.params(path: Pathname).returns(T::Boolean) }
def self.can_extract?(path)
super && (path/".hg").directory?
!!(super && (path/".hg").directory?)
end
private
sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void }
def extract_to_dir(unpack_dir, basename:, verbose:)
system_command! "hg",
args: ["--cwd", path, "archive", "--subrepos", "-y", "-t", "files", unpack_dir],

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
require_relative "uncompressed"
@ -15,6 +15,7 @@ module UnpackStrategy
]
end
sig { override.params(path: Pathname).returns(T::Boolean) }
def self.can_extract?(path)
return false unless Zip.can_extract?(path)

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
require_relative "uncompressed"
@ -11,6 +11,7 @@ module UnpackStrategy
[".otf"]
end
sig { override.params(path: Pathname).returns(T::Boolean) }
def self.can_extract?(path)
path.magic_number.match?(/\AOTTO/n)
end

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
module UnpackStrategy
@ -11,12 +11,14 @@ module UnpackStrategy
[".7z"]
end
sig { override.params(path: Pathname).returns(T::Boolean) }
def self.can_extract?(path)
path.magic_number.match?(/\A7z\xBC\xAF\x27\x1C/n)
end
sig { returns(T.nilable(T::Array[Formula])) }
def dependencies
@dependencies ||= [Formula["p7zip"]]
@dependencies ||= T.let([Formula["p7zip"]], T.nilable(T::Array[Formula]))
end
private

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
module UnpackStrategy
@ -11,6 +11,7 @@ module UnpackStrategy
[".pax"]
end
sig { override.params(_path: Pathname).returns(T::Boolean) }
def self.can_extract?(_path)
false
end

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
require_relative "uncompressed"
@ -11,6 +11,7 @@ module UnpackStrategy
[".pkg", ".mkpg"]
end
sig { override.params(path: Pathname).returns(T::Boolean) }
def self.can_extract?(path)
path.extname.match?(/\A.m?pkg\Z/) &&
(path.directory? || path.magic_number.match?(/\Axar!/n))

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
module UnpackStrategy
@ -11,12 +11,14 @@ module UnpackStrategy
[".rar"]
end
sig { override.params(path: Pathname).returns(T::Boolean) }
def self.can_extract?(path)
path.magic_number.match?(/\ARar!/n)
end
sig { returns(T.nilable(T::Array[Formula])) }
def dependencies
@dependencies ||= [Formula["libarchive"]]
@dependencies ||= T.let([Formula["libarchive"]], T.nilable(T::Array[Formula]))
end
private

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
require_relative "generic_unar"
@ -11,6 +11,7 @@ module UnpackStrategy
[]
end
sig { override.params(path: Pathname).returns(T::Boolean) }
def self.can_extract?(path)
path.magic_number.match?(/\AMZ/n) &&
path.file_type.include?("self-extracting archive")

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
require_relative "generic_unar"
@ -11,6 +11,7 @@ module UnpackStrategy
[".sit"]
end
sig { override.params(path: Pathname).returns(T::Boolean) }
def self.can_extract?(path)
path.magic_number.match?(/\AStuffIt/n)
end

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
require_relative "directory"
@ -6,12 +6,14 @@ require_relative "directory"
module UnpackStrategy
# Strategy for unpacking Subversion repositories.
class Subversion < Directory
sig { override.params(path: Pathname).returns(T::Boolean) }
def self.can_extract?(path)
super && (path/".svn").directory?
!!(super && (path/".svn").directory?)
end
private
sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).void }
def extract_to_dir(unpack_dir, basename:, verbose:)
system_command! "svn",
args: ["export", "--force", ".", unpack_dir],

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
require "system_command"
@ -22,6 +22,7 @@ module UnpackStrategy
]
end
sig { override.params(path: Pathname).returns(T::Boolean) }
def self.can_extract?(path)
return true if path.magic_number.match?(/\A.{257}ustar/n)

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
require_relative "uncompressed"
@ -11,6 +11,7 @@ module UnpackStrategy
[".ttc", ".ttf"]
end
sig { override.params(path: Pathname).returns(T::Boolean) }
def self.can_extract?(path)
# TrueType Font
path.magic_number.match?(/\A\000\001\000\000\000/n) ||

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
module UnpackStrategy
@ -11,6 +11,7 @@ module UnpackStrategy
[".xar"]
end
sig { override.params(path: Pathname).returns(T::Boolean) }
def self.can_extract?(path)
path.magic_number.match?(/\Axar!/n)
end

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
module UnpackStrategy
@ -11,12 +11,14 @@ module UnpackStrategy
[".xz"]
end
sig { override.params(path: Pathname).returns(T::Boolean) }
def self.can_extract?(path)
path.magic_number.match?(/\A\xFD7zXZ\x00/n)
end
sig { returns(T.nilable(T::Array[Formula])) }
def dependencies
@dependencies ||= [Formula["xz"]]
@dependencies ||= T.let([Formula["xz"]], T.nilable(T::Array[Formula]))
end
private

View File

@ -23,6 +23,7 @@ module UnpackStrategy
.returns(SystemCommand::Result)
}
def extract_to_dir(unpack_dir, basename:, verbose:)
odebug "in unpack_strategy, zip, extract_to_dir, verbose: #{verbose.inspect}"
unzip = if which("unzip").blank?
begin
Formula["unzip"]

View File

@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true
module UnpackStrategy
@ -11,12 +11,14 @@ module UnpackStrategy
[".zst"]
end
sig { override.params(path: Pathname).returns(T::Boolean) }
def self.can_extract?(path)
path.magic_number.match?(/\x28\xB5\x2F\xFD/n)
end
sig { returns(T.nilable(T::Array[Formula])) }
def dependencies
@dependencies ||= [Formula["zstd"]]
@dependencies ||= T.let([Formula["zstd"]], T.nilable(T::Array[Formula]))
end
private