diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index f9fd1bf405..a58b56a176 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -1689,7 +1689,7 @@ class Formula ENV.clear_sensitive_environment! - Formula.mktemp("#{name}-test") do |staging| + mktemp("#{name}-test") do |staging| staging.retain! if ARGV.keep_tmp? @testpath = staging.tmpdir test_env[:HOME] = @testpath @@ -1897,6 +1897,16 @@ class Formula eligible_for_cleanup end + # Create a temporary directory then yield. When the block returns, + # recursively delete the temporary directory. Passing opts[:retain] + # or calling `do |staging| ... staging.retain!` in the block will skip + # the deletion and retain the temporary directory's contents. + def mktemp(prefix = name, opts = {}) + Mktemp.new(prefix, opts).run do |staging| + yield staging + end + end + private # Returns the prefix for a given formula version number. @@ -2465,16 +2475,6 @@ class Formula @pour_bottle_check.instance_eval(&block) end - # Create a temporary directory then yield. When the block returns, - # recursively delete the temporary directory. Passing opts[:retain] - # or calling `do |staging| ... staging.retain!` in the block will skip - # the deletion and retain the temporary directory's contents. - def mktemp(prefix = name, opts = {}) - Mktemp.new(prefix, opts).run do |staging| - yield staging - end - end - # @private def link_overwrite(*paths) paths.flatten! diff --git a/Library/Homebrew/mktemp.rb b/Library/Homebrew/mktemp.rb index c84b0594c6..2a8d698b44 100644 --- a/Library/Homebrew/mktemp.rb +++ b/Library/Homebrew/mktemp.rb @@ -1,4 +1,4 @@ -# Performs `Formula.mktemp`'s functionality, and tracks the results. +# Performs `Formula#mktemp`'s functionality, and tracks the results. # Each instance is only intended to be used once. class Mktemp include FileUtils diff --git a/Library/Homebrew/resource.rb b/Library/Homebrew/resource.rb index 26945b4626..0b2897bd43 100644 --- a/Library/Homebrew/resource.rb +++ b/Library/Homebrew/resource.rb @@ -82,7 +82,7 @@ class Resource # Verifies download and unpacks it # The block may call `|resource,staging| staging.retain!` to retain the staging # directory. Subclasses that override stage should implement the tmp - # dir using FileUtils.mktemp so that works with all subtypes. + # dir using Resource#mktemp so that works with all subtypes. def stage(target = nil, &block) unless target || block raise ArgumentError, "target directory or block is required"