Use Dir.mktmpdir instead of shelling out to mktemp
Closes Homebrew/homebrew#37616.
This commit is contained in:
parent
b03faffcc1
commit
db05618561
@ -1,4 +1,5 @@
|
|||||||
require 'fileutils'
|
require "fileutils"
|
||||||
|
require "tmpdir"
|
||||||
|
|
||||||
# We enhance FileUtils to make our Formula code more readable.
|
# We enhance FileUtils to make our Formula code more readable.
|
||||||
module FileUtils
|
module FileUtils
|
||||||
@ -6,24 +7,19 @@ module FileUtils
|
|||||||
# Create a temporary directory then yield. When the block returns,
|
# Create a temporary directory then yield. When the block returns,
|
||||||
# recursively delete the temporary directory.
|
# recursively delete the temporary directory.
|
||||||
def mktemp(prefix=name)
|
def mktemp(prefix=name)
|
||||||
# I used /tmp rather than `mktemp -td` because that generates a directory
|
prev = pwd
|
||||||
# name with exotic characters like + in it, and these break badly written
|
tmp = Dir.mktmpdir(prefix, HOMEBREW_TEMP)
|
||||||
# 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
|
begin
|
||||||
# /tmp volume to the other volume. So we let the user override the tmp
|
cd(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)
|
|
||||||
|
|
||||||
begin
|
begin
|
||||||
yield
|
yield
|
||||||
ensure
|
ensure
|
||||||
cd(prevd)
|
cd(prev)
|
||||||
ignore_interrupts { rm_r(tempd) }
|
end
|
||||||
|
ensure
|
||||||
|
ignore_interrupts { rm_r(tmp) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
module_function :mktemp
|
module_function :mktemp
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user