diff options
| author | Markus Reiter | 2016-09-24 13:52:43 +0200 |
|---|---|---|
| committer | Markus Reiter | 2016-09-24 16:00:58 +0200 |
| commit | b86c8efb79b3ed835d552c4d7416640ef10caf21 (patch) | |
| tree | 7e1edc8a8f339e4d2781f43576d40c9c79aebcdc /Library/Homebrew/cask/lib/hbc/container | |
| parent | 687f0fcf721c8e36f32570ed72d0988a6eaf986f (diff) | |
| download | brew-b86c8efb79b3ed835d552c4d7416640ef10caf21.tar.bz2 | |
Cask: Use nested classes and modules.
Diffstat (limited to 'Library/Homebrew/cask/lib/hbc/container')
21 files changed, 410 insertions, 326 deletions
diff --git a/Library/Homebrew/cask/lib/hbc/container/air.rb b/Library/Homebrew/cask/lib/hbc/container/air.rb index fc618db83..4b083e538 100644 --- a/Library/Homebrew/cask/lib/hbc/container/air.rb +++ b/Library/Homebrew/cask/lib/hbc/container/air.rb @@ -1,33 +1,37 @@ require "hbc/container/base" -class Hbc::Container::Air < Hbc::Container::Base - INSTALLER_PATHNAME = - Pathname("/Applications/Utilities/Adobe AIR Application Installer.app" \ - "/Contents/MacOS/Adobe AIR Application Installer") - - def self.me?(criteria) - %w[.air].include?(criteria.path.extname) - end - - def self.installer_cmd - return @installer_cmd ||= INSTALLER_PATHNAME if installer_exist? - raise Hbc::CaskError, <<-EOS.undent - Adobe AIR runtime not present, try installing it via - - brew cask install adobe-air - - EOS - end - - def self.installer_exist? - INSTALLER_PATHNAME.exist? - end - - def extract - install = @command.run(self.class.installer_cmd, - args: ["-silent", "-location", @cask.staged_path, Pathname.new(@path).realpath]) - - return unless install.exit_status == 9 - raise Hbc::CaskError, "Adobe AIR application #{@cask} already exists on the system, and cannot be reinstalled." +module Hbc + class Container + class Air < Base + INSTALLER_PATHNAME = + Pathname("/Applications/Utilities/Adobe AIR Application Installer.app" \ + "/Contents/MacOS/Adobe AIR Application Installer") + + def self.me?(criteria) + %w[.air].include?(criteria.path.extname) + end + + def self.installer_cmd + return @installer_cmd ||= INSTALLER_PATHNAME if installer_exist? + raise CaskError, <<-EOS.undent + Adobe AIR runtime not present, try installing it via + + brew cask install adobe-air + + EOS + end + + def self.installer_exist? + INSTALLER_PATHNAME.exist? + end + + def extract + install = @command.run(self.class.installer_cmd, + args: ["-silent", "-location", @cask.staged_path, Pathname.new(@path).realpath]) + + return unless install.exit_status == 9 + raise CaskError, "Adobe AIR application #{@cask} already exists on the system, and cannot be reinstalled." + end + end end end diff --git a/Library/Homebrew/cask/lib/hbc/container/base.rb b/Library/Homebrew/cask/lib/hbc/container/base.rb index 42331df31..1f1c9ad9b 100644 --- a/Library/Homebrew/cask/lib/hbc/container/base.rb +++ b/Library/Homebrew/cask/lib/hbc/container/base.rb @@ -1,37 +1,41 @@ -class Hbc::Container::Base - def initialize(cask, path, command, nested: false) - @cask = cask - @path = path - @command = command - @nested = nested - end +module Hbc + class Container + class Base + def initialize(cask, path, command, nested: false) + @cask = cask + @path = path + @command = command + @nested = nested + end - def extract_nested_inside(dir) - children = Pathname.new(dir).children + def extract_nested_inside(dir) + children = Pathname.new(dir).children - nested_container = children[0] + nested_container = children[0] - unless children.count == 1 && - !nested_container.directory? && - @cask.artifacts[:nested_container].empty? && - extract_nested_container(nested_container) + unless children.count == 1 && + !nested_container.directory? && + @cask.artifacts[:nested_container].empty? && + extract_nested_container(nested_container) - children.each do |src| - dest = @cask.staged_path.join(src.basename) - FileUtils.rm_r(dest) if dest.exist? - FileUtils.mv(src, dest) + children.each do |src| + dest = @cask.staged_path.join(src.basename) + FileUtils.rm_r(dest) if dest.exist? + FileUtils.mv(src, dest) + end + end end - end - end - def extract_nested_container(source) - container = Hbc::Container.for_path(source, @command) + def extract_nested_container(source) + container = Container.for_path(source, @command) - return false unless container + return false unless container - ohai "Extracting nested container #{source.basename}" - container.new(@cask, source, @command, nested: true).extract + ohai "Extracting nested container #{source.basename}" + container.new(@cask, source, @command, nested: true).extract - true + true + end + end end end diff --git a/Library/Homebrew/cask/lib/hbc/container/bzip2.rb b/Library/Homebrew/cask/lib/hbc/container/bzip2.rb index 617c68b32..81808071f 100644 --- a/Library/Homebrew/cask/lib/hbc/container/bzip2.rb +++ b/Library/Homebrew/cask/lib/hbc/container/bzip2.rb @@ -2,17 +2,21 @@ require "tmpdir" require "hbc/container/base" -class Hbc::Container::Bzip2 < Hbc::Container::Base - def self.me?(criteria) - criteria.magic_number(%r{^BZh}n) - end +module Hbc + class Container + class Bzip2 < Base + def self.me?(criteria) + criteria.magic_number(%r{^BZh}n) + end - def extract - Dir.mktmpdir do |unpack_dir| - @command.run!("/usr/bin/ditto", args: ["--", @path, unpack_dir]) - @command.run!("/usr/bin/bunzip2", args: ["--quiet", "--", Pathname.new(unpack_dir).join(@path.basename)]) + def extract + Dir.mktmpdir do |unpack_dir| + @command.run!("/usr/bin/ditto", args: ["--", @path, unpack_dir]) + @command.run!("/usr/bin/bunzip2", args: ["--quiet", "--", Pathname.new(unpack_dir).join(@path.basename)]) - extract_nested_inside(unpack_dir) + extract_nested_inside(unpack_dir) + end + end end end end diff --git a/Library/Homebrew/cask/lib/hbc/container/cab.rb b/Library/Homebrew/cask/lib/hbc/container/cab.rb index 28000a5a3..d32b1b205 100644 --- a/Library/Homebrew/cask/lib/hbc/container/cab.rb +++ b/Library/Homebrew/cask/lib/hbc/container/cab.rb @@ -2,25 +2,29 @@ require "tmpdir" require "hbc/container/base" -class Hbc::Container::Cab < Hbc::Container::Base - def self.me?(criteria) - cabextract = Hbc.homebrew_prefix.join("bin", "cabextract") +module Hbc + class Container + class Cab < Base + def self.me?(criteria) + cabextract = Hbc.homebrew_prefix.join("bin", "cabextract") - criteria.magic_number(%r{^MSCF}n) && - cabextract.exist? && - criteria.command.run(cabextract, args: ["-t", "--", criteria.path.to_s]).stderr.empty? - end + criteria.magic_number(%r{^MSCF}n) && + cabextract.exist? && + criteria.command.run(cabextract, args: ["-t", "--", criteria.path.to_s]).stderr.empty? + end - def extract - cabextract = Hbc.homebrew_prefix.join("bin", "cabextract") + def extract + cabextract = Hbc.homebrew_prefix.join("bin", "cabextract") - unless cabextract.exist? - raise Hbc::CaskError, "Expected to find cabextract executable. Cask '#{@cask}' must add: depends_on formula: 'cabextract'" - end + unless cabextract.exist? + raise CaskError, "Expected to find cabextract executable. Cask '#{@cask}' must add: depends_on formula: 'cabextract'" + end - Dir.mktmpdir do |unpack_dir| - @command.run!(cabextract, args: ["-d", unpack_dir, "--", @path]) - @command.run!("/usr/bin/ditto", args: ["--", unpack_dir, @cask.staged_path]) + Dir.mktmpdir do |unpack_dir| + @command.run!(cabextract, args: ["-d", unpack_dir, "--", @path]) + @command.run!("/usr/bin/ditto", args: ["--", unpack_dir, @cask.staged_path]) + end + end end end end diff --git a/Library/Homebrew/cask/lib/hbc/container/criteria.rb b/Library/Homebrew/cask/lib/hbc/container/criteria.rb index 2ebb9d6fa..207c5f3cd 100644 --- a/Library/Homebrew/cask/lib/hbc/container/criteria.rb +++ b/Library/Homebrew/cask/lib/hbc/container/criteria.rb @@ -1,18 +1,22 @@ -class Hbc::Container::Criteria - attr_reader :path, :command +module Hbc + class Container + class Criteria + attr_reader :path, :command - def initialize(path, command) - @path = path - @command = command - end + def initialize(path, command) + @path = path + @command = command + end - def extension(regex) - path.extname.sub(%r{^\.}, "") =~ Regexp.new(regex.source, regex.options | Regexp::IGNORECASE) - end + def extension(regex) + path.extname.sub(%r{^\.}, "") =~ Regexp.new(regex.source, regex.options | Regexp::IGNORECASE) + end - def magic_number(regex) - # 262: length of the longest regex (currently: Hbc::Container::Tar) - @magic_number ||= File.open(@path, "rb") { |f| f.read(262) } - @magic_number =~ regex + def magic_number(regex) + # 262: length of the longest regex (currently: Hbc::Container::Tar) + @magic_number ||= File.open(@path, "rb") { |f| f.read(262) } + @magic_number =~ regex + end + end end end diff --git a/Library/Homebrew/cask/lib/hbc/container/dmg.rb b/Library/Homebrew/cask/lib/hbc/container/dmg.rb index 7e4b9340d..d53c077cb 100644 --- a/Library/Homebrew/cask/lib/hbc/container/dmg.rb +++ b/Library/Homebrew/cask/lib/hbc/container/dmg.rb @@ -3,123 +3,127 @@ require "tempfile" require "hbc/container/base" -class Hbc::Container::Dmg < Hbc::Container::Base - def self.me?(criteria) - !criteria.command.run("/usr/bin/hdiutil", - # realpath is a failsafe against unusual filenames - args: ["imageinfo", Pathname.new(criteria.path).realpath], - print_stderr: false).stdout.empty? - end +module Hbc + class Container + class Dmg < Base + def self.me?(criteria) + !criteria.command.run("/usr/bin/hdiutil", + # realpath is a failsafe against unusual filenames + args: ["imageinfo", Pathname.new(criteria.path).realpath], + print_stderr: false).stdout.empty? + end - attr_reader :mounts - def initialize(*args) - super(*args) - @mounts = [] - end + attr_reader :mounts + def initialize(*args) + super(*args) + @mounts = [] + end - def extract - mount! - assert_mounts_found - extract_mounts - ensure - eject! - end + def extract + mount! + assert_mounts_found + extract_mounts + ensure + eject! + end - def mount! - plist = @command.run!("/usr/bin/hdiutil", - # realpath is a failsafe against unusual filenames - args: %w[mount -plist -nobrowse -readonly -noidme -mountrandom /tmp] + [Pathname.new(@path).realpath], - input: %w[y]) - .plist - @mounts = mounts_from_plist(plist) - end + def mount! + plist = @command.run!("/usr/bin/hdiutil", + # realpath is a failsafe against unusual filenames + args: %w[mount -plist -nobrowse -readonly -noidme -mountrandom /tmp] + [Pathname.new(@path).realpath], + input: %w[y]) + .plist + @mounts = mounts_from_plist(plist) + end - def eject! - @mounts.each do |mount| - # realpath is a failsafe against unusual filenames - mountpath = Pathname.new(mount).realpath - next unless mountpath.exist? - - begin - tries ||= 2 - @command.run("/usr/sbin/diskutil", - args: ["eject", mountpath], - print_stderr: false) - - raise Hbc::CaskError, "Failed to eject #{mountpath}" if mountpath.exist? - rescue Hbc::CaskError => e - raise e if (tries -= 1).zero? - sleep 1 - retry + def eject! + @mounts.each do |mount| + # realpath is a failsafe against unusual filenames + mountpath = Pathname.new(mount).realpath + next unless mountpath.exist? + + begin + tries ||= 2 + @command.run("/usr/sbin/diskutil", + args: ["eject", mountpath], + print_stderr: false) + + raise CaskError, "Failed to eject #{mountpath}" if mountpath.exist? + rescue CaskError => e + raise e if (tries -= 1).zero? + sleep 1 + retry + end + end end - end - end - private + private - def extract_mounts - @mounts.each(&method(:extract_mount)) - end + def extract_mounts + @mounts.each(&method(:extract_mount)) + end - def extract_mount(mount) - Tempfile.open(["", ".bom"]) do |bomfile| - bomfile.close + def extract_mount(mount) + Tempfile.open(["", ".bom"]) do |bomfile| + bomfile.close - Tempfile.open(["", ".list"]) do |filelist| - filelist.write(bom_filelist_from_path(mount)) - filelist.close + Tempfile.open(["", ".list"]) do |filelist| + filelist.write(bom_filelist_from_path(mount)) + filelist.close - @command.run!("/usr/bin/mkbom", args: ["-s", "-i", filelist.path, "--", bomfile.path]) - @command.run!("/usr/bin/ditto", args: ["--bom", bomfile.path, "--", mount, @cask.staged_path]) + @command.run!("/usr/bin/mkbom", args: ["-s", "-i", filelist.path, "--", bomfile.path]) + @command.run!("/usr/bin/ditto", args: ["--bom", bomfile.path, "--", mount, @cask.staged_path]) + end + end end - end - end - def bom_filelist_from_path(mount) - Dir.chdir(mount) { - Dir.glob("**/*", File::FNM_DOTMATCH).map { |path| - next if skip_path?(Pathname(path)) - path == "." ? path : path.prepend("./") - }.compact.join("\n").concat("\n") - } - end + def bom_filelist_from_path(mount) + Dir.chdir(mount) { + Dir.glob("**/*", File::FNM_DOTMATCH).map { |path| + next if skip_path?(Pathname(path)) + path == "." ? path : path.prepend("./") + }.compact.join("\n").concat("\n") + } + end - def skip_path?(path) - dmg_metadata?(path) || system_dir_symlink?(path) - end + def skip_path?(path) + dmg_metadata?(path) || system_dir_symlink?(path) + end - # unnecessary DMG metadata - DMG_METADATA_FILES = %w[ - .background - .com.apple.timemachine.donotpresent - .DocumentRevisions-V100 - .DS_Store - .fseventsd - .MobileBackups - .Spotlight-V100 - .TemporaryItems - .Trashes - .VolumeIcon.icns - ].to_set.freeze - - def dmg_metadata?(path) - relative_root = path.sub(%r{/.*}, "") - DMG_METADATA_FILES.include?(relative_root.basename.to_s) - end + # unnecessary DMG metadata + DMG_METADATA_FILES = %w[ + .background + .com.apple.timemachine.donotpresent + .DocumentRevisions-V100 + .DS_Store + .fseventsd + .MobileBackups + .Spotlight-V100 + .TemporaryItems + .Trashes + .VolumeIcon.icns + ].to_set.freeze + + def dmg_metadata?(path) + relative_root = path.sub(%r{/.*}, "") + DMG_METADATA_FILES.include?(relative_root.basename.to_s) + end - def system_dir_symlink?(path) - # symlinks to system directories (commonly to /Applications) - path.symlink? && MacOS.system_dir?(path.readlink) - end + def system_dir_symlink?(path) + # symlinks to system directories (commonly to /Applications) + path.symlink? && MacOS.system_dir?(path.readlink) + end - def mounts_from_plist(plist) - return [] unless plist.respond_to?(:fetch) - plist.fetch("system-entities", []).map { |entity| - entity["mount-point"] - }.compact - end + def mounts_from_plist(plist) + return [] unless plist.respond_to?(:fetch) + plist.fetch("system-entities", []).map { |entity| + entity["mount-point"] + }.compact + end - def assert_mounts_found - raise Hbc::CaskError, "No mounts found in '#{@path}'; perhaps it is a bad DMG?" if @mounts.empty? + def assert_mounts_found + raise CaskError, "No mounts found in '#{@path}'; perhaps it is a bad DMG?" if @mounts.empty? + end + end end end diff --git a/Library/Homebrew/cask/lib/hbc/container/generic_unar.rb b/Library/Homebrew/cask/lib/hbc/container/generic_unar.rb index 1dcc0997a..32bbc8d15 100644 --- a/Library/Homebrew/cask/lib/hbc/container/generic_unar.rb +++ b/Library/Homebrew/cask/lib/hbc/container/generic_unar.rb @@ -2,25 +2,29 @@ require "tmpdir" require "hbc/container/base" -class Hbc::Container::GenericUnar < Hbc::Container::Base - def self.me?(criteria) - lsar = Hbc.homebrew_prefix.join("bin", "lsar") - lsar.exist? && - criteria.command.run(lsar, - args: ["-l", "-t", "--", criteria.path], - print_stderr: false).stdout.chomp.end_with?("passed, 0 failed.") - end +module Hbc + class Container + class GenericUnar < Base + def self.me?(criteria) + lsar = Hbc.homebrew_prefix.join("bin", "lsar") + lsar.exist? && + criteria.command.run(lsar, + args: ["-l", "-t", "--", criteria.path], + print_stderr: false).stdout.chomp.end_with?("passed, 0 failed.") + end - def extract - unar = Hbc.homebrew_prefix.join("bin", "unar") + def extract + unar = Hbc.homebrew_prefix.join("bin", "unar") - unless unar.exist? - raise Hbc::CaskError, "Expected to find unar executable. Cask #{@cask} must add: depends_on formula: 'unar'" - end + unless unar.exist? + raise CaskError, "Expected to find unar executable. Cask #{@cask} must add: depends_on formula: 'unar'" + end - Dir.mktmpdir do |unpack_dir| - @command.run!(unar, args: ["-force-overwrite", "-quiet", "-no-directory", "-output-directory", unpack_dir, "--", @path]) - @command.run!("/usr/bin/ditto", args: ["--", unpack_dir, @cask.staged_path]) + Dir.mktmpdir do |unpack_dir| + @command.run!(unar, args: ["-force-overwrite", "-quiet", "-no-directory", "-output-directory", unpack_dir, "--", @path]) + @command.run!("/usr/bin/ditto", args: ["--", unpack_dir, @cask.staged_path]) + end + end end end end diff --git a/Library/Homebrew/cask/lib/hbc/container/gzip.rb b/Library/Homebrew/cask/lib/hbc/container/gzip.rb index 161578162..7e4722a7f 100644 --- a/Library/Homebrew/cask/lib/hbc/container/gzip.rb +++ b/Library/Homebrew/cask/lib/hbc/container/gzip.rb @@ -2,17 +2,21 @@ require "tmpdir" require "hbc/container/base" -class Hbc::Container::Gzip < Hbc::Container::Base - def self.me?(criteria) - criteria.magic_number(%r{^\037\213}n) - end +module Hbc + class Container + class Gzip < Base + def self.me?(criteria) + criteria.magic_number(%r{^\037\213}n) + end - def extract - Dir.mktmpdir do |unpack_dir| - @command.run!("/usr/bin/ditto", args: ["--", @path, unpack_dir]) - @command.run!("/usr/bin/gunzip", args: ["--quiet", "--name", "--", Pathname.new(unpack_dir).join(@path.basename)]) + def extract + Dir.mktmpdir do |unpack_dir| + @command.run!("/usr/bin/ditto", args: ["--", @path, unpack_dir]) + @command.run!("/usr/bin/gunzip", args: ["--quiet", "--name", "--", Pathname.new(unpack_dir).join(@path.basename)]) - extract_nested_inside(unpack_dir) + extract_nested_inside(unpack_dir) + end + end end end end diff --git a/Library/Homebrew/cask/lib/hbc/container/lzma.rb b/Library/Homebrew/cask/lib/hbc/container/lzma.rb index e538b3779..a91132b55 100644 --- a/Library/Homebrew/cask/lib/hbc/container/lzma.rb +++ b/Library/Homebrew/cask/lib/hbc/container/lzma.rb @@ -2,22 +2,26 @@ require "tmpdir" require "hbc/container/base" -class Hbc::Container::Lzma < Hbc::Container::Base - def self.me?(criteria) - criteria.magic_number(%r{^\]\000\000\200\000}n) - end +module Hbc + class Container + class Lzma < Base + def self.me?(criteria) + criteria.magic_number(%r{^\]\000\000\200\000}n) + end - def extract - unlzma = Hbc.homebrew_prefix.join("bin", "unlzma") + def extract + unlzma = Hbc.homebrew_prefix.join("bin", "unlzma") - unless unlzma.exist? - raise Hbc::CaskError, "Expected to find unlzma executable. Cask '#{@cask}' must add: depends_on formula: 'lzma'" - end + unless unlzma.exist? + raise CaskError, "Expected to find unlzma executable. Cask '#{@cask}' must add: depends_on formula: 'lzma'" + end - Dir.mktmpdir do |unpack_dir| - @command.run!("/usr/bin/ditto", args: ["--", @path, unpack_dir]) - @command.run!(unlzma, args: ["-q", "--", Pathname(unpack_dir).join(@path.basename)]) - @command.run!("/usr/bin/ditto", args: ["--", unpack_dir, @cask.staged_path]) + Dir.mktmpdir do |unpack_dir| + @command.run!("/usr/bin/ditto", args: ["--", @path, unpack_dir]) + @command.run!(unlzma, args: ["-q", "--", Pathname(unpack_dir).join(@path.basename)]) + @command.run!("/usr/bin/ditto", args: ["--", unpack_dir, @cask.staged_path]) + end + end end end end diff --git a/Library/Homebrew/cask/lib/hbc/container/naked.rb b/Library/Homebrew/cask/lib/hbc/container/naked.rb index 596f50789..375d62f7a 100644 --- a/Library/Homebrew/cask/lib/hbc/container/naked.rb +++ b/Library/Homebrew/cask/lib/hbc/container/naked.rb @@ -1,19 +1,23 @@ require "hbc/container/base" -class Hbc::Container::Naked < Hbc::Container::Base - # Either inherit from this class and override with self.me?(criteria), - # or use this class directly as "container type: :naked", - # in which case self.me? is not called. - def self.me?(*) - false - end +module Hbc + class Container + class Naked < Base + # Either inherit from this class and override with self.me?(criteria), + # or use this class directly as "container type: :naked", + # in which case self.me? is not called. + def self.me?(*) + false + end - def extract - @command.run!("/usr/bin/ditto", args: ["--", @path, @cask.staged_path.join(target_file)]) - end + def extract + @command.run!("/usr/bin/ditto", args: ["--", @path, @cask.staged_path.join(target_file)]) + end - def target_file - return @path.basename if @nested - URI.decode(File.basename(@cask.url.path)) + def target_file + return @path.basename if @nested + URI.decode(File.basename(@cask.url.path)) + end + end end end diff --git a/Library/Homebrew/cask/lib/hbc/container/otf.rb b/Library/Homebrew/cask/lib/hbc/container/otf.rb index f9a25e1ed..66222ad8d 100644 --- a/Library/Homebrew/cask/lib/hbc/container/otf.rb +++ b/Library/Homebrew/cask/lib/hbc/container/otf.rb @@ -1,7 +1,11 @@ require "hbc/container/naked" -class Hbc::Container::Otf < Hbc::Container::Naked - def self.me?(criteria) - criteria.magic_number(%r{^OTTO}n) +module Hbc + class Container + class Otf < Naked + def self.me?(criteria) + criteria.magic_number(%r{^OTTO}n) + end + end end end diff --git a/Library/Homebrew/cask/lib/hbc/container/pkg.rb b/Library/Homebrew/cask/lib/hbc/container/pkg.rb index 5d2282d0f..dfd62a863 100644 --- a/Library/Homebrew/cask/lib/hbc/container/pkg.rb +++ b/Library/Homebrew/cask/lib/hbc/container/pkg.rb @@ -1,9 +1,13 @@ require "hbc/container/naked" -class Hbc::Container::Pkg < Hbc::Container::Naked - def self.me?(criteria) - criteria.extension(%r{m?pkg$}) && - (criteria.path.directory? || - criteria.magic_number(%r{^xar!}n)) +module Hbc + class Container + class Pkg < Naked + def self.me?(criteria) + criteria.extension(%r{m?pkg$}) && + (criteria.path.directory? || + criteria.magic_number(%r{^xar!}n)) + end + end end end diff --git a/Library/Homebrew/cask/lib/hbc/container/rar.rb b/Library/Homebrew/cask/lib/hbc/container/rar.rb index 9c144006f..bcf225623 100644 --- a/Library/Homebrew/cask/lib/hbc/container/rar.rb +++ b/Library/Homebrew/cask/lib/hbc/container/rar.rb @@ -1,8 +1,12 @@ require "hbc/container/generic_unar" -class Hbc::Container::Rar < Hbc::Container::GenericUnar - def self.me?(criteria) - criteria.magic_number(%r{^Rar!}n) && - super +module Hbc + class Container + class Rar < GenericUnar + def self.me?(criteria) + criteria.magic_number(%r{^Rar!}n) && + super + end + end end end diff --git a/Library/Homebrew/cask/lib/hbc/container/seven_zip.rb b/Library/Homebrew/cask/lib/hbc/container/seven_zip.rb index f0d183064..7a144d532 100644 --- a/Library/Homebrew/cask/lib/hbc/container/seven_zip.rb +++ b/Library/Homebrew/cask/lib/hbc/container/seven_zip.rb @@ -1,9 +1,13 @@ require "hbc/container/generic_unar" -class Hbc::Container::SevenZip < Hbc::Container::GenericUnar - def self.me?(criteria) - # TODO: cover self-extracting archives - criteria.magic_number(%r{^7z}n) && - super +module Hbc + class Container + class SevenZip < GenericUnar + def self.me?(criteria) + # TODO: cover self-extracting archives + criteria.magic_number(%r{^7z}n) && + super + end + end end end diff --git a/Library/Homebrew/cask/lib/hbc/container/sit.rb b/Library/Homebrew/cask/lib/hbc/container/sit.rb index 155b93f3f..2d8849399 100644 --- a/Library/Homebrew/cask/lib/hbc/container/sit.rb +++ b/Library/Homebrew/cask/lib/hbc/container/sit.rb @@ -1,8 +1,12 @@ require "hbc/container/generic_unar" -class Hbc::Container::Sit < Hbc::Container::GenericUnar - def self.me?(criteria) - criteria.magic_number(%r{^StuffIt}n) && - super +module Hbc + class Container + class Sit < GenericUnar + def self.me?(criteria) + criteria.magic_number(%r{^StuffIt}n) && + super + end + end end end diff --git a/Library/Homebrew/cask/lib/hbc/container/tar.rb b/Library/Homebrew/cask/lib/hbc/container/tar.rb index 8bc7c5f64..df77e454d 100644 --- a/Library/Homebrew/cask/lib/hbc/container/tar.rb +++ b/Library/Homebrew/cask/lib/hbc/container/tar.rb @@ -2,17 +2,21 @@ require "tmpdir" require "hbc/container/base" -class Hbc::Container::Tar < Hbc::Container::Base - def self.me?(criteria) - criteria.magic_number(%r{^.{257}ustar}n) || - # or compressed tar (bzip2/gzip/lzma/xz) - IO.popen(["/usr/bin/tar", "-t", "-f", criteria.path.to_s], err: "/dev/null") { |io| !io.read(1).nil? } - end +module Hbc + class Container + class Tar < Base + def self.me?(criteria) + criteria.magic_number(%r{^.{257}ustar}n) || + # or compressed tar (bzip2/gzip/lzma/xz) + IO.popen(["/usr/bin/tar", "-t", "-f", criteria.path.to_s], err: "/dev/null") { |io| !io.read(1).nil? } + end - def extract - Dir.mktmpdir do |unpack_dir| - @command.run!("/usr/bin/tar", args: ["-x", "-f", @path, "-C", unpack_dir]) - @command.run!("/usr/bin/ditto", args: ["--", unpack_dir, @cask.staged_path]) + def extract + Dir.mktmpdir do |unpack_dir| + @command.run!("/usr/bin/tar", args: ["-x", "-f", @path, "-C", unpack_dir]) + @command.run!("/usr/bin/ditto", args: ["--", unpack_dir, @cask.staged_path]) + end + end end end end diff --git a/Library/Homebrew/cask/lib/hbc/container/ttf.rb b/Library/Homebrew/cask/lib/hbc/container/ttf.rb index 8d787f360..62ca29b22 100644 --- a/Library/Homebrew/cask/lib/hbc/container/ttf.rb +++ b/Library/Homebrew/cask/lib/hbc/container/ttf.rb @@ -1,10 +1,14 @@ require "hbc/container/naked" -class Hbc::Container::Ttf < Hbc::Container::Naked - def self.me?(criteria) - # TrueType Font - criteria.magic_number(%r{^\000\001\000\000\000}n) || - # Truetype Font Collection - criteria.magic_number(%r{^ttcf}n) +module Hbc + class Container + class Ttf < Naked + def self.me?(criteria) + # TrueType Font + criteria.magic_number(%r{^\000\001\000\000\000}n) || + # Truetype Font Collection + criteria.magic_number(%r{^ttcf}n) + end + end end end diff --git a/Library/Homebrew/cask/lib/hbc/container/xar.rb b/Library/Homebrew/cask/lib/hbc/container/xar.rb index 5afc78bc5..228ab2343 100644 --- a/Library/Homebrew/cask/lib/hbc/container/xar.rb +++ b/Library/Homebrew/cask/lib/hbc/container/xar.rb @@ -2,15 +2,19 @@ require "tmpdir" require "hbc/container/base" -class Hbc::Container::Xar < Hbc::Container::Base - def self.me?(criteria) - criteria.magic_number(%r{^xar!}n) - end +module Hbc + class Container + class Xar < Base + def self.me?(criteria) + criteria.magic_number(%r{^xar!}n) + end - def extract - Dir.mktmpdir do |unpack_dir| - @command.run!("/usr/bin/xar", args: ["-x", "-f", @path, "-C", unpack_dir]) - @command.run!("/usr/bin/ditto", args: ["--", unpack_dir, @cask.staged_path]) + def extract + Dir.mktmpdir do |unpack_dir| + @command.run!("/usr/bin/xar", args: ["-x", "-f", @path, "-C", unpack_dir]) + @command.run!("/usr/bin/ditto", args: ["--", unpack_dir, @cask.staged_path]) + end + end end end end diff --git a/Library/Homebrew/cask/lib/hbc/container/xip.rb b/Library/Homebrew/cask/lib/hbc/container/xip.rb index 579f28fe0..2d0f17e2e 100644 --- a/Library/Homebrew/cask/lib/hbc/container/xip.rb +++ b/Library/Homebrew/cask/lib/hbc/container/xip.rb @@ -1,24 +1,28 @@ require "tmpdir" -class Hbc::Container::Xip < Hbc::Container::Base - def self.me?(criteria) - criteria.magic_number(%r{^xar!}n) && - IO.popen(["/usr/bin/xar", "-t", "-f", criteria.path.to_s], err: "/dev/null") { |io| io.read =~ %r{\AContent\nMetadata\n\Z} } - end - - def extract - Dir.mktmpdir do |unpack_dir| - begin - ohai "Verifying signature for #{@path.basename}" - @command.run!("/usr/sbin/pkgutil", args: ["--check-signature", @path]) - rescue - raise "Signature check failed." +module Hbc + class Container + class Xip < Base + def self.me?(criteria) + criteria.magic_number(%r{^xar!}n) && + IO.popen(["/usr/bin/xar", "-t", "-f", criteria.path.to_s], err: "/dev/null") { |io| io.read =~ %r{\AContent\nMetadata\n\Z} } end - @command.run!("/usr/bin/xar", args: ["-x", "-f", @path, "Content", "-C", unpack_dir]) + def extract + Dir.mktmpdir do |unpack_dir| + begin + ohai "Verifying signature for #{@path.basename}" + @command.run!("/usr/sbin/pkgutil", args: ["--check-signature", @path]) + rescue + raise "Signature check failed." + end + + @command.run!("/usr/bin/xar", args: ["-x", "-f", @path, "Content", "-C", unpack_dir]) - Dir.chdir(@cask.staged_path) do - @command.run!("/usr/bin/cpio", args: ["--quiet", "-i", "-I", Pathname(unpack_dir).join("Content")]) + Dir.chdir(@cask.staged_path) do + @command.run!("/usr/bin/cpio", args: ["--quiet", "-i", "-I", Pathname(unpack_dir).join("Content")]) + end + end end end end diff --git a/Library/Homebrew/cask/lib/hbc/container/xz.rb b/Library/Homebrew/cask/lib/hbc/container/xz.rb index 228532943..831bef5aa 100644 --- a/Library/Homebrew/cask/lib/hbc/container/xz.rb +++ b/Library/Homebrew/cask/lib/hbc/container/xz.rb @@ -2,22 +2,26 @@ require "tmpdir" require "hbc/container/base" -class Hbc::Container::Xz < Hbc::Container::Base - def self.me?(criteria) - criteria.magic_number(%r{^\xFD7zXZ\x00}n) - end +module Hbc + class Container + class Xz < Base + def self.me?(criteria) + criteria.magic_number(%r{^\xFD7zXZ\x00}n) + end - def extract - unxz = Hbc.homebrew_prefix.join("bin", "unxz") + def extract + unxz = Hbc.homebrew_prefix.join("bin", "unxz") - unless unxz.exist? - raise Hbc::CaskError, "Expected to find unxz executable. Cask '#{@cask}' must add: depends_on formula: 'xz'" - end + unless unxz.exist? + raise CaskError, "Expected to find unxz executable. Cask '#{@cask}' must add: depends_on formula: 'xz'" + end - Dir.mktmpdir do |unpack_dir| - @command.run!("/usr/bin/ditto", args: ["--", @path, unpack_dir]) - @command.run!(unxz, args: ["-q", "--", Pathname(unpack_dir).join(@path.basename)]) - @command.run!("/usr/bin/ditto", args: ["--", unpack_dir, @cask.staged_path]) + Dir.mktmpdir do |unpack_dir| + @command.run!("/usr/bin/ditto", args: ["--", @path, unpack_dir]) + @command.run!(unxz, args: ["-q", "--", Pathname(unpack_dir).join(@path.basename)]) + @command.run!("/usr/bin/ditto", args: ["--", unpack_dir, @cask.staged_path]) + end + end end end end diff --git a/Library/Homebrew/cask/lib/hbc/container/zip.rb b/Library/Homebrew/cask/lib/hbc/container/zip.rb index c6702fbb5..86e2d1bd6 100644 --- a/Library/Homebrew/cask/lib/hbc/container/zip.rb +++ b/Library/Homebrew/cask/lib/hbc/container/zip.rb @@ -1,15 +1,19 @@ require "hbc/container/base" -class Hbc::Container::Zip < Hbc::Container::Base - def self.me?(criteria) - criteria.magic_number(%r{^PK(\003\004|\005\006)}n) - end +module Hbc + class Container + class Zip < Base + def self.me?(criteria) + criteria.magic_number(%r{^PK(\003\004|\005\006)}n) + end - def extract - Dir.mktmpdir do |unpack_dir| - @command.run!("/usr/bin/ditto", args: ["-x", "-k", "--", @path, unpack_dir]) + def extract + Dir.mktmpdir do |unpack_dir| + @command.run!("/usr/bin/ditto", args: ["-x", "-k", "--", @path, unpack_dir]) - extract_nested_inside(unpack_dir) + extract_nested_inside(unpack_dir) + end + end end end end |
