From 03e59f4ec81cd129aaae94d4bd3b13ed64cff7ce Mon Sep 17 00:00:00 2001 From: Bo Anderson Date: Wed, 24 Feb 2021 01:13:10 +0000 Subject: [PATCH] download_strategy: don't chdir unless a block is passed --- Library/Homebrew/download_strategy.rb | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index f4199caf04..44d1ada96a 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -66,9 +66,13 @@ class AbstractDownloadStrategy Context.current.quiet? || @quiet end - # Unpack {#cached_location} into the current working directory, and possibly - # chdir into the newly-unpacked directory. - # Unlike {Resource#stage}, this does not take a block. + # Unpack {#cached_location} into the current working directory. + # + # 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 def stage(&block) @@ -78,7 +82,7 @@ class AbstractDownloadStrategy .extract_nestedly(basename: basename, prioritise_extension: true, verbose: verbose? && !quiet?) - chdir(&block) + chdir(&block) if block end def chdir(&block) @@ -86,13 +90,13 @@ class AbstractDownloadStrategy raise "Empty archive" if entries.length.zero? if entries.length != 1 - yield if block + yield return end if File.directory? entries.first Dir.chdir(entries.first, &block) - elsif block + else yield end end