aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/extend/fileutils.rb
diff options
context:
space:
mode:
authorAdam Vandenberg2012-03-04 16:48:00 -0800
committerAdam Vandenberg2012-03-05 21:14:39 -0800
commit1b372d7840a60c8d592aa03e5c95fb41a6c5fb6b (patch)
tree9c967f79e64833166227cafbac81e8ba8c2448a4 /Library/Homebrew/extend/fileutils.rb
parent19a0aa51a1e8e5df95f9b802b165ea9ffce9cf27 (diff)
downloadbrew-1b372d7840a60c8d592aa03e5c95fb41a6c5fb6b.tar.bz2
Move path utils out of formula.rb
Make a new module for our FileUtils extensions and use that instead.
Diffstat (limited to 'Library/Homebrew/extend/fileutils.rb')
-rw-r--r--Library/Homebrew/extend/fileutils.rb40
1 files changed, 40 insertions, 0 deletions
diff --git a/Library/Homebrew/extend/fileutils.rb b/Library/Homebrew/extend/fileutils.rb
new file mode 100644
index 000000000..89c7de2fe
--- /dev/null
+++ b/Library/Homebrew/extend/fileutils.rb
@@ -0,0 +1,40 @@
+require 'fileutils'
+
+# We enhance FileUtils to make our Formula code more readable.
+module Homebrew::FileUtils
+ include FileUtils
+
+ # 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'
+ tmp=Pathname.new `/usr/bin/mktemp -d #{tmp_prefix}/homebrew-#{name}-#{version}-XXXX`.strip
+ raise "Couldn't create build sandbox" if not tmp.directory? or $? != 0
+ begin
+ wd=Dir.pwd
+ chdir tmp
+ yield
+ ensure
+ chdir wd
+ tmp.rmtree
+ end
+ end
+
+ # A version of mkdir that also changes to that folder in a block.
+ def mkdir name, &block
+ super(name)
+ if block_given?
+ chdir name do
+ yield
+ end
+ end
+ end
+
+end