download_strategy: pass chdir block to stage

This commit is contained in:
Rylan Polster 2021-02-12 11:10:18 -05:00
parent 26722647c3
commit 1cc983f00d
No known key found for this signature in database
GPG Key ID: 46A744940CFF4D64
2 changed files with 21 additions and 16 deletions

View File

@ -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

View File

@ -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)