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.
|
2012-08-29 19:17:53 -04:00
|
|
|
tmp = ENV['HOMEBREW_TEMP'].chuzzle || '/tmp'
|
2013-03-10 17:03:17 +00:00
|
|
|
tempd = with_system_path { `mktemp -d #{tmp}/#{name}-XXXX` }.chuzzle
|
2012-08-29 22:25:29 -04:00
|
|
|
raise "Failed to create sandbox" if tempd.nil?
|
2012-08-29 19:17:53 -04:00
|
|
|
prevd = pwd
|
|
|
|
cd tempd
|
|
|
|
yield
|
2012-08-23 12:47:36 -04:00
|
|
|
ensure
|
2012-08-29 19:17:53 -04:00
|
|
|
cd prevd if prevd
|
|
|
|
ignore_interrupts{ rm_r tempd } if tempd
|
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
|
|
|
|
|
2012-09-27 09:52:06 -05:00
|
|
|
# The #copy_metadata method in all current versions of Ruby has a
|
|
|
|
# bad bug which causes copying symlinks across filesystems to fail;
|
|
|
|
# see #14710.
|
|
|
|
# This was resolved in Ruby HEAD after the release of 1.9.3p194, but
|
|
|
|
# as of September 2012 isn't in any released version of Ruby.
|
|
|
|
# The monkey-patched method here is copied directly from upstream fix.
|
|
|
|
if RUBY_VERSION < "1.9.3" or RUBY_PATCHLEVEL < 195
|
|
|
|
class Entry_
|
|
|
|
def copy_metadata(path)
|
|
|
|
st = lstat()
|
|
|
|
if !st.symlink?
|
|
|
|
File.utime st.atime, st.mtime, path
|
|
|
|
end
|
|
|
|
begin
|
|
|
|
if st.symlink?
|
|
|
|
begin
|
|
|
|
File.lchown st.uid, st.gid, path
|
|
|
|
rescue NotImplementedError
|
|
|
|
end
|
|
|
|
else
|
|
|
|
File.chown st.uid, st.gid, path
|
|
|
|
end
|
|
|
|
rescue Errno::EPERM
|
|
|
|
# clear setuid/setgid
|
|
|
|
if st.symlink?
|
|
|
|
begin
|
|
|
|
File.lchmod st.mode & 01777, path
|
|
|
|
rescue NotImplementedError
|
|
|
|
end
|
|
|
|
else
|
|
|
|
File.chmod st.mode & 01777, path
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if st.symlink?
|
|
|
|
begin
|
|
|
|
File.lchmod st.mode, path
|
|
|
|
rescue NotImplementedError
|
|
|
|
end
|
|
|
|
else
|
|
|
|
File.chmod st.mode, path
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-02-02 11:24:55 -06:00
|
|
|
def rake *args
|
2013-03-10 17:02:06 +00:00
|
|
|
system RUBY_BIN/'rake', *args
|
2013-02-02 11:24:55 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
def ruby *args
|
2013-03-10 17:02:06 +00:00
|
|
|
system RUBY_PATH, *args
|
2013-02-02 11:24:55 -06:00
|
|
|
end
|
2012-03-04 16:48:00 -08:00
|
|
|
end
|