From 82dc57dfea50f43c10b5e5fa4a990563ef693cb9 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Mon, 20 Mar 2023 13:15:43 -0700 Subject: [PATCH 1/5] Enable UnpackStrategy types --- Library/Homebrew/extend/object.rbi | 6 + .../extend/os/mac/unpack_strategy/zip.rb | 2 +- Library/Homebrew/extend/pathname.rb | 22 +++ Library/Homebrew/unpack_strategy.rb | 70 ++------- Library/Homebrew/unpack_strategy/air.rb | 2 - Library/Homebrew/unpack_strategy/bazaar.rb | 2 +- Library/Homebrew/unpack_strategy/bzip2.rb | 2 +- Library/Homebrew/unpack_strategy/cab.rb | 2 +- Library/Homebrew/unpack_strategy/compress.rb | 2 +- Library/Homebrew/unpack_strategy/cvs.rb | 2 +- Library/Homebrew/unpack_strategy/directory.rb | 2 +- Library/Homebrew/unpack_strategy/dmg.rb | 136 +++++++++--------- .../Homebrew/unpack_strategy/executable.rb | 2 +- Library/Homebrew/unpack_strategy/fossil.rb | 2 +- .../Homebrew/unpack_strategy/generic_unar.rb | 2 +- Library/Homebrew/unpack_strategy/git.rb | 2 +- Library/Homebrew/unpack_strategy/gzip.rb | 2 +- Library/Homebrew/unpack_strategy/jar.rb | 2 +- Library/Homebrew/unpack_strategy/lha.rb | 2 +- Library/Homebrew/unpack_strategy/lua_rock.rb | 2 +- Library/Homebrew/unpack_strategy/lzip.rb | 2 +- Library/Homebrew/unpack_strategy/lzma.rb | 2 +- Library/Homebrew/unpack_strategy/mercurial.rb | 2 +- .../unpack_strategy/microsoft_office_xml.rb | 2 +- Library/Homebrew/unpack_strategy/otf.rb | 2 +- Library/Homebrew/unpack_strategy/p7zip.rb | 2 +- Library/Homebrew/unpack_strategy/pax.rb | 2 +- Library/Homebrew/unpack_strategy/pkg.rb | 2 +- Library/Homebrew/unpack_strategy/rar.rb | 2 +- .../self_extracting_executable.rb | 2 +- Library/Homebrew/unpack_strategy/sit.rb | 2 +- .../Homebrew/unpack_strategy/subversion.rb | 2 +- Library/Homebrew/unpack_strategy/tar.rb | 2 +- Library/Homebrew/unpack_strategy/ttf.rb | 2 +- Library/Homebrew/unpack_strategy/xar.rb | 2 +- Library/Homebrew/unpack_strategy/xz.rb | 2 +- Library/Homebrew/unpack_strategy/zip.rb | 2 +- Library/Homebrew/unpack_strategy/zstd.rb | 2 +- 38 files changed, 142 insertions(+), 160 deletions(-) create mode 100644 Library/Homebrew/extend/object.rbi diff --git a/Library/Homebrew/extend/object.rbi b/Library/Homebrew/extend/object.rbi new file mode 100644 index 0000000000..cc39405568 --- /dev/null +++ b/Library/Homebrew/extend/object.rbi @@ -0,0 +1,6 @@ +# typed: strict + +class Object + sig { returns(T::Boolean) } + def present?; end +end diff --git a/Library/Homebrew/extend/os/mac/unpack_strategy/zip.rb b/Library/Homebrew/extend/os/mac/unpack_strategy/zip.rb index 65585d3cd0..edd4d0f041 100644 --- a/Library/Homebrew/extend/os/mac/unpack_strategy/zip.rb +++ b/Library/Homebrew/extend/os/mac/unpack_strategy/zip.rb @@ -11,7 +11,7 @@ module UnpackStrategy include UnpackStrategy include SystemCommand::Mixin - using Magic + sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } def extract_to_dir(unpack_dir, basename:, verbose:) diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb index 28bd016628..643d01b305 100644 --- a/Library/Homebrew/extend/pathname.rb +++ b/Library/Homebrew/extend/pathname.rb @@ -466,6 +466,28 @@ class Pathname def rpaths [] end + + def magic_number + @magic_number ||= if directory? + "" + else + # Length of the longest regex (currently Tar). + # The `T.let` is a workaround until we have https://github.com/sorbet/sorbet/pull/6865 + T.let(binread(262), T.nilable(String)) || "" + end + end + + def file_type + @file_type ||= system_command("file", args: ["-b", self], print_stderr: false) + .stdout.chomp + end + + def zipinfo + @zipinfo ||= system_command("zipinfo", args: ["-1", self], print_stderr: false) + .stdout + .encode(Encoding::UTF_8, invalid: :replace) + .split("\n") + end end require "extend/os/pathname" diff --git a/Library/Homebrew/unpack_strategy.rb b/Library/Homebrew/unpack_strategy.rb index b7572d18e7..20f3353d43 100644 --- a/Library/Homebrew/unpack_strategy.rb +++ b/Library/Homebrew/unpack_strategy.rb @@ -1,29 +1,8 @@ -# typed: false +# typed: true # frozen_string_literal: true require "system_command" -# Helper module for iterating over directory trees. -# -# @api private -module PathnameEachDirectory - refine Pathname do - extend T::Sig - - sig { - type_parameters(:T) - .params( - _block: T.proc.params(path: Pathname).returns(T.type_parameter(:T)), - ).returns(T.type_parameter(:T)) - } - def each_directory(&_block) - find do |path| - yield path if path.directory? - end - end - end -end - # Module containing all available strategies for unpacking archives. # # @api private @@ -33,38 +12,6 @@ module UnpackStrategy include SystemCommand::Mixin - using PathnameEachDirectory - - # Helper module for identifying the file type. - module Magic - # Length of the longest regex (currently Tar). - MAX_MAGIC_NUMBER_LENGTH = 262 - private_constant :MAX_MAGIC_NUMBER_LENGTH - - refine Pathname do - def magic_number - @magic_number ||= if directory? - "" - else - binread(MAX_MAGIC_NUMBER_LENGTH) || "" - end - end - - def file_type - @file_type ||= system_command("file", args: ["-b", self], print_stderr: false) - .stdout.chomp - end - - def zipinfo - @zipinfo ||= system_command("zipinfo", args: ["-1", self], print_stderr: false) - .stdout - .encode(Encoding::UTF_8, invalid: :replace) - .split("\n") - end - end - end - private_constant :Magic - def self.strategies @strategies ||= [ Tar, # Needs to be before Bzip2/Gzip/Xz/Lzma/Zstd. @@ -195,7 +142,7 @@ module UnpackStrategy end # Ensure all extracted directories are writable. - tmp_unpack_dir.each_directory do |path| + each_directory(tmp_unpack_dir) do |path| next if path.writable? FileUtils.chmod "u+w", path, verbose: verbose @@ -208,6 +155,19 @@ module UnpackStrategy def dependencies [] end + + # Helper method for iterating over directory trees. + sig { + params( + pathname: Pathname, + _block: T.proc.params(path: Pathname).void, + ).returns(T.nilable(Pathname)) + } + def each_directory(pathname, &_block) + pathname.find do |path| + yield path if path.directory? + end + end end require "unpack_strategy/air" diff --git a/Library/Homebrew/unpack_strategy/air.rb b/Library/Homebrew/unpack_strategy/air.rb index 9f8bd8c473..aac0881fa8 100644 --- a/Library/Homebrew/unpack_strategy/air.rb +++ b/Library/Homebrew/unpack_strategy/air.rb @@ -8,8 +8,6 @@ module UnpackStrategy include UnpackStrategy - using Magic - sig { returns(T::Array[String]) } def self.extensions [".air"] diff --git a/Library/Homebrew/unpack_strategy/bazaar.rb b/Library/Homebrew/unpack_strategy/bazaar.rb index 12fbd503d0..301b61b196 100644 --- a/Library/Homebrew/unpack_strategy/bazaar.rb +++ b/Library/Homebrew/unpack_strategy/bazaar.rb @@ -8,7 +8,7 @@ module UnpackStrategy class Bazaar < Directory extend T::Sig - using Magic + def self.can_extract?(path) super && (path/".bzr").directory? diff --git a/Library/Homebrew/unpack_strategy/bzip2.rb b/Library/Homebrew/unpack_strategy/bzip2.rb index 6b05e4dc15..b030a9ccb9 100644 --- a/Library/Homebrew/unpack_strategy/bzip2.rb +++ b/Library/Homebrew/unpack_strategy/bzip2.rb @@ -8,7 +8,7 @@ module UnpackStrategy include UnpackStrategy - using Magic + sig { returns(T::Array[String]) } def self.extensions diff --git a/Library/Homebrew/unpack_strategy/cab.rb b/Library/Homebrew/unpack_strategy/cab.rb index 82265231d5..3ac8bb88e6 100644 --- a/Library/Homebrew/unpack_strategy/cab.rb +++ b/Library/Homebrew/unpack_strategy/cab.rb @@ -8,7 +8,7 @@ module UnpackStrategy include UnpackStrategy - using Magic + sig { returns(T::Array[String]) } def self.extensions diff --git a/Library/Homebrew/unpack_strategy/compress.rb b/Library/Homebrew/unpack_strategy/compress.rb index 65f9ea8728..c9cbac5a1c 100644 --- a/Library/Homebrew/unpack_strategy/compress.rb +++ b/Library/Homebrew/unpack_strategy/compress.rb @@ -8,7 +8,7 @@ module UnpackStrategy class Compress < Tar extend T::Sig - using Magic + sig { returns(T::Array[String]) } def self.extensions diff --git a/Library/Homebrew/unpack_strategy/cvs.rb b/Library/Homebrew/unpack_strategy/cvs.rb index 66c2f17f8f..5e61d86202 100644 --- a/Library/Homebrew/unpack_strategy/cvs.rb +++ b/Library/Homebrew/unpack_strategy/cvs.rb @@ -6,7 +6,7 @@ require_relative "directory" module UnpackStrategy # Strategy for unpacking CVS repositories. class Cvs < Directory - using Magic + def self.can_extract?(path) super && (path/"CVS").directory? diff --git a/Library/Homebrew/unpack_strategy/directory.rb b/Library/Homebrew/unpack_strategy/directory.rb index 02772dcc68..4af36d9cbd 100644 --- a/Library/Homebrew/unpack_strategy/directory.rb +++ b/Library/Homebrew/unpack_strategy/directory.rb @@ -8,7 +8,7 @@ module UnpackStrategy include UnpackStrategy - using Magic + sig { returns(T::Array[String]) } def self.extensions diff --git a/Library/Homebrew/unpack_strategy/dmg.rb b/Library/Homebrew/unpack_strategy/dmg.rb index 66c9f32fe7..6891ad1ad5 100644 --- a/Library/Homebrew/unpack_strategy/dmg.rb +++ b/Library/Homebrew/unpack_strategy/dmg.rb @@ -1,4 +1,4 @@ -# typed: false +# typed: true # frozen_string_literal: true require "tempfile" @@ -12,6 +12,8 @@ module UnpackStrategy # Helper module for listing the contents of a volume mounted from a disk image. module Bom + extend T::Sig + DMG_METADATA = Set.new(%w[ .background .com.apple.timemachine.donotpresent @@ -35,106 +37,100 @@ module UnpackStrategy end end - refine Pathname do - extend T::Sig + # Check if path is considered disk image metadata. + sig { params(pathname: Pathname).returns(T::Boolean) } + def self.dmg_metadata?(pathname) + DMG_METADATA.include?(pathname.cleanpath.ascend.to_a.last.to_s) + end - # Check if path is considered disk image metadata. - sig { returns(T::Boolean) } - def dmg_metadata? - DMG_METADATA.include?(cleanpath.ascend.to_a.last.to_s) + # Check if path is a symlink to a system directory (commonly to /Applications). + sig { params(pathname: Pathname).returns(T::Boolean) } + def self.system_dir_symlink?(pathname) + pathname.symlink? && MacOS.system_dir?(pathname.dirname.join(pathname.readlink)) + end + + sig { params(pathname: Pathname).returns(String) } + def self.bom(pathname) + tries = 0 + result = loop do + # We need to use `find` here instead of Ruby in order to properly handle + # file names containing special characters, such as “e” + “´” vs. “é”. + r = system_command("find", args: [".", "-print0"], chdir: pathname, print_stderr: false) + tries += 1 + + # Spurious bug on CI, which in most cases can be worked around by retrying. + break r unless r.stderr.match?(/Interrupted system call/i) + + raise "Command `#{r.command.shelljoin}` was interrupted." if tries >= 3 end - # Check if path is a symlink to a system directory (commonly to /Applications). - sig { returns(T::Boolean) } - def system_dir_symlink? - symlink? && MacOS.system_dir?(dirname.join(readlink)) - end + odebug "Command `#{result.command.shelljoin}` in '#{pathname}' took #{tries} tries." if tries > 1 - sig { returns(String) } - def bom - tries = 0 - result = loop do - # We need to use `find` here instead of Ruby in order to properly handle - # file names containing special characters, such as “e” + “´” vs. “é”. - r = system_command("find", args: [".", "-print0"], chdir: self, print_stderr: false) - tries += 1 + bom_paths = result.stdout.split("\0") - # Spurious bug on CI, which in most cases can be worked around by retrying. - break r unless r.stderr.match?(/Interrupted system call/i) + raise EmptyError, pathname if bom_paths.empty? - raise "Command `#{r.command.shelljoin}` was interrupted." if tries >= 3 - end - - odebug "Command `#{result.command.shelljoin}` in '#{self}' took #{tries} tries." if tries > 1 - - bom_paths = result.stdout.split("\0") - - raise EmptyError, self if bom_paths.empty? - - bom_paths - .reject { |path| Pathname(path).dmg_metadata? } - .reject { |path| (self/path).system_dir_symlink? } - .join("\n") - end + bom_paths + .reject { |path| dmg_metadata?(Pathname(path)) } + .reject { |path| system_dir_symlink?(pathname/path) } + .join("\n") end end - private_constant :Bom # Strategy for unpacking a volume mounted from a disk image. class Mount extend T::Sig - using Bom include UnpackStrategy def eject(verbose: false) - tries ||= 3 + tries = 3 + begin + return unless path.exist? - return unless path.exist? + if tries > 1 + disk_info = system_command!( + "diskutil", + args: ["info", "-plist", path], + print_stderr: false, + verbose: verbose, + ) - if tries > 1 - disk_info = system_command!( - "diskutil", - args: ["info", "-plist", path], - print_stderr: false, - verbose: verbose, - ) + # For HFS, just use + # For APFS, find the corresponding to + eject_paths = disk_info.plist + .fetch("APFSPhysicalStores", []) + .map { |store| store["APFSPhysicalStore"] } + .compact + .presence || [path] - # For HFS, just use - # For APFS, find the corresponding to - eject_paths = disk_info.plist - .fetch("APFSPhysicalStores", []) - .map { |store| store["APFSPhysicalStore"] } - .compact - .presence || [path] - - eject_paths.each do |eject_path| + eject_paths.each do |eject_path| + system_command! "diskutil", + args: ["eject", eject_path], + print_stderr: false, + verbose: verbose + end + else system_command! "diskutil", - args: ["eject", eject_path], + args: ["unmount", "force", path], print_stderr: false, verbose: verbose end - else - system_command! "diskutil", - args: ["unmount", "force", path], - print_stderr: false, - verbose: verbose - end - rescue ErrorDuringExecution => e - raise e if (tries -= 1).zero? + rescue ErrorDuringExecution => e + raise e if (tries -= 1).zero? - sleep 1 - retry + sleep 1 + retry + end end private sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } def extract_to_dir(unpack_dir, basename:, verbose:) + tries = 3 bom = begin - tries ||= 3 - - path.bom + Bom.bom(path) rescue Bom::EmptyError => e raise e if (tries -= 1).zero? diff --git a/Library/Homebrew/unpack_strategy/executable.rb b/Library/Homebrew/unpack_strategy/executable.rb index 1daeb7d0f7..3a749bc845 100644 --- a/Library/Homebrew/unpack_strategy/executable.rb +++ b/Library/Homebrew/unpack_strategy/executable.rb @@ -8,7 +8,7 @@ module UnpackStrategy class Executable < Uncompressed extend T::Sig - using Magic + sig { returns(T::Array[String]) } def self.extensions diff --git a/Library/Homebrew/unpack_strategy/fossil.rb b/Library/Homebrew/unpack_strategy/fossil.rb index ddaf147795..b7abec13ae 100644 --- a/Library/Homebrew/unpack_strategy/fossil.rb +++ b/Library/Homebrew/unpack_strategy/fossil.rb @@ -11,7 +11,7 @@ module UnpackStrategy include UnpackStrategy extend SystemCommand::Mixin - using Magic + sig { returns(T::Array[String]) } def self.extensions diff --git a/Library/Homebrew/unpack_strategy/generic_unar.rb b/Library/Homebrew/unpack_strategy/generic_unar.rb index 0322d5c9ef..af19520cb7 100644 --- a/Library/Homebrew/unpack_strategy/generic_unar.rb +++ b/Library/Homebrew/unpack_strategy/generic_unar.rb @@ -8,7 +8,7 @@ module UnpackStrategy include UnpackStrategy - using Magic + sig { returns(T::Array[String]) } def self.extensions diff --git a/Library/Homebrew/unpack_strategy/git.rb b/Library/Homebrew/unpack_strategy/git.rb index 23257c0502..fbed22cc38 100644 --- a/Library/Homebrew/unpack_strategy/git.rb +++ b/Library/Homebrew/unpack_strategy/git.rb @@ -6,7 +6,7 @@ require_relative "directory" module UnpackStrategy # Strategy for unpacking Git repositories. class Git < Directory - using Magic + def self.can_extract?(path) super && (path/".git").directory? diff --git a/Library/Homebrew/unpack_strategy/gzip.rb b/Library/Homebrew/unpack_strategy/gzip.rb index 983d995a98..777b0a62c4 100644 --- a/Library/Homebrew/unpack_strategy/gzip.rb +++ b/Library/Homebrew/unpack_strategy/gzip.rb @@ -8,7 +8,7 @@ module UnpackStrategy include UnpackStrategy - using Magic + sig { returns(T::Array[String]) } def self.extensions diff --git a/Library/Homebrew/unpack_strategy/jar.rb b/Library/Homebrew/unpack_strategy/jar.rb index d4170a8689..867274d505 100644 --- a/Library/Homebrew/unpack_strategy/jar.rb +++ b/Library/Homebrew/unpack_strategy/jar.rb @@ -8,7 +8,7 @@ module UnpackStrategy class Jar < Uncompressed extend T::Sig - using Magic + sig { returns(T::Array[String]) } def self.extensions diff --git a/Library/Homebrew/unpack_strategy/lha.rb b/Library/Homebrew/unpack_strategy/lha.rb index 543f4e4540..b6811d2519 100644 --- a/Library/Homebrew/unpack_strategy/lha.rb +++ b/Library/Homebrew/unpack_strategy/lha.rb @@ -8,7 +8,7 @@ module UnpackStrategy include UnpackStrategy - using Magic + sig { returns(T::Array[String]) } def self.extensions diff --git a/Library/Homebrew/unpack_strategy/lua_rock.rb b/Library/Homebrew/unpack_strategy/lua_rock.rb index 6150e2788e..56623e115d 100644 --- a/Library/Homebrew/unpack_strategy/lua_rock.rb +++ b/Library/Homebrew/unpack_strategy/lua_rock.rb @@ -8,7 +8,7 @@ module UnpackStrategy class LuaRock < Uncompressed extend T::Sig - using Magic + sig { returns(T::Array[String]) } def self.extensions diff --git a/Library/Homebrew/unpack_strategy/lzip.rb b/Library/Homebrew/unpack_strategy/lzip.rb index da8a991b9e..cd4565ce93 100644 --- a/Library/Homebrew/unpack_strategy/lzip.rb +++ b/Library/Homebrew/unpack_strategy/lzip.rb @@ -8,7 +8,7 @@ module UnpackStrategy include UnpackStrategy - using Magic + sig { returns(T::Array[String]) } def self.extensions diff --git a/Library/Homebrew/unpack_strategy/lzma.rb b/Library/Homebrew/unpack_strategy/lzma.rb index 7ef147b61b..a5a4540796 100644 --- a/Library/Homebrew/unpack_strategy/lzma.rb +++ b/Library/Homebrew/unpack_strategy/lzma.rb @@ -8,7 +8,7 @@ module UnpackStrategy include UnpackStrategy - using Magic + sig { returns(T::Array[String]) } def self.extensions diff --git a/Library/Homebrew/unpack_strategy/mercurial.rb b/Library/Homebrew/unpack_strategy/mercurial.rb index cc27a11395..835e38cdc8 100644 --- a/Library/Homebrew/unpack_strategy/mercurial.rb +++ b/Library/Homebrew/unpack_strategy/mercurial.rb @@ -6,7 +6,7 @@ require_relative "directory" module UnpackStrategy # Strategy for unpacking Mercurial repositories. class Mercurial < Directory - using Magic + def self.can_extract?(path) super && (path/".hg").directory? diff --git a/Library/Homebrew/unpack_strategy/microsoft_office_xml.rb b/Library/Homebrew/unpack_strategy/microsoft_office_xml.rb index 616d78bc06..0c831d8f6e 100644 --- a/Library/Homebrew/unpack_strategy/microsoft_office_xml.rb +++ b/Library/Homebrew/unpack_strategy/microsoft_office_xml.rb @@ -8,7 +8,7 @@ module UnpackStrategy class MicrosoftOfficeXml < Uncompressed extend T::Sig - using Magic + sig { returns(T::Array[String]) } def self.extensions diff --git a/Library/Homebrew/unpack_strategy/otf.rb b/Library/Homebrew/unpack_strategy/otf.rb index e94eb15029..29557f99d9 100644 --- a/Library/Homebrew/unpack_strategy/otf.rb +++ b/Library/Homebrew/unpack_strategy/otf.rb @@ -8,7 +8,7 @@ module UnpackStrategy class Otf < Uncompressed extend T::Sig - using Magic + sig { returns(T::Array[String]) } def self.extensions diff --git a/Library/Homebrew/unpack_strategy/p7zip.rb b/Library/Homebrew/unpack_strategy/p7zip.rb index 618ea06f23..36dc862d8a 100644 --- a/Library/Homebrew/unpack_strategy/p7zip.rb +++ b/Library/Homebrew/unpack_strategy/p7zip.rb @@ -8,7 +8,7 @@ module UnpackStrategy include UnpackStrategy - using Magic + sig { returns(T::Array[String]) } def self.extensions diff --git a/Library/Homebrew/unpack_strategy/pax.rb b/Library/Homebrew/unpack_strategy/pax.rb index 4067132c80..4b5ec1ad33 100644 --- a/Library/Homebrew/unpack_strategy/pax.rb +++ b/Library/Homebrew/unpack_strategy/pax.rb @@ -8,7 +8,7 @@ module UnpackStrategy include UnpackStrategy - using Magic + sig { returns(T::Array[String]) } def self.extensions diff --git a/Library/Homebrew/unpack_strategy/pkg.rb b/Library/Homebrew/unpack_strategy/pkg.rb index 220b86a58c..5d1837d9da 100644 --- a/Library/Homebrew/unpack_strategy/pkg.rb +++ b/Library/Homebrew/unpack_strategy/pkg.rb @@ -8,7 +8,7 @@ module UnpackStrategy class Pkg < Uncompressed extend T::Sig - using Magic + sig { returns(T::Array[String]) } def self.extensions diff --git a/Library/Homebrew/unpack_strategy/rar.rb b/Library/Homebrew/unpack_strategy/rar.rb index bd2b8042bb..3f23099844 100644 --- a/Library/Homebrew/unpack_strategy/rar.rb +++ b/Library/Homebrew/unpack_strategy/rar.rb @@ -8,7 +8,7 @@ module UnpackStrategy include UnpackStrategy - using Magic + sig { returns(T::Array[String]) } def self.extensions diff --git a/Library/Homebrew/unpack_strategy/self_extracting_executable.rb b/Library/Homebrew/unpack_strategy/self_extracting_executable.rb index 0e99278711..67f2d820f3 100644 --- a/Library/Homebrew/unpack_strategy/self_extracting_executable.rb +++ b/Library/Homebrew/unpack_strategy/self_extracting_executable.rb @@ -8,7 +8,7 @@ module UnpackStrategy class SelfExtractingExecutable < GenericUnar extend T::Sig - using Magic + sig { returns(T::Array[String]) } def self.extensions diff --git a/Library/Homebrew/unpack_strategy/sit.rb b/Library/Homebrew/unpack_strategy/sit.rb index 687e7d0e64..ac04355bf5 100644 --- a/Library/Homebrew/unpack_strategy/sit.rb +++ b/Library/Homebrew/unpack_strategy/sit.rb @@ -8,7 +8,7 @@ module UnpackStrategy class Sit < GenericUnar extend T::Sig - using Magic + sig { returns(T::Array[String]) } def self.extensions diff --git a/Library/Homebrew/unpack_strategy/subversion.rb b/Library/Homebrew/unpack_strategy/subversion.rb index dd3355825b..d20fe5664b 100644 --- a/Library/Homebrew/unpack_strategy/subversion.rb +++ b/Library/Homebrew/unpack_strategy/subversion.rb @@ -6,7 +6,7 @@ require_relative "directory" module UnpackStrategy # Strategy for unpacking Subversion repositories. class Subversion < Directory - using Magic + def self.can_extract?(path) super && (path/".svn").directory? diff --git a/Library/Homebrew/unpack_strategy/tar.rb b/Library/Homebrew/unpack_strategy/tar.rb index 9b0797cfa1..e9641f936a 100644 --- a/Library/Homebrew/unpack_strategy/tar.rb +++ b/Library/Homebrew/unpack_strategy/tar.rb @@ -11,7 +11,7 @@ module UnpackStrategy include UnpackStrategy extend SystemCommand::Mixin - using Magic + sig { returns(T::Array[String]) } def self.extensions diff --git a/Library/Homebrew/unpack_strategy/ttf.rb b/Library/Homebrew/unpack_strategy/ttf.rb index 38b44879de..17588ce827 100644 --- a/Library/Homebrew/unpack_strategy/ttf.rb +++ b/Library/Homebrew/unpack_strategy/ttf.rb @@ -8,7 +8,7 @@ module UnpackStrategy class Ttf < Uncompressed extend T::Sig - using Magic + sig { returns(T::Array[String]) } def self.extensions diff --git a/Library/Homebrew/unpack_strategy/xar.rb b/Library/Homebrew/unpack_strategy/xar.rb index ce35a0683a..db223e4b10 100644 --- a/Library/Homebrew/unpack_strategy/xar.rb +++ b/Library/Homebrew/unpack_strategy/xar.rb @@ -8,7 +8,7 @@ module UnpackStrategy include UnpackStrategy - using Magic + sig { returns(T::Array[String]) } def self.extensions diff --git a/Library/Homebrew/unpack_strategy/xz.rb b/Library/Homebrew/unpack_strategy/xz.rb index 61e1b2c3ab..71894af646 100644 --- a/Library/Homebrew/unpack_strategy/xz.rb +++ b/Library/Homebrew/unpack_strategy/xz.rb @@ -8,7 +8,7 @@ module UnpackStrategy include UnpackStrategy - using Magic + sig { returns(T::Array[String]) } def self.extensions diff --git a/Library/Homebrew/unpack_strategy/zip.rb b/Library/Homebrew/unpack_strategy/zip.rb index c8925c96c6..9495e4ac66 100644 --- a/Library/Homebrew/unpack_strategy/zip.rb +++ b/Library/Homebrew/unpack_strategy/zip.rb @@ -8,7 +8,7 @@ module UnpackStrategy include UnpackStrategy - using Magic + sig { returns(T::Array[String]) } def self.extensions diff --git a/Library/Homebrew/unpack_strategy/zstd.rb b/Library/Homebrew/unpack_strategy/zstd.rb index 4e77184977..ab256ea5ac 100644 --- a/Library/Homebrew/unpack_strategy/zstd.rb +++ b/Library/Homebrew/unpack_strategy/zstd.rb @@ -8,7 +8,7 @@ module UnpackStrategy include UnpackStrategy - using Magic + sig { returns(T::Array[String]) } def self.extensions From f38a672938a9e288a694f0d4e21076332ac026e3 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Mon, 20 Mar 2023 13:16:31 -0700 Subject: [PATCH 2/5] brew style --fix --- Library/Homebrew/extend/os/mac/unpack_strategy/zip.rb | 2 -- Library/Homebrew/unpack_strategy.rb | 6 +++--- Library/Homebrew/unpack_strategy/bazaar.rb | 2 -- Library/Homebrew/unpack_strategy/bzip2.rb | 2 -- Library/Homebrew/unpack_strategy/cab.rb | 2 -- Library/Homebrew/unpack_strategy/compress.rb | 2 -- Library/Homebrew/unpack_strategy/cvs.rb | 2 -- Library/Homebrew/unpack_strategy/directory.rb | 2 -- Library/Homebrew/unpack_strategy/dmg.rb | 8 ++++---- Library/Homebrew/unpack_strategy/executable.rb | 2 -- Library/Homebrew/unpack_strategy/fossil.rb | 2 -- Library/Homebrew/unpack_strategy/generic_unar.rb | 2 -- Library/Homebrew/unpack_strategy/git.rb | 2 -- Library/Homebrew/unpack_strategy/gzip.rb | 2 -- Library/Homebrew/unpack_strategy/jar.rb | 2 -- Library/Homebrew/unpack_strategy/lha.rb | 2 -- Library/Homebrew/unpack_strategy/lua_rock.rb | 2 -- Library/Homebrew/unpack_strategy/lzip.rb | 2 -- Library/Homebrew/unpack_strategy/lzma.rb | 2 -- Library/Homebrew/unpack_strategy/mercurial.rb | 2 -- Library/Homebrew/unpack_strategy/microsoft_office_xml.rb | 2 -- Library/Homebrew/unpack_strategy/otf.rb | 2 -- Library/Homebrew/unpack_strategy/p7zip.rb | 2 -- Library/Homebrew/unpack_strategy/pax.rb | 2 -- Library/Homebrew/unpack_strategy/pkg.rb | 2 -- Library/Homebrew/unpack_strategy/rar.rb | 2 -- .../unpack_strategy/self_extracting_executable.rb | 2 -- Library/Homebrew/unpack_strategy/sit.rb | 2 -- Library/Homebrew/unpack_strategy/subversion.rb | 2 -- Library/Homebrew/unpack_strategy/tar.rb | 2 -- Library/Homebrew/unpack_strategy/ttf.rb | 2 -- Library/Homebrew/unpack_strategy/xar.rb | 2 -- Library/Homebrew/unpack_strategy/xz.rb | 2 -- Library/Homebrew/unpack_strategy/zip.rb | 2 -- Library/Homebrew/unpack_strategy/zstd.rb | 2 -- 35 files changed, 7 insertions(+), 73 deletions(-) diff --git a/Library/Homebrew/extend/os/mac/unpack_strategy/zip.rb b/Library/Homebrew/extend/os/mac/unpack_strategy/zip.rb index edd4d0f041..cff64f5802 100644 --- a/Library/Homebrew/extend/os/mac/unpack_strategy/zip.rb +++ b/Library/Homebrew/extend/os/mac/unpack_strategy/zip.rb @@ -11,8 +11,6 @@ module UnpackStrategy include UnpackStrategy include SystemCommand::Mixin - - sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) } def extract_to_dir(unpack_dir, basename:, verbose:) with_env(TZ: "UTC") do diff --git a/Library/Homebrew/unpack_strategy.rb b/Library/Homebrew/unpack_strategy.rb index 20f3353d43..8a29604b93 100644 --- a/Library/Homebrew/unpack_strategy.rb +++ b/Library/Homebrew/unpack_strategy.rb @@ -159,9 +159,9 @@ module UnpackStrategy # Helper method for iterating over directory trees. sig { params( - pathname: Pathname, - _block: T.proc.params(path: Pathname).void, - ).returns(T.nilable(Pathname)) + pathname: Pathname, + _block: T.proc.params(path: Pathname).void, + ).returns(T.nilable(Pathname)) } def each_directory(pathname, &_block) pathname.find do |path| diff --git a/Library/Homebrew/unpack_strategy/bazaar.rb b/Library/Homebrew/unpack_strategy/bazaar.rb index 301b61b196..62eb0c4946 100644 --- a/Library/Homebrew/unpack_strategy/bazaar.rb +++ b/Library/Homebrew/unpack_strategy/bazaar.rb @@ -8,8 +8,6 @@ module UnpackStrategy class Bazaar < Directory extend T::Sig - - def self.can_extract?(path) super && (path/".bzr").directory? end diff --git a/Library/Homebrew/unpack_strategy/bzip2.rb b/Library/Homebrew/unpack_strategy/bzip2.rb index b030a9ccb9..82e9501b6a 100644 --- a/Library/Homebrew/unpack_strategy/bzip2.rb +++ b/Library/Homebrew/unpack_strategy/bzip2.rb @@ -8,8 +8,6 @@ module UnpackStrategy include UnpackStrategy - - sig { returns(T::Array[String]) } def self.extensions [".bz2"] diff --git a/Library/Homebrew/unpack_strategy/cab.rb b/Library/Homebrew/unpack_strategy/cab.rb index 3ac8bb88e6..de2258af88 100644 --- a/Library/Homebrew/unpack_strategy/cab.rb +++ b/Library/Homebrew/unpack_strategy/cab.rb @@ -8,8 +8,6 @@ module UnpackStrategy include UnpackStrategy - - sig { returns(T::Array[String]) } def self.extensions [".cab"] diff --git a/Library/Homebrew/unpack_strategy/compress.rb b/Library/Homebrew/unpack_strategy/compress.rb index c9cbac5a1c..0cc11abbd7 100644 --- a/Library/Homebrew/unpack_strategy/compress.rb +++ b/Library/Homebrew/unpack_strategy/compress.rb @@ -8,8 +8,6 @@ module UnpackStrategy class Compress < Tar extend T::Sig - - sig { returns(T::Array[String]) } def self.extensions [".Z"] diff --git a/Library/Homebrew/unpack_strategy/cvs.rb b/Library/Homebrew/unpack_strategy/cvs.rb index 5e61d86202..af6f0a3a77 100644 --- a/Library/Homebrew/unpack_strategy/cvs.rb +++ b/Library/Homebrew/unpack_strategy/cvs.rb @@ -6,8 +6,6 @@ require_relative "directory" module UnpackStrategy # Strategy for unpacking CVS repositories. class Cvs < Directory - - def self.can_extract?(path) super && (path/"CVS").directory? end diff --git a/Library/Homebrew/unpack_strategy/directory.rb b/Library/Homebrew/unpack_strategy/directory.rb index 4af36d9cbd..f20b9a566e 100644 --- a/Library/Homebrew/unpack_strategy/directory.rb +++ b/Library/Homebrew/unpack_strategy/directory.rb @@ -8,8 +8,6 @@ module UnpackStrategy include UnpackStrategy - - sig { returns(T::Array[String]) } def self.extensions [] diff --git a/Library/Homebrew/unpack_strategy/dmg.rb b/Library/Homebrew/unpack_strategy/dmg.rb index 6891ad1ad5..cb3ee47d12 100644 --- a/Library/Homebrew/unpack_strategy/dmg.rb +++ b/Library/Homebrew/unpack_strategy/dmg.rb @@ -99,10 +99,10 @@ module UnpackStrategy # For HFS, just use # For APFS, find the corresponding to eject_paths = disk_info.plist - .fetch("APFSPhysicalStores", []) - .map { |store| store["APFSPhysicalStore"] } - .compact - .presence || [path] + .fetch("APFSPhysicalStores", []) + .map { |store| store["APFSPhysicalStore"] } + .compact + .presence || [path] eject_paths.each do |eject_path| system_command! "diskutil", diff --git a/Library/Homebrew/unpack_strategy/executable.rb b/Library/Homebrew/unpack_strategy/executable.rb index 3a749bc845..6bf45599ed 100644 --- a/Library/Homebrew/unpack_strategy/executable.rb +++ b/Library/Homebrew/unpack_strategy/executable.rb @@ -8,8 +8,6 @@ module UnpackStrategy class Executable < Uncompressed extend T::Sig - - sig { returns(T::Array[String]) } def self.extensions [".sh", ".bash"] diff --git a/Library/Homebrew/unpack_strategy/fossil.rb b/Library/Homebrew/unpack_strategy/fossil.rb index b7abec13ae..a09218cf77 100644 --- a/Library/Homebrew/unpack_strategy/fossil.rb +++ b/Library/Homebrew/unpack_strategy/fossil.rb @@ -11,8 +11,6 @@ module UnpackStrategy include UnpackStrategy extend SystemCommand::Mixin - - sig { returns(T::Array[String]) } def self.extensions [] diff --git a/Library/Homebrew/unpack_strategy/generic_unar.rb b/Library/Homebrew/unpack_strategy/generic_unar.rb index af19520cb7..a860f8ec6b 100644 --- a/Library/Homebrew/unpack_strategy/generic_unar.rb +++ b/Library/Homebrew/unpack_strategy/generic_unar.rb @@ -8,8 +8,6 @@ module UnpackStrategy include UnpackStrategy - - sig { returns(T::Array[String]) } def self.extensions [] diff --git a/Library/Homebrew/unpack_strategy/git.rb b/Library/Homebrew/unpack_strategy/git.rb index fbed22cc38..ab39f3c4e0 100644 --- a/Library/Homebrew/unpack_strategy/git.rb +++ b/Library/Homebrew/unpack_strategy/git.rb @@ -6,8 +6,6 @@ require_relative "directory" module UnpackStrategy # Strategy for unpacking Git repositories. class Git < Directory - - def self.can_extract?(path) super && (path/".git").directory? end diff --git a/Library/Homebrew/unpack_strategy/gzip.rb b/Library/Homebrew/unpack_strategy/gzip.rb index 777b0a62c4..dbc70d2766 100644 --- a/Library/Homebrew/unpack_strategy/gzip.rb +++ b/Library/Homebrew/unpack_strategy/gzip.rb @@ -8,8 +8,6 @@ module UnpackStrategy include UnpackStrategy - - sig { returns(T::Array[String]) } def self.extensions [".gz"] diff --git a/Library/Homebrew/unpack_strategy/jar.rb b/Library/Homebrew/unpack_strategy/jar.rb index 867274d505..21153d1c2b 100644 --- a/Library/Homebrew/unpack_strategy/jar.rb +++ b/Library/Homebrew/unpack_strategy/jar.rb @@ -8,8 +8,6 @@ module UnpackStrategy class Jar < Uncompressed extend T::Sig - - sig { returns(T::Array[String]) } def self.extensions [".apk", ".jar"] diff --git a/Library/Homebrew/unpack_strategy/lha.rb b/Library/Homebrew/unpack_strategy/lha.rb index b6811d2519..a8cdfdb4cf 100644 --- a/Library/Homebrew/unpack_strategy/lha.rb +++ b/Library/Homebrew/unpack_strategy/lha.rb @@ -8,8 +8,6 @@ module UnpackStrategy include UnpackStrategy - - sig { returns(T::Array[String]) } def self.extensions [".lha", ".lzh"] diff --git a/Library/Homebrew/unpack_strategy/lua_rock.rb b/Library/Homebrew/unpack_strategy/lua_rock.rb index 56623e115d..d5ce7de33e 100644 --- a/Library/Homebrew/unpack_strategy/lua_rock.rb +++ b/Library/Homebrew/unpack_strategy/lua_rock.rb @@ -8,8 +8,6 @@ module UnpackStrategy class LuaRock < Uncompressed extend T::Sig - - sig { returns(T::Array[String]) } def self.extensions [".rock"] diff --git a/Library/Homebrew/unpack_strategy/lzip.rb b/Library/Homebrew/unpack_strategy/lzip.rb index cd4565ce93..d1f2c432af 100644 --- a/Library/Homebrew/unpack_strategy/lzip.rb +++ b/Library/Homebrew/unpack_strategy/lzip.rb @@ -8,8 +8,6 @@ module UnpackStrategy include UnpackStrategy - - sig { returns(T::Array[String]) } def self.extensions [".lz"] diff --git a/Library/Homebrew/unpack_strategy/lzma.rb b/Library/Homebrew/unpack_strategy/lzma.rb index a5a4540796..bfe04be2c9 100644 --- a/Library/Homebrew/unpack_strategy/lzma.rb +++ b/Library/Homebrew/unpack_strategy/lzma.rb @@ -8,8 +8,6 @@ module UnpackStrategy include UnpackStrategy - - sig { returns(T::Array[String]) } def self.extensions [".lzma"] diff --git a/Library/Homebrew/unpack_strategy/mercurial.rb b/Library/Homebrew/unpack_strategy/mercurial.rb index 835e38cdc8..72d9547933 100644 --- a/Library/Homebrew/unpack_strategy/mercurial.rb +++ b/Library/Homebrew/unpack_strategy/mercurial.rb @@ -6,8 +6,6 @@ require_relative "directory" module UnpackStrategy # Strategy for unpacking Mercurial repositories. class Mercurial < Directory - - def self.can_extract?(path) super && (path/".hg").directory? end diff --git a/Library/Homebrew/unpack_strategy/microsoft_office_xml.rb b/Library/Homebrew/unpack_strategy/microsoft_office_xml.rb index 0c831d8f6e..ad3940d86e 100644 --- a/Library/Homebrew/unpack_strategy/microsoft_office_xml.rb +++ b/Library/Homebrew/unpack_strategy/microsoft_office_xml.rb @@ -8,8 +8,6 @@ module UnpackStrategy class MicrosoftOfficeXml < Uncompressed extend T::Sig - - sig { returns(T::Array[String]) } def self.extensions [ diff --git a/Library/Homebrew/unpack_strategy/otf.rb b/Library/Homebrew/unpack_strategy/otf.rb index 29557f99d9..61ac40a249 100644 --- a/Library/Homebrew/unpack_strategy/otf.rb +++ b/Library/Homebrew/unpack_strategy/otf.rb @@ -8,8 +8,6 @@ module UnpackStrategy class Otf < Uncompressed extend T::Sig - - sig { returns(T::Array[String]) } def self.extensions [".otf"] diff --git a/Library/Homebrew/unpack_strategy/p7zip.rb b/Library/Homebrew/unpack_strategy/p7zip.rb index 36dc862d8a..715c816076 100644 --- a/Library/Homebrew/unpack_strategy/p7zip.rb +++ b/Library/Homebrew/unpack_strategy/p7zip.rb @@ -8,8 +8,6 @@ module UnpackStrategy include UnpackStrategy - - sig { returns(T::Array[String]) } def self.extensions [".7z"] diff --git a/Library/Homebrew/unpack_strategy/pax.rb b/Library/Homebrew/unpack_strategy/pax.rb index 4b5ec1ad33..c454b57ab4 100644 --- a/Library/Homebrew/unpack_strategy/pax.rb +++ b/Library/Homebrew/unpack_strategy/pax.rb @@ -8,8 +8,6 @@ module UnpackStrategy include UnpackStrategy - - sig { returns(T::Array[String]) } def self.extensions [".pax"] diff --git a/Library/Homebrew/unpack_strategy/pkg.rb b/Library/Homebrew/unpack_strategy/pkg.rb index 5d1837d9da..7151ba6078 100644 --- a/Library/Homebrew/unpack_strategy/pkg.rb +++ b/Library/Homebrew/unpack_strategy/pkg.rb @@ -8,8 +8,6 @@ module UnpackStrategy class Pkg < Uncompressed extend T::Sig - - sig { returns(T::Array[String]) } def self.extensions [".pkg", ".mkpg"] diff --git a/Library/Homebrew/unpack_strategy/rar.rb b/Library/Homebrew/unpack_strategy/rar.rb index 3f23099844..9a2be11326 100644 --- a/Library/Homebrew/unpack_strategy/rar.rb +++ b/Library/Homebrew/unpack_strategy/rar.rb @@ -8,8 +8,6 @@ module UnpackStrategy include UnpackStrategy - - sig { returns(T::Array[String]) } def self.extensions [".rar"] diff --git a/Library/Homebrew/unpack_strategy/self_extracting_executable.rb b/Library/Homebrew/unpack_strategy/self_extracting_executable.rb index 67f2d820f3..a3ea1e8de1 100644 --- a/Library/Homebrew/unpack_strategy/self_extracting_executable.rb +++ b/Library/Homebrew/unpack_strategy/self_extracting_executable.rb @@ -8,8 +8,6 @@ module UnpackStrategy class SelfExtractingExecutable < GenericUnar extend T::Sig - - sig { returns(T::Array[String]) } def self.extensions [] diff --git a/Library/Homebrew/unpack_strategy/sit.rb b/Library/Homebrew/unpack_strategy/sit.rb index ac04355bf5..d747cb3178 100644 --- a/Library/Homebrew/unpack_strategy/sit.rb +++ b/Library/Homebrew/unpack_strategy/sit.rb @@ -8,8 +8,6 @@ module UnpackStrategy class Sit < GenericUnar extend T::Sig - - sig { returns(T::Array[String]) } def self.extensions [".sit"] diff --git a/Library/Homebrew/unpack_strategy/subversion.rb b/Library/Homebrew/unpack_strategy/subversion.rb index d20fe5664b..4097f13610 100644 --- a/Library/Homebrew/unpack_strategy/subversion.rb +++ b/Library/Homebrew/unpack_strategy/subversion.rb @@ -6,8 +6,6 @@ require_relative "directory" module UnpackStrategy # Strategy for unpacking Subversion repositories. class Subversion < Directory - - def self.can_extract?(path) super && (path/".svn").directory? end diff --git a/Library/Homebrew/unpack_strategy/tar.rb b/Library/Homebrew/unpack_strategy/tar.rb index e9641f936a..42ca323d33 100644 --- a/Library/Homebrew/unpack_strategy/tar.rb +++ b/Library/Homebrew/unpack_strategy/tar.rb @@ -11,8 +11,6 @@ module UnpackStrategy include UnpackStrategy extend SystemCommand::Mixin - - sig { returns(T::Array[String]) } def self.extensions [ diff --git a/Library/Homebrew/unpack_strategy/ttf.rb b/Library/Homebrew/unpack_strategy/ttf.rb index 17588ce827..bd0da5ea76 100644 --- a/Library/Homebrew/unpack_strategy/ttf.rb +++ b/Library/Homebrew/unpack_strategy/ttf.rb @@ -8,8 +8,6 @@ module UnpackStrategy class Ttf < Uncompressed extend T::Sig - - sig { returns(T::Array[String]) } def self.extensions [".ttc", ".ttf"] diff --git a/Library/Homebrew/unpack_strategy/xar.rb b/Library/Homebrew/unpack_strategy/xar.rb index db223e4b10..4707a602d5 100644 --- a/Library/Homebrew/unpack_strategy/xar.rb +++ b/Library/Homebrew/unpack_strategy/xar.rb @@ -8,8 +8,6 @@ module UnpackStrategy include UnpackStrategy - - sig { returns(T::Array[String]) } def self.extensions [".xar"] diff --git a/Library/Homebrew/unpack_strategy/xz.rb b/Library/Homebrew/unpack_strategy/xz.rb index 71894af646..cc450d51d6 100644 --- a/Library/Homebrew/unpack_strategy/xz.rb +++ b/Library/Homebrew/unpack_strategy/xz.rb @@ -8,8 +8,6 @@ module UnpackStrategy include UnpackStrategy - - sig { returns(T::Array[String]) } def self.extensions [".xz"] diff --git a/Library/Homebrew/unpack_strategy/zip.rb b/Library/Homebrew/unpack_strategy/zip.rb index 9495e4ac66..85ef33cbbb 100644 --- a/Library/Homebrew/unpack_strategy/zip.rb +++ b/Library/Homebrew/unpack_strategy/zip.rb @@ -8,8 +8,6 @@ module UnpackStrategy include UnpackStrategy - - sig { returns(T::Array[String]) } def self.extensions [".zip"] diff --git a/Library/Homebrew/unpack_strategy/zstd.rb b/Library/Homebrew/unpack_strategy/zstd.rb index ab256ea5ac..c5f0b2a6b9 100644 --- a/Library/Homebrew/unpack_strategy/zstd.rb +++ b/Library/Homebrew/unpack_strategy/zstd.rb @@ -8,8 +8,6 @@ module UnpackStrategy include UnpackStrategy - - sig { returns(T::Array[String]) } def self.extensions [".zst"] From b1f722aed7ed4a6e475bb7fb230748db68bc307f Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Mon, 20 Mar 2023 13:35:29 -0700 Subject: [PATCH 3/5] Update RBI files --- .../Homebrew/extend/os/mac/unpack_strategy/zip.rbi | 8 ++------ Library/Homebrew/extend/pathname.rb | 3 +++ Library/Homebrew/unpack_strategy.rbi | 11 ----------- 3 files changed, 5 insertions(+), 17 deletions(-) diff --git a/Library/Homebrew/extend/os/mac/unpack_strategy/zip.rbi b/Library/Homebrew/extend/os/mac/unpack_strategy/zip.rbi index ee40416382..43597431d9 100644 --- a/Library/Homebrew/extend/os/mac/unpack_strategy/zip.rbi +++ b/Library/Homebrew/extend/os/mac/unpack_strategy/zip.rbi @@ -1,9 +1,5 @@ # typed: strict -module UnpackStrategy - class Zip - module MacOSZipExtension - include Kernel - end - end +module UnpackStrategy::Zip::MacOSZipExtension + include Kernel end diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb index 643d01b305..ca61e8d3f1 100644 --- a/Library/Homebrew/extend/pathname.rb +++ b/Library/Homebrew/extend/pathname.rb @@ -467,6 +467,7 @@ class Pathname [] end + sig { returns(String) } def magic_number @magic_number ||= if directory? "" @@ -477,11 +478,13 @@ class Pathname end end + sig { returns(String) } def file_type @file_type ||= system_command("file", args: ["-b", self], print_stderr: false) .stdout.chomp end + sig { returns(T::Array[String]) } def zipinfo @zipinfo ||= system_command("zipinfo", args: ["-1", self], print_stderr: false) .stdout diff --git a/Library/Homebrew/unpack_strategy.rbi b/Library/Homebrew/unpack_strategy.rbi index 55284f6668..d7550c56b2 100644 --- a/Library/Homebrew/unpack_strategy.rbi +++ b/Library/Homebrew/unpack_strategy.rbi @@ -3,14 +3,3 @@ module UnpackStrategy include Kernel end - -class Pathname - sig { returns(String) } - def magic_number; end - - sig { returns(String) } - def file_type; end - - sig { returns(T::Array[String]) } - def zipinfo; end -end From 91afda651af6708e722f6f4c702a573932545be1 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Tue, 21 Mar 2023 17:34:06 -0700 Subject: [PATCH 4/5] Update Pathname#magic_number --- Library/Homebrew/extend/pathname.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb index ca61e8d3f1..d83c5fc39f 100644 --- a/Library/Homebrew/extend/pathname.rb +++ b/Library/Homebrew/extend/pathname.rb @@ -472,9 +472,10 @@ class Pathname @magic_number ||= if directory? "" else + max_magic_number_length = 262 # Length of the longest regex (currently Tar). - # The `T.let` is a workaround until we have https://github.com/sorbet/sorbet/pull/6865 - T.let(binread(262), T.nilable(String)) || "" + # FIXME: The `T.let` is a workaround until we have https://github.com/sorbet/sorbet/pull/6865 + T.let(binread(max_magic_number_length), T.nilable(String)) || "" end end From 9ba677f6d480cb78867c1cec01c9b93267d5d215 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Wed, 22 Mar 2023 10:04:53 -0700 Subject: [PATCH 5/5] Update Library/Homebrew/extend/pathname.rb Co-authored-by: Mike McQuaid --- Library/Homebrew/extend/pathname.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb index d83c5fc39f..ca9144b27a 100644 --- a/Library/Homebrew/extend/pathname.rb +++ b/Library/Homebrew/extend/pathname.rb @@ -472,8 +472,8 @@ class Pathname @magic_number ||= if directory? "" else - max_magic_number_length = 262 # Length of the longest regex (currently Tar). + max_magic_number_length = 262 # FIXME: The `T.let` is a workaround until we have https://github.com/sorbet/sorbet/pull/6865 T.let(binread(max_magic_number_length), T.nilable(String)) || "" end