diff options
| author | Jack Nagel | 2015-03-13 20:59:17 -0400 |
|---|---|---|
| committer | Jack Nagel | 2015-03-14 20:45:21 -0400 |
| commit | 7c63fecb7450dbf19c81e5c37a984d7d029a75eb (patch) | |
| tree | a5b4198fdf9b177b8b49047a770bc92ca3d297d3 /Library/Homebrew/extend/fileutils.rb | |
| parent | a2e8ef4505da5c872b13c46a9cfb6550e031ec3a (diff) | |
| download | homebrew-7c63fecb7450dbf19c81e5c37a984d7d029a75eb.tar.bz2 | |
Use Dir.mktmpdir instead of shelling out to mktemp
Closes #37616.
Diffstat (limited to 'Library/Homebrew/extend/fileutils.rb')
| -rw-r--r-- | Library/Homebrew/extend/fileutils.rb | 28 |
1 files changed, 12 insertions, 16 deletions
diff --git a/Library/Homebrew/extend/fileutils.rb b/Library/Homebrew/extend/fileutils.rb index aa1735cb1..a29128378 100644 --- a/Library/Homebrew/extend/fileutils.rb +++ b/Library/Homebrew/extend/fileutils.rb @@ -1,4 +1,5 @@ -require 'fileutils' +require "fileutils" +require "tmpdir" # We enhance FileUtils to make our Formula code more readable. module FileUtils @@ -6,24 +7,19 @@ 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` }.strip - raise "Failed to create sandbox" if tempd.empty? - prevd = pwd - cd(tempd) + prev = pwd + tmp = Dir.mktmpdir(prefix, HOMEBREW_TEMP) begin - yield + cd(tmp) + + begin + yield + ensure + cd(prev) + end ensure - cd(prevd) - ignore_interrupts { rm_r(tempd) } + ignore_interrupts { rm_r(tmp) } end end module_function :mktemp |
