diff --git a/Library/Homebrew/unpack_strategy.rb b/Library/Homebrew/unpack_strategy.rb index e0ed8caca9..3a06993f4b 100644 --- a/Library/Homebrew/unpack_strategy.rb +++ b/Library/Homebrew/unpack_strategy.rb @@ -43,17 +43,17 @@ module UnpackStrategy Xar, Ttf, Otf, - Executable, Git, Mercurial, Subversion, Cvs, + SelfExtractingExecutable, # needs to be before Cab + Cab, + Executable, Dmg, # needs to be before Bzip2 Bzip2, Fossil, Bazaar, - SelfExtractingExecutable, # needs to be before Cab - Cab, Compress, P7Zip, Sit, @@ -77,19 +77,14 @@ module UnpackStrategy end def self.from_path(path) - strategy = strategies.detect do |s| - s.can_extract?(path) - end + strategy = strategies + .sort_by { |s| s.extensions.map(&:length).max(0) } + .reverse + .detect { |s| s.extensions.include?(path.extname) } - # This is so that bad files produce good error messages. - strategy ||= case path.extname - when ".tar", ".tar.gz", ".tgz", ".tar.bz2", ".tbz", ".tar.xz", ".txz" - Tar - when ".zip" - Zip - else - Uncompressed - end + strategy ||= strategies.detect { |s| s.can_extract?(path) } + + strategy ||= Uncompressed strategy end diff --git a/Library/Homebrew/unpack_strategy/air.rb b/Library/Homebrew/unpack_strategy/air.rb index eabcefbacf..1b12e221b0 100644 --- a/Library/Homebrew/unpack_strategy/air.rb +++ b/Library/Homebrew/unpack_strategy/air.rb @@ -4,6 +4,10 @@ module UnpackStrategy using Magic + def self.extensions + [".air"] + end + def self.can_extract?(path) mime_type = "application/vnd.adobe.air-application-installer-package+zip" path.magic_number.match?(/.{59}#{Regexp.escape(mime_type)}/) diff --git a/Library/Homebrew/unpack_strategy/bzip2.rb b/Library/Homebrew/unpack_strategy/bzip2.rb index aa56ab711a..e47cc062df 100644 --- a/Library/Homebrew/unpack_strategy/bzip2.rb +++ b/Library/Homebrew/unpack_strategy/bzip2.rb @@ -4,6 +4,10 @@ module UnpackStrategy using Magic + def self.extensions + [".bz2"] + end + def self.can_extract?(path) path.magic_number.match?(/\ABZh/n) end diff --git a/Library/Homebrew/unpack_strategy/cab.rb b/Library/Homebrew/unpack_strategy/cab.rb index 346ac014f2..afbf9e3784 100644 --- a/Library/Homebrew/unpack_strategy/cab.rb +++ b/Library/Homebrew/unpack_strategy/cab.rb @@ -4,6 +4,10 @@ module UnpackStrategy using Magic + def self.extensions + [".cab"] + end + def self.can_extract?(path) path.magic_number.match?(/\AMSCF/n) end diff --git a/Library/Homebrew/unpack_strategy/compress.rb b/Library/Homebrew/unpack_strategy/compress.rb index be7039beb6..952e17c980 100644 --- a/Library/Homebrew/unpack_strategy/compress.rb +++ b/Library/Homebrew/unpack_strategy/compress.rb @@ -4,6 +4,10 @@ module UnpackStrategy class Compress < Tar using Magic + def self.extensions + [".compress"] + end + def self.can_extract?(path) path.magic_number.match?(/\A\037\235/n) end diff --git a/Library/Homebrew/unpack_strategy/directory.rb b/Library/Homebrew/unpack_strategy/directory.rb index b8909bc0ef..5aa39e9137 100644 --- a/Library/Homebrew/unpack_strategy/directory.rb +++ b/Library/Homebrew/unpack_strategy/directory.rb @@ -4,6 +4,10 @@ module UnpackStrategy using Magic + def self.extensions + [] + end + def self.can_extract?(path) path.directory? end diff --git a/Library/Homebrew/unpack_strategy/dmg.rb b/Library/Homebrew/unpack_strategy/dmg.rb index e2f3b83322..b15ec3c44d 100644 --- a/Library/Homebrew/unpack_strategy/dmg.rb +++ b/Library/Homebrew/unpack_strategy/dmg.rb @@ -92,14 +92,11 @@ module UnpackStrategy end private_constant :Mount + def self.extensions + [".dmg"] + end + def self.can_extract?(path) - bzip2 = Bzip2.can_extract?(path) - - zlib = path.magic_number.match?(/\A(\x78|\x08|\x18|\x28|\x38|\x48|\x58|\x68)/n) && - (path.magic_number[0...2].unpack("S>").first % 31).zero? - - return false unless bzip2 || zlib - imageinfo = system_command("hdiutil", args: ["imageinfo", path], print_stderr: false).stdout diff --git a/Library/Homebrew/unpack_strategy/executable.rb b/Library/Homebrew/unpack_strategy/executable.rb index b7b2d9cb9a..3378bb6ff1 100644 --- a/Library/Homebrew/unpack_strategy/executable.rb +++ b/Library/Homebrew/unpack_strategy/executable.rb @@ -4,8 +4,13 @@ module UnpackStrategy class Executable < Uncompressed using Magic + def self.extensions + [".sh", ".bash"] + end + def self.can_extract?(path) - path.magic_number.match?(/\A#!\s*\S+/n) + path.magic_number.match?(/\A#!\s*\S+/n) || + path.magic_number.match?(/\AMZ/n) end end end diff --git a/Library/Homebrew/unpack_strategy/fossil.rb b/Library/Homebrew/unpack_strategy/fossil.rb index 9effd39874..5bc5e5e78f 100644 --- a/Library/Homebrew/unpack_strategy/fossil.rb +++ b/Library/Homebrew/unpack_strategy/fossil.rb @@ -4,6 +4,10 @@ module UnpackStrategy using Magic + def self.extensions + [] + end + def self.can_extract?(path) return false unless path.magic_number.match?(/\ASQLite format 3\000/n) diff --git a/Library/Homebrew/unpack_strategy/generic_unar.rb b/Library/Homebrew/unpack_strategy/generic_unar.rb index 228e8fd05d..f9e65b9dec 100644 --- a/Library/Homebrew/unpack_strategy/generic_unar.rb +++ b/Library/Homebrew/unpack_strategy/generic_unar.rb @@ -4,6 +4,10 @@ module UnpackStrategy using Magic + def self.extensions + [] + end + def self.can_extract?(_path) false end diff --git a/Library/Homebrew/unpack_strategy/gzip.rb b/Library/Homebrew/unpack_strategy/gzip.rb index c9dcc48d06..d575721d74 100644 --- a/Library/Homebrew/unpack_strategy/gzip.rb +++ b/Library/Homebrew/unpack_strategy/gzip.rb @@ -4,6 +4,10 @@ module UnpackStrategy using Magic + def self.extensions + [".gz"] + end + def self.can_extract?(path) path.magic_number.match?(/\A\037\213/n) end diff --git a/Library/Homebrew/unpack_strategy/jar.rb b/Library/Homebrew/unpack_strategy/jar.rb index 6c23d29f1f..90d4f6485c 100644 --- a/Library/Homebrew/unpack_strategy/jar.rb +++ b/Library/Homebrew/unpack_strategy/jar.rb @@ -4,6 +4,10 @@ module UnpackStrategy class Jar < Uncompressed using Magic + def self.extensions + [".apk", ".jar"] + end + def self.can_extract?(path) return false unless Zip.can_extract?(path) diff --git a/Library/Homebrew/unpack_strategy/lha.rb b/Library/Homebrew/unpack_strategy/lha.rb index c0ade6f5e1..b3671b0a60 100644 --- a/Library/Homebrew/unpack_strategy/lha.rb +++ b/Library/Homebrew/unpack_strategy/lha.rb @@ -4,6 +4,10 @@ module UnpackStrategy using Magic + def self.extensions + [".lha", ".lzh"] + end + def self.can_extract?(path) path.magic_number.match?(/\A..-(lh0|lh1|lz4|lz5|lzs|lh\\40|lhd|lh2|lh3|lh4|lh5)-/n) end diff --git a/Library/Homebrew/unpack_strategy/lua_rock.rb b/Library/Homebrew/unpack_strategy/lua_rock.rb index e6bf7bf336..fe3d8f130b 100644 --- a/Library/Homebrew/unpack_strategy/lua_rock.rb +++ b/Library/Homebrew/unpack_strategy/lua_rock.rb @@ -4,6 +4,10 @@ module UnpackStrategy class LuaRock < Uncompressed using Magic + def self.extensions + [".rock"] + end + def self.can_extract?(path) return false unless Zip.can_extract?(path) diff --git a/Library/Homebrew/unpack_strategy/lzip.rb b/Library/Homebrew/unpack_strategy/lzip.rb index 364dd2139f..f96e0ab2da 100644 --- a/Library/Homebrew/unpack_strategy/lzip.rb +++ b/Library/Homebrew/unpack_strategy/lzip.rb @@ -4,6 +4,10 @@ module UnpackStrategy using Magic + def self.extensions + [".lz"] + end + def self.can_extract?(path) path.magic_number.match?(/\ALZIP/n) end diff --git a/Library/Homebrew/unpack_strategy/lzma.rb b/Library/Homebrew/unpack_strategy/lzma.rb index 189495c37f..a9a60a0b9a 100644 --- a/Library/Homebrew/unpack_strategy/lzma.rb +++ b/Library/Homebrew/unpack_strategy/lzma.rb @@ -4,6 +4,10 @@ module UnpackStrategy using Magic + def self.extensions + [".lzma"] + end + def self.can_extract?(path) path.magic_number.match?(/\A\]\000\000\200\000/n) end diff --git a/Library/Homebrew/unpack_strategy/microsoft_office_xml.rb b/Library/Homebrew/unpack_strategy/microsoft_office_xml.rb index 7d40000773..50647869e2 100644 --- a/Library/Homebrew/unpack_strategy/microsoft_office_xml.rb +++ b/Library/Homebrew/unpack_strategy/microsoft_office_xml.rb @@ -4,6 +4,14 @@ module UnpackStrategy class MicrosoftOfficeXml < Uncompressed using Magic + def self.extensions + [ + ".doc", ".docx", + ".ppt", ".pptx", + ".xls", ".xlsx" + ] + end + def self.can_extract?(path) return false unless Zip.can_extract?(path) diff --git a/Library/Homebrew/unpack_strategy/otf.rb b/Library/Homebrew/unpack_strategy/otf.rb index 87d7c860d5..a540f7779f 100644 --- a/Library/Homebrew/unpack_strategy/otf.rb +++ b/Library/Homebrew/unpack_strategy/otf.rb @@ -4,6 +4,10 @@ module UnpackStrategy class Otf < Uncompressed using Magic + def self.extensions + [".otf"] + end + def self.can_extract?(path) path.magic_number.match?(/\AOTTO/n) end diff --git a/Library/Homebrew/unpack_strategy/p7zip.rb b/Library/Homebrew/unpack_strategy/p7zip.rb index fa4fd3b7f1..cfb76d08c9 100644 --- a/Library/Homebrew/unpack_strategy/p7zip.rb +++ b/Library/Homebrew/unpack_strategy/p7zip.rb @@ -4,6 +4,10 @@ module UnpackStrategy using Magic + def self.extensions + [".7z"] + end + def self.can_extract?(path) path.magic_number.match?(/\A7z\xBC\xAF\x27\x1C/n) end diff --git a/Library/Homebrew/unpack_strategy/pkg.rb b/Library/Homebrew/unpack_strategy/pkg.rb index a9f6597972..f837d4933c 100644 --- a/Library/Homebrew/unpack_strategy/pkg.rb +++ b/Library/Homebrew/unpack_strategy/pkg.rb @@ -4,6 +4,10 @@ module UnpackStrategy class Pkg < Uncompressed using Magic + def self.extensions + [".pkg", ".mkpg"] + end + def self.can_extract?(path) path.extname.match?(/\A.m?pkg\Z/) && (path.directory? || path.magic_number.match?(/\Axar!/n)) diff --git a/Library/Homebrew/unpack_strategy/rar.rb b/Library/Homebrew/unpack_strategy/rar.rb index 4b3d6acba6..648c79e972 100644 --- a/Library/Homebrew/unpack_strategy/rar.rb +++ b/Library/Homebrew/unpack_strategy/rar.rb @@ -4,6 +4,10 @@ module UnpackStrategy using Magic + def self.extensions + [".rar"] + end + def self.can_extract?(path) path.magic_number.match?(/\ARar!/n) end diff --git a/Library/Homebrew/unpack_strategy/self_extracting_executable.rb b/Library/Homebrew/unpack_strategy/self_extracting_executable.rb index 9c442d778d..a502cce547 100644 --- a/Library/Homebrew/unpack_strategy/self_extracting_executable.rb +++ b/Library/Homebrew/unpack_strategy/self_extracting_executable.rb @@ -4,10 +4,13 @@ module UnpackStrategy class SelfExtractingExecutable < GenericUnar using Magic - def self.can_extract?(path) - return false unless path.magic_number.match?(/\AMZ/n) + def self.extensions + [] + end - path.file_type.include?("self-extracting archive") + def self.can_extract?(path) + path.magic_number.match?(/\AMZ/n) && + path.file_type.include?("self-extracting archive") end end end diff --git a/Library/Homebrew/unpack_strategy/sit.rb b/Library/Homebrew/unpack_strategy/sit.rb index 57ada1253c..c719de4a04 100644 --- a/Library/Homebrew/unpack_strategy/sit.rb +++ b/Library/Homebrew/unpack_strategy/sit.rb @@ -4,6 +4,10 @@ module UnpackStrategy class Sit < GenericUnar using Magic + def self.extensions + [".sit"] + end + def self.can_extract?(path) path.magic_number.match?(/\AStuffIt/n) end diff --git a/Library/Homebrew/unpack_strategy/tar.rb b/Library/Homebrew/unpack_strategy/tar.rb index b19f127764..fcd67a3d49 100644 --- a/Library/Homebrew/unpack_strategy/tar.rb +++ b/Library/Homebrew/unpack_strategy/tar.rb @@ -4,6 +4,16 @@ module UnpackStrategy using Magic + def self.extensions + [ + ".tar", + ".tbz", ".tbz2", ".tar.bz2", + ".tgz", ".tar.gz", + ".tlz", ".tar.lz", + ".txz", ".tar.xz" + ] + end + def self.can_extract?(path) return true if path.magic_number.match?(/\A.{257}ustar/n) diff --git a/Library/Homebrew/unpack_strategy/ttf.rb b/Library/Homebrew/unpack_strategy/ttf.rb index 664f6f766e..e5f0540c0b 100644 --- a/Library/Homebrew/unpack_strategy/ttf.rb +++ b/Library/Homebrew/unpack_strategy/ttf.rb @@ -4,6 +4,10 @@ module UnpackStrategy class Ttf < Uncompressed using Magic + def self.extensions + [".ttc", ".ttf"] + end + def self.can_extract?(path) # TrueType Font path.magic_number.match?(/\A\000\001\000\000\000/n) || diff --git a/Library/Homebrew/unpack_strategy/xar.rb b/Library/Homebrew/unpack_strategy/xar.rb index 903732dc31..043c6a5f49 100644 --- a/Library/Homebrew/unpack_strategy/xar.rb +++ b/Library/Homebrew/unpack_strategy/xar.rb @@ -4,6 +4,10 @@ module UnpackStrategy using Magic + def self.extensions + [".xar"] + end + def self.can_extract?(path) path.magic_number.match?(/\Axar!/n) end diff --git a/Library/Homebrew/unpack_strategy/xz.rb b/Library/Homebrew/unpack_strategy/xz.rb index 1cbb23b330..c53d2681d5 100644 --- a/Library/Homebrew/unpack_strategy/xz.rb +++ b/Library/Homebrew/unpack_strategy/xz.rb @@ -4,6 +4,10 @@ module UnpackStrategy using Magic + def self.extensions + [".xz"] + end + def self.can_extract?(path) path.magic_number.match?(/\A\xFD7zXZ\x00/n) end diff --git a/Library/Homebrew/unpack_strategy/zip.rb b/Library/Homebrew/unpack_strategy/zip.rb index 237d43f3f5..d8188447ba 100644 --- a/Library/Homebrew/unpack_strategy/zip.rb +++ b/Library/Homebrew/unpack_strategy/zip.rb @@ -4,6 +4,10 @@ module UnpackStrategy using Magic + def self.extensions + [".zip"] + end + def self.can_extract?(path) path.magic_number.match?(/\APK(\003\004|\005\006)/n) end