Only search by extension when unpacking formulae.
This commit is contained in:
parent
f8dc9eff58
commit
4c80f827ad
@ -47,8 +47,11 @@ class AbstractDownloadStrategy
|
|||||||
# chdir into the newly-unpacked directory.
|
# chdir into the newly-unpacked directory.
|
||||||
# Unlike {Resource#stage}, this does not take a block.
|
# Unlike {Resource#stage}, this does not take a block.
|
||||||
def stage
|
def stage
|
||||||
UnpackStrategy.detect(cached_location, ref_type: @ref_type, ref: @ref)
|
UnpackStrategy.detect(cached_location,
|
||||||
|
extension_only: true,
|
||||||
|
ref_type: @ref_type, ref: @ref)
|
||||||
.extract_nestedly(basename: basename_without_params,
|
.extract_nestedly(basename: basename_without_params,
|
||||||
|
extension_only: true,
|
||||||
verbose: ARGV.verbose? && !shutup)
|
verbose: ARGV.verbose? && !shutup)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -66,6 +66,7 @@ module UnpackStrategy
|
|||||||
def self.from_type(type)
|
def self.from_type(type)
|
||||||
type = {
|
type = {
|
||||||
naked: :uncompressed,
|
naked: :uncompressed,
|
||||||
|
nounzip: :uncompressed,
|
||||||
seven_zip: :p7zip,
|
seven_zip: :p7zip,
|
||||||
}.fetch(type, type)
|
}.fetch(type, type)
|
||||||
|
|
||||||
@ -76,21 +77,30 @@ module UnpackStrategy
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.from_path(path)
|
def self.from_extension(extension)
|
||||||
strategy = strategies
|
strategies.sort_by { |s| s.extensions.map(&:length).max(0) }
|
||||||
.sort_by { |s| s.extensions.map(&:length).max(0) }
|
.reverse
|
||||||
.reverse
|
.detect { |s| s.extensions.any? { |ext| extension.end_with?(ext) } }
|
||||||
.detect { |s| s.extensions.include?(path.extname) }
|
end
|
||||||
|
|
||||||
strategy ||= strategies.detect { |s| s.can_extract?(path) }
|
def self.from_magic(path)
|
||||||
|
strategies.detect { |s| s.can_extract?(path) }
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.detect(path, extension_only: false, type: nil, ref_type: nil, ref: nil)
|
||||||
|
strategy = from_type(type) if type
|
||||||
|
|
||||||
|
if extension_only
|
||||||
|
strategy ||= from_extension(path.extname)
|
||||||
|
strategy ||= strategies.select { |s| s < Directory || s == Fossil }
|
||||||
|
.detect { |s| s.can_extract?(path) }
|
||||||
|
else
|
||||||
|
strategy ||= from_magic(path)
|
||||||
|
strategy ||= from_extension(path.extname)
|
||||||
|
end
|
||||||
|
|
||||||
strategy ||= Uncompressed
|
strategy ||= Uncompressed
|
||||||
|
|
||||||
strategy
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.detect(path, type: nil, ref_type: nil, ref: nil)
|
|
||||||
strategy = type ? from_type(type) : from_path(path)
|
|
||||||
strategy.new(path, ref_type: ref_type, ref: ref)
|
strategy.new(path, ref_type: ref_type, ref: ref)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -109,7 +119,7 @@ module UnpackStrategy
|
|||||||
extract_to_dir(unpack_dir, basename: basename, verbose: verbose)
|
extract_to_dir(unpack_dir, basename: basename, verbose: verbose)
|
||||||
end
|
end
|
||||||
|
|
||||||
def extract_nestedly(to: nil, basename: nil, verbose: false)
|
def extract_nestedly(to: nil, basename: nil, verbose: false, extension_only: false)
|
||||||
Dir.mktmpdir do |tmp_unpack_dir|
|
Dir.mktmpdir do |tmp_unpack_dir|
|
||||||
tmp_unpack_dir = Pathname(tmp_unpack_dir)
|
tmp_unpack_dir = Pathname(tmp_unpack_dir)
|
||||||
|
|
||||||
@ -118,9 +128,9 @@ module UnpackStrategy
|
|||||||
children = tmp_unpack_dir.children
|
children = tmp_unpack_dir.children
|
||||||
|
|
||||||
if children.count == 1 && !children.first.directory?
|
if children.count == 1 && !children.first.directory?
|
||||||
s = UnpackStrategy.detect(children.first)
|
s = UnpackStrategy.detect(children.first, extension_only: extension_only)
|
||||||
|
|
||||||
s.extract_nestedly(to: to, verbose: verbose)
|
s.extract_nestedly(to: to, verbose: verbose, extension_only: extension_only)
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,9 @@ module UnpackStrategy
|
|||||||
class Uncompressed
|
class Uncompressed
|
||||||
include UnpackStrategy
|
include UnpackStrategy
|
||||||
|
|
||||||
alias extract_nestedly extract
|
def extract_nestedly(extension_only: false, **options)
|
||||||
|
extract(**options)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user