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.
|
# Unlike {Resource#stage}, this does not take a block.
|
||||||
#
|
#
|
||||||
# @api public
|
# @api public
|
||||||
def stage
|
def stage(&block)
|
||||||
UnpackStrategy.detect(cached_location,
|
UnpackStrategy.detect(cached_location,
|
||||||
prioritise_extension: true,
|
prioritise_extension: true,
|
||||||
ref_type: @ref_type, ref: @ref)
|
ref_type: @ref_type, ref: @ref)
|
||||||
.extract_nestedly(basename: basename,
|
.extract_nestedly(basename: basename,
|
||||||
prioritise_extension: true,
|
prioritise_extension: true,
|
||||||
verbose: verbose? && !quiet?)
|
verbose: verbose? && !quiet?)
|
||||||
chdir
|
chdir(&block)
|
||||||
end
|
end
|
||||||
|
|
||||||
def chdir
|
def chdir(&block)
|
||||||
entries = Dir["*"]
|
entries = Dir["*"]
|
||||||
raise "Empty archive" if entries.length.zero?
|
raise "Empty archive" if entries.length.zero?
|
||||||
return if entries.length != 1
|
|
||||||
|
|
||||||
begin
|
if entries.length != 1
|
||||||
Dir.chdir entries.first
|
yield if block
|
||||||
rescue
|
return
|
||||||
nil
|
end
|
||||||
|
|
||||||
|
if File.directory? entries.first
|
||||||
|
Dir.chdir(entries.first, &block)
|
||||||
|
elsif block
|
||||||
|
yield
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
private :chdir
|
private :chdir
|
||||||
|
@ -114,14 +114,15 @@ class Resource
|
|||||||
# A target or a block must be given, but not both.
|
# A target or a block must be given, but not both.
|
||||||
def unpack(target = nil)
|
def unpack(target = nil)
|
||||||
mktemp(download_name) do |staging|
|
mktemp(download_name) do |staging|
|
||||||
downloader.stage
|
downloader.stage do
|
||||||
@source_modified_time = downloader.source_modified_time
|
@source_modified_time = downloader.source_modified_time
|
||||||
apply_patches
|
apply_patches
|
||||||
if block_given?
|
if block_given?
|
||||||
yield ResourceStageContext.new(self, staging)
|
yield ResourceStageContext.new(self, staging)
|
||||||
elsif target
|
elsif target
|
||||||
target = Pathname(target)
|
target = Pathname(target)
|
||||||
target.install Pathname.pwd.children
|
target.install Pathname.pwd.children
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user