Skip to content

Commit

Permalink
Add signatures for extraction methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
reitermarkus authored and pull[bot] committed Mar 9, 2023
1 parent 3019f45 commit 6e91c35
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 13 deletions.
2 changes: 1 addition & 1 deletion Library/Homebrew/cask/audit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ def audit_signing
Dir.mktmpdir do |tmpdir|
tmpdir = Pathname(tmpdir)
primary_container.extract_nestedly(to: tmpdir, basename: downloaded_path.basename, verbose: false)

artifacts.each do |artifact|
path = case artifact
when Artifact::Moved
Expand All @@ -501,7 +502,6 @@ def audit_signing
next unless path.exist?

result = system_command("codesign", args: ["--verify", path], print_stderr: false)

next if result.success?

message = "Signature verification failed:\n#{result.merged_output}\nmacOS on ARM requires applications " \
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/download_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ def quiet?
# @api public
def stage(&block)
UnpackStrategy.detect(cached_location,
prioritise_extension: true,
prioritize_extension: true,
ref_type: @ref_type, ref: @ref)
.extract_nestedly(basename: basename,
prioritise_extension: true,
prioritize_extension: true,
verbose: verbose? && !quiet?)
chdir(&block) if block
end
Expand Down
27 changes: 20 additions & 7 deletions Library/Homebrew/unpack_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ def self.from_magic(path)
strategies.find { |s| s.can_extract?(path) }
end

def self.detect(path, prioritise_extension: false, type: nil, ref_type: nil, ref: nil, merge_xattrs: nil)
def self.detect(path, prioritize_extension: false, type: nil, ref_type: nil, ref: nil, merge_xattrs: nil)
strategy = from_type(type) if type

if prioritise_extension && path.extname.present?
if prioritize_extension && path.extname.present?
strategy ||= from_extension(path.extname)
strategy ||= strategies.select { |s| s < Directory || s == Fossil }
.find { |s| s.can_extract?(path) }
Expand Down Expand Up @@ -135,14 +135,27 @@ def initialize(path, ref_type: nil, ref: nil, merge_xattrs: nil)
def extract_to_dir(unpack_dir, basename:, verbose:); end
private :extract_to_dir

def extract(to: nil, basename: nil, verbose: nil)
sig {
params(
to: T.nilable(Pathname), basename: T.nilable(T.any(String, Pathname)), verbose: T::Boolean,
).returns(T.untyped)
}
def extract(to: nil, basename: nil, verbose: false)
basename ||= path.basename
unpack_dir = Pathname(to || Dir.pwd).expand_path
unpack_dir.mkpath
extract_to_dir(unpack_dir, basename: Pathname(basename), verbose: verbose || false)
extract_to_dir(unpack_dir, basename: Pathname(basename), verbose: verbose)
end

def extract_nestedly(to: nil, basename: nil, verbose: false, prioritise_extension: false)
sig {
params(
to: T.nilable(Pathname),
basename: T.nilable(T.any(String, Pathname)),
verbose: T::Boolean,
prioritize_extension: T::Boolean,
).returns(T.untyped)
}
def extract_nestedly(to: nil, basename: nil, verbose: false, prioritize_extension: false)
Dir.mktmpdir do |tmp_unpack_dir|
tmp_unpack_dir = Pathname(tmp_unpack_dir)

Expand All @@ -153,9 +166,9 @@ def extract_nestedly(to: nil, basename: nil, verbose: false, prioritise_extensio
if children.count == 1 && !children.first.directory?
FileUtils.chmod "+rw", children.first, verbose: verbose

s = UnpackStrategy.detect(children.first, prioritise_extension: prioritise_extension)
s = UnpackStrategy.detect(children.first, prioritize_extension: prioritize_extension)

s.extract_nestedly(to: to, verbose: verbose, prioritise_extension: prioritise_extension)
s.extract_nestedly(to: to, verbose: verbose, prioritize_extension: prioritize_extension)
next
end

Expand Down
14 changes: 11 additions & 3 deletions Library/Homebrew/unpack_strategy/uncompressed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,22 @@ class Uncompressed

include UnpackStrategy

def extract_nestedly(prioritise_extension: false, **options)
extract(**options)
sig {
params(
to: T.nilable(Pathname),
basename: T.nilable(T.any(String, Pathname)),
verbose: T::Boolean,
prioritize_extension: T::Boolean,
).returns(T.untyped)
}
def extract_nestedly(to: nil, basename: nil, verbose: false, prioritize_extension: false)
extract(to: to, basename: basename, verbose: verbose)
end

private

sig { override.params(unpack_dir: Pathname, basename: Pathname, verbose: T::Boolean).returns(T.untyped) }
def extract_to_dir(unpack_dir, basename:, verbose:)
def extract_to_dir(unpack_dir, basename:, verbose: false)
FileUtils.cp path, unpack_dir/basename, preserve: true, verbose: verbose
end
end
Expand Down

0 comments on commit 6e91c35

Please sign in to comment.