From 2a63d363c2d49c6fbf4f6f5a53cd73701a63e997 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Thu, 12 Jul 2018 22:15:21 +0200 Subject: [PATCH] Add two new unpack strategies. --- Library/Homebrew/unpack_strategy.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Library/Homebrew/unpack_strategy.rb b/Library/Homebrew/unpack_strategy.rb index f360296503..96c0f14ce6 100644 --- a/Library/Homebrew/unpack_strategy.rb +++ b/Library/Homebrew/unpack_strategy.rb @@ -6,6 +6,8 @@ class UnpackStrategy def self.strategies @strategies ||= [ JarUnpackStrategy, + LuaRockUnpackStrategy, + MicrosoftOfficeXmlUnpackStrategy, ZipUnpackStrategy, XarUnpackStrategy, CompressUnpackStrategy, @@ -87,6 +89,26 @@ class UncompressedUnpackStrategy < UnpackStrategy end end +class MicrosoftOfficeXmlUnpackStrategy < UncompressedUnpackStrategy + def self.can_extract?(path:, magic_number:) + return false unless ZipUnpackStrategy.can_extract?(path: path, magic_number: magic_number) + + # Check further if the ZIP is a Microsoft Office XML document. + magic_number.match?(/\APK\003\004/n) && + magic_number.match?(%r{\A.{30}(\[Content_Types\]\.xml|_rels/\.rels)}n) + end +end + +class LuaRockUnpackStrategy < UncompressedUnpackStrategy + def self.can_extract?(path:, magic_number:) + return false unless ZipUnpackStrategy.can_extract?(path: path, magic_number: magic_number) + + # Check further if the ZIP is a LuaRocks package. + out, _, status = Open3.capture3("zipinfo", "-1", path) + status.success? && out.split("\n").any? { |line| line.match?(%r{\A[^/]+.rockspec\Z}) } + end +end + class JarUnpackStrategy < UncompressedUnpackStrategy def self.can_extract?(path:, magic_number:) return false unless ZipUnpackStrategy.can_extract?(path: path, magic_number: magic_number)