mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
39 lines
881 B
Ruby
39 lines
881 B
Ruby
# frozen_string_literal: true
|
|
|
|
module UnpackStrategy
|
|
# Strategy for unpacking ZIP archives.
|
|
class Zip
|
|
include UnpackStrategy
|
|
|
|
using Magic
|
|
|
|
def self.extensions
|
|
[".zip"]
|
|
end
|
|
|
|
def self.can_extract?(path)
|
|
path.magic_number.match?(/\APK(\003\004|\005\006)/n)
|
|
end
|
|
|
|
private
|
|
|
|
def contains_extended_attributes?(path)
|
|
path.zipinfo.grep(/(^__MACOSX|\._)/).any?
|
|
end
|
|
|
|
def extract_to_dir(unpack_dir, basename:, verbose:)
|
|
quiet_flags = verbose ? [] : ["-qq"]
|
|
result = system_command! "unzip",
|
|
args: [*quiet_flags, "-o", path, "-d", unpack_dir],
|
|
verbose: verbose,
|
|
print_stderr: false
|
|
|
|
FileUtils.rm_rf unpack_dir/"__MACOSX"
|
|
|
|
result
|
|
end
|
|
end
|
|
end
|
|
|
|
require "extend/os/mac/unpack_strategy/zip" if OS.mac?
|