From 3fbe631b02617323964e178e847d8a58ee8502f3 Mon Sep 17 00:00:00 2001 From: Max Howell Date: Wed, 29 Aug 2012 19:17:53 -0400 Subject: [PATCH] Block form of chdir can only be used once If you nest them, the library complains. So let's not do that. /cc @jacknagel --- Library/Homebrew/extend/fileutils.rb | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Library/Homebrew/extend/fileutils.rb b/Library/Homebrew/extend/fileutils.rb index 691fbdcd2b..60f795700a 100644 --- a/Library/Homebrew/extend/fileutils.rb +++ b/Library/Homebrew/extend/fileutils.rb @@ -13,12 +13,16 @@ module FileUtils extend self # 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`.chomp) - raise "Failed to create sandbox: #{tmp}" unless tmp.directory? - cd(tmp){ yield } + tmp = ENV['HOMEBREW_TEMP'].chuzzle || '/tmp' + tempd = `/usr/bin/mktemp -d #{tmp}/brew-#{name}-#{version}-XXXX`.chuzzle + prevd = pwd + cd tempd + yield + rescue StandardError + raise "Failed to create sandbox" ensure - ignore_interrupts{ tmp.rmtree } if tmp + cd prevd if prevd + ignore_interrupts{ rm_r tempd } if tempd end # A version of mkdir that also changes to that folder in a block.