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

move mktemp method into homebrew-fork resource.rb #8335

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions lib/homebrew-fork/Library/Homebrew/extend/fileutils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,6 @@
# We enhance FileUtils to make our Formula code more readable.
module FileUtils

# Create a temporary directory then yield. When the block returns,
# recursively delete the temporary directory.
def mktemp(prefix=name)
# I used /tmp rather than `mktemp -td` because that generates a directory
# name with exotic characters like + in it, and these break badly written
# scripts that don't escape strings before trying to regexp them :(

# If the user has FileVault enabled, then we can't mv symlinks from the
# /tmp volume to the other volume. So we let the user override the tmp
# prefix if they need to.

tempd = with_system_path { `mktemp -d #{HOMEBREW_TEMP}/#{prefix}-XXXXXX` }.chuzzle
raise "Failed to create sandbox" if tempd.nil?
prevd = pwd
cd tempd
yield
ensure
cd prevd if prevd
ignore_interrupts{ rm_r tempd } if tempd
end
module_function :mktemp

# A version of mkdir that also changes to that folder in a block.
alias_method :old_mkdir, :mkdir
def mkdir name, &block
Expand Down
22 changes: 21 additions & 1 deletion lib/homebrew-fork/Library/Homebrew/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
# primary formula download, along with other declared resources, are instances
# of this class.
class Resource
include FileUtils

attr_reader :checksum, :mirrors, :specs, :using
attr_writer :url, :checksum, :version
Expand All @@ -27,6 +26,27 @@ def initialize name=nil, &block
instance_eval(&block) if block_given?
end

# Create a temporary directory then yield. When the block returns,
# recursively delete the temporary directory.
def mktemp(prefix=name)
# I used /tmp rather than `mktemp -td` because that generates a directory
# name with exotic characters like + in it, and these break badly written
# scripts that don't escape strings before trying to regexp them :(

# If the user has FileVault enabled, then we can't mv symlinks from the
# /tmp volume to the other volume. So we let the user override the tmp
# prefix if they need to.

tempd = with_system_path { `mktemp -d #{HOMEBREW_TEMP}/#{prefix}-XXXXXX` }.chuzzle
raise "Failed to create sandbox" if tempd.nil?
prevd = pwd
cd tempd
yield
ensure
cd prevd if prevd
ignore_interrupts{ rm_r tempd } if tempd
end

def downloader
@downloader ||= download_strategy.new(download_name, self)
end
Expand Down