mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
download_strategy: pass chdir block to stage
This commit is contained in:
parent
26722647c3
commit
1cc983f00d
@ -71,25 +71,29 @@ class AbstractDownloadStrategy
|
||||
# Unlike {Resource#stage}, this does not take a block.
|
||||
#
|
||||
# @api public
|
||||
def stage
|
||||
def stage(&block)
|
||||
UnpackStrategy.detect(cached_location,
|
||||
prioritise_extension: true,
|
||||
ref_type: @ref_type, ref: @ref)
|
||||
.extract_nestedly(basename: basename,
|
||||
prioritise_extension: true,
|
||||
verbose: verbose? && !quiet?)
|
||||
chdir
|
||||
chdir(&block)
|
||||
end
|
||||
|
||||
def chdir
|
||||
def chdir(&block)
|
||||
entries = Dir["*"]
|
||||
raise "Empty archive" if entries.length.zero?
|
||||
return if entries.length != 1
|
||||
|
||||
begin
|
||||
Dir.chdir entries.first
|
||||
rescue
|
||||
nil
|
||||
if entries.length != 1
|
||||
yield if block
|
||||
return
|
||||
end
|
||||
|
||||
if File.directory? entries.first
|
||||
Dir.chdir(entries.first, &block)
|
||||
elsif block
|
||||
yield
|
||||
end
|
||||
end
|
||||
private :chdir
|
||||
|
@ -114,7 +114,7 @@ class Resource
|
||||
# A target or a block must be given, but not both.
|
||||
def unpack(target = nil)
|
||||
mktemp(download_name) do |staging|
|
||||
downloader.stage
|
||||
downloader.stage do
|
||||
@source_modified_time = downloader.source_modified_time
|
||||
apply_patches
|
||||
if block_given?
|
||||
@ -125,6 +125,7 @@ class Resource
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Partial = Struct.new(:resource, :files)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user