Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

formula: move mktemp. #4472

Merged
merged 1 commit into from
Jul 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 11 additions & 11 deletions Library/Homebrew/formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1689,7 +1689,7 @@ def run_test

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
Expand Down Expand Up @@ -1897,6 +1897,16 @@ def eligible_kegs_for_cleanup
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.
Expand Down Expand Up @@ -2465,16 +2475,6 @@ def pour_bottle?(&block)
@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!
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/mktemp.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def clear_cache
# 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"
Expand Down