Merge pull request #14773 from reitermarkus/extract-signatures
Add signatures for extraction functions.
This commit is contained in:
commit
2d31f80f5c
@ -95,10 +95,10 @@ class AbstractDownloadStrategy
|
||||
# @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
|
||||
|
@ -104,10 +104,10 @@ module UnpackStrategy
|
||||
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) }
|
||||
@ -135,14 +135,27 @@ module UnpackStrategy
|
||||
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)
|
||||
|
||||
@ -153,9 +166,9 @@ module UnpackStrategy
|
||||
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
|
||||
|
||||
|
@ -8,14 +8,22 @@ module UnpackStrategy
|
||||
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user