Skip to content

Commit

Permalink
unpack_strategy/*: Convert to Sorbet typed: strict
Browse files Browse the repository at this point in the history
  • Loading branch information
issyl0 committed Jul 12, 2024
1 parent bffb470 commit edb8055
Show file tree
Hide file tree
Showing 33 changed files with 92 additions and 47 deletions.
6 changes: 4 additions & 2 deletions Library/Homebrew/unpack_strategy/air.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true

module UnpackStrategy
Expand All @@ -11,13 +11,15 @@ def self.extensions
[".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]))

Check warning on line 22 in Library/Homebrew/unpack_strategy/air.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/unpack_strategy/air.rb#L22

Added line #L22 was not covered by tests
end

AIR_APPLICATION_INSTALLER =
Expand Down
5 changes: 3 additions & 2 deletions Library/Homebrew/unpack_strategy/bazaar.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# typed: true
# typed: strict
# frozen_string_literal: true

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
Expand Down
3 changes: 2 additions & 1 deletion Library/Homebrew/unpack_strategy/bzip2.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true

module UnpackStrategy
Expand All @@ -11,6 +11,7 @@ def self.extensions
[".bz2"]
end

sig { override.params(path: Pathname).returns(T::Boolean) }
def self.can_extract?(path)
path.magic_number.match?(/\ABZh/n)
end
Expand Down
6 changes: 4 additions & 2 deletions Library/Homebrew/unpack_strategy/cab.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true

module UnpackStrategy
Expand All @@ -11,6 +11,7 @@ def self.extensions
[".cab"]
end

sig { override.params(path: Pathname).returns(T::Boolean) }
def self.can_extract?(path)
path.magic_number.match?(/\AMSCF/n)
end
Expand All @@ -23,8 +24,9 @@ def extract_to_dir(unpack_dir, basename:, verbose:)
verbose:
end

sig { returns(T.nilable(T::Array[Formula])) }
def dependencies
@dependencies ||= [Formula["cabextract"]]
@dependencies ||= T.let([Formula["cabextract"]], T.nilable(T::Array[Formula]))

Check warning on line 29 in Library/Homebrew/unpack_strategy/cab.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/unpack_strategy/cab.rb#L29

Added line #L29 was not covered by tests
end
end
end
3 changes: 2 additions & 1 deletion Library/Homebrew/unpack_strategy/compress.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true

require_relative "tar"
Expand All @@ -11,6 +11,7 @@ def self.extensions
[".Z"]
end

sig { override.params(path: Pathname).returns(T::Boolean) }
def self.can_extract?(path)
path.magic_number.match?(/\A\037\235/n)
end
Expand Down
5 changes: 3 additions & 2 deletions Library/Homebrew/unpack_strategy/cvs.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# typed: true
# typed: strict
# frozen_string_literal: true

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
3 changes: 2 additions & 1 deletion Library/Homebrew/unpack_strategy/directory.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true

module UnpackStrategy
Expand All @@ -11,6 +11,7 @@ def self.extensions
[]
end

sig { override.params(path: Pathname).returns(T::Boolean) }
def self.can_extract?(path)
path.directory?
end
Expand Down
3 changes: 2 additions & 1 deletion Library/Homebrew/unpack_strategy/executable.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true

require_relative "uncompressed"
Expand All @@ -11,6 +11,7 @@ def self.extensions
[".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)
Expand Down
3 changes: 2 additions & 1 deletion Library/Homebrew/unpack_strategy/fossil.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true

require "system_command"
Expand All @@ -14,6 +14,7 @@ def self.extensions
[]
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)

Expand Down
6 changes: 4 additions & 2 deletions Library/Homebrew/unpack_strategy/generic_unar.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true

module UnpackStrategy
Expand All @@ -11,12 +11,14 @@ def self.extensions
[]
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]))

Check warning on line 21 in Library/Homebrew/unpack_strategy/generic_unar.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/unpack_strategy/generic_unar.rb#L21

Added line #L21 was not covered by tests
end

private
Expand Down
5 changes: 3 additions & 2 deletions Library/Homebrew/unpack_strategy/git.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# typed: true
# typed: strict
# frozen_string_literal: true

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
3 changes: 2 additions & 1 deletion Library/Homebrew/unpack_strategy/gzip.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true

module UnpackStrategy
Expand All @@ -11,6 +11,7 @@ def self.extensions
[".gz"]
end

sig { override.params(path: Pathname).returns(T::Boolean) }
def self.can_extract?(path)
path.magic_number.match?(/\A\037\213/n)
end
Expand Down
3 changes: 2 additions & 1 deletion Library/Homebrew/unpack_strategy/jar.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true

require_relative "uncompressed"
Expand All @@ -11,6 +11,7 @@ def self.extensions
[".apk", ".jar"]
end

sig { override.params(path: Pathname).returns(T::Boolean) }
def self.can_extract?(path)
return false unless Zip.can_extract?(path)

Expand Down
6 changes: 4 additions & 2 deletions Library/Homebrew/unpack_strategy/lha.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true

module UnpackStrategy
Expand All @@ -11,12 +11,14 @@ def self.extensions
[".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]))

Check warning on line 21 in Library/Homebrew/unpack_strategy/lha.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/unpack_strategy/lha.rb#L21

Added line #L21 was not covered by tests
end

private
Expand Down
3 changes: 2 additions & 1 deletion Library/Homebrew/unpack_strategy/lua_rock.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true

require_relative "uncompressed"
Expand All @@ -11,6 +11,7 @@ def self.extensions
[".rock"]
end

sig { override.params(path: Pathname).returns(T::Boolean) }
def self.can_extract?(path)
return false unless Zip.can_extract?(path)

Expand Down
6 changes: 4 additions & 2 deletions Library/Homebrew/unpack_strategy/lzip.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true

module UnpackStrategy
Expand All @@ -11,12 +11,14 @@ def self.extensions
[".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]))

Check warning on line 21 in Library/Homebrew/unpack_strategy/lzip.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/unpack_strategy/lzip.rb#L21

Added line #L21 was not covered by tests
end

private
Expand Down
6 changes: 4 additions & 2 deletions Library/Homebrew/unpack_strategy/lzma.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true

module UnpackStrategy
Expand All @@ -11,12 +11,14 @@ def self.extensions
[".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]))

Check warning on line 21 in Library/Homebrew/unpack_strategy/lzma.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/unpack_strategy/lzma.rb#L21

Added line #L21 was not covered by tests
end

private
Expand Down
6 changes: 4 additions & 2 deletions Library/Homebrew/unpack_strategy/mercurial.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# typed: true
# typed: strict
# frozen_string_literal: true

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],
Expand Down
3 changes: 2 additions & 1 deletion Library/Homebrew/unpack_strategy/microsoft_office_xml.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true

require_relative "uncompressed"
Expand All @@ -15,6 +15,7 @@ def self.extensions
]
end

sig { override.params(path: Pathname).returns(T::Boolean) }
def self.can_extract?(path)
return false unless Zip.can_extract?(path)

Expand Down
3 changes: 2 additions & 1 deletion Library/Homebrew/unpack_strategy/otf.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true

require_relative "uncompressed"
Expand All @@ -11,6 +11,7 @@ def self.extensions
[".otf"]
end

sig { override.params(path: Pathname).returns(T::Boolean) }
def self.can_extract?(path)
path.magic_number.match?(/\AOTTO/n)
end
Expand Down
6 changes: 4 additions & 2 deletions Library/Homebrew/unpack_strategy/p7zip.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true

module UnpackStrategy
Expand All @@ -11,12 +11,14 @@ def self.extensions
[".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]))

Check warning on line 21 in Library/Homebrew/unpack_strategy/p7zip.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/unpack_strategy/p7zip.rb#L21

Added line #L21 was not covered by tests
end

private
Expand Down
3 changes: 2 additions & 1 deletion Library/Homebrew/unpack_strategy/pax.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true

module UnpackStrategy
Expand All @@ -11,6 +11,7 @@ def self.extensions
[".pax"]
end

sig { override.params(_path: Pathname).returns(T::Boolean) }
def self.can_extract?(_path)
false
end
Expand Down
3 changes: 2 additions & 1 deletion Library/Homebrew/unpack_strategy/pkg.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# typed: true
# typed: strict
# frozen_string_literal: true

require_relative "uncompressed"
Expand All @@ -11,6 +11,7 @@ def self.extensions
[".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))
Expand Down
Loading

0 comments on commit edb8055

Please sign in to comment.