From 1be120f4c1d7f0be24ead200a6cb0925acc90129 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Tue, 28 Mar 2017 15:34:34 +0200 Subject: [PATCH] Add `Container::Executable`. --- Library/Homebrew/cask/lib/hbc/container.rb | 2 ++ .../cask/lib/hbc/container/executable.rb | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 Library/Homebrew/cask/lib/hbc/container/executable.rb diff --git a/Library/Homebrew/cask/lib/hbc/container.rb b/Library/Homebrew/cask/lib/hbc/container.rb index fc7246f3d9..c6b2c3c370 100644 --- a/Library/Homebrew/cask/lib/hbc/container.rb +++ b/Library/Homebrew/cask/lib/hbc/container.rb @@ -4,6 +4,7 @@ require "hbc/container/bzip2" require "hbc/container/cab" require "hbc/container/criteria" require "hbc/container/dmg" +require "hbc/container/executable" require "hbc/container/generic_unar" require "hbc/container/gzip" require "hbc/container/lzma" @@ -39,6 +40,7 @@ module Hbc Gzip, # pure gzip Lzma, # pure lzma Xz, # pure xz + Executable, ] # for explicit use only (never autodetected): # Hbc::Container::Naked diff --git a/Library/Homebrew/cask/lib/hbc/container/executable.rb b/Library/Homebrew/cask/lib/hbc/container/executable.rb new file mode 100644 index 0000000000..848f6d4be2 --- /dev/null +++ b/Library/Homebrew/cask/lib/hbc/container/executable.rb @@ -0,0 +1,18 @@ +require "hbc/container/naked" +require "vendor/macho/macho" + +module Hbc + class Container + class Executable < Naked + def self.me?(criteria) + return true if criteria.magic_number(/^#!\s*\S+/) + + begin + MachO.open(criteria.path).header.executable? + rescue MachO::MagicError + false + end + end + end + end +end