2012-03-04 16:48:00 -08:00
|
|
|
require 'fileutils'
|
|
|
|
|
|
|
|
# We enhance FileUtils to make our Formula code more readable.
|
2012-03-06 19:23:51 -06:00
|
|
|
module FileUtils extend self
|
2012-03-04 16:48:00 -08:00
|
|
|
|
|
|
|
# Create a temporary directory then yield. When the block returns,
|
|
|
|
# recursively delete the temporary directory.
|
|
|
|
def mktemp
|
|
|
|
# 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.
|
|
|
|
tmp_prefix = ENV['HOMEBREW_TEMP'] || '/tmp'
|
2012-08-23 12:47:36 -04:00
|
|
|
tmp = Pathname.new(`/usr/bin/mktemp -d #{tmp_prefix}/homebrew-#{name}-#{version}-XXXX`.chomp)
|
|
|
|
raise "Failed to create sandbox: #{tmp}" unless tmp.directory?
|
|
|
|
cd(tmp){ yield }
|
|
|
|
ensure
|
|
|
|
ignore_interrupts{ tmp.rmtree } if tmp
|
2012-03-04 16:48:00 -08:00
|
|
|
end
|
|
|
|
|
|
|
|
# A version of mkdir that also changes to that folder in a block.
|
2012-04-30 14:17:56 +10:00
|
|
|
alias mkdir_old mkdir
|
2012-03-04 16:48:00 -08:00
|
|
|
def mkdir name, &block
|
2012-03-06 19:23:51 -06:00
|
|
|
FileUtils.mkdir(name)
|
2012-03-04 16:48:00 -08:00
|
|
|
if block_given?
|
|
|
|
chdir name do
|
|
|
|
yield
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|