mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
download_strategy: don't chdir unless a block is passed
This commit is contained in:
parent
9b94234866
commit
03e59f4ec8
@ -66,9 +66,13 @@ class AbstractDownloadStrategy
|
|||||||
Context.current.quiet? || @quiet
|
Context.current.quiet? || @quiet
|
||||||
end
|
end
|
||||||
|
|
||||||
# Unpack {#cached_location} into the current working directory, and possibly
|
# Unpack {#cached_location} into the current working directory.
|
||||||
# chdir into the newly-unpacked directory.
|
#
|
||||||
# Unlike {Resource#stage}, this does not take a block.
|
# Additionally, if a block is given, the working directory was previously empty
|
||||||
|
# and a single directory is extracted from the archive, the block will be called
|
||||||
|
# with the working directory changed to that directory. Otherwise this method
|
||||||
|
# will return, or the block will be called, without changing the current working
|
||||||
|
# directory.
|
||||||
#
|
#
|
||||||
# @api public
|
# @api public
|
||||||
def stage(&block)
|
def stage(&block)
|
||||||
@ -78,7 +82,7 @@ class AbstractDownloadStrategy
|
|||||||
.extract_nestedly(basename: basename,
|
.extract_nestedly(basename: basename,
|
||||||
prioritise_extension: true,
|
prioritise_extension: true,
|
||||||
verbose: verbose? && !quiet?)
|
verbose: verbose? && !quiet?)
|
||||||
chdir(&block)
|
chdir(&block) if block
|
||||||
end
|
end
|
||||||
|
|
||||||
def chdir(&block)
|
def chdir(&block)
|
||||||
@ -86,13 +90,13 @@ class AbstractDownloadStrategy
|
|||||||
raise "Empty archive" if entries.length.zero?
|
raise "Empty archive" if entries.length.zero?
|
||||||
|
|
||||||
if entries.length != 1
|
if entries.length != 1
|
||||||
yield if block
|
yield
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if File.directory? entries.first
|
if File.directory? entries.first
|
||||||
Dir.chdir(entries.first, &block)
|
Dir.chdir(entries.first, &block)
|
||||||
elsif block
|
else
|
||||||
yield
|
yield
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user