Add with_system_path to run using system PATHs.

Needed for Linux compatibility.
This commit is contained in:
Mike McQuaid 2013-03-10 17:03:17 +00:00
parent d39280bdf7
commit 9837bbda55
3 changed files with 12 additions and 4 deletions

View File

@ -88,12 +88,12 @@ class CurlDownloadStrategy < AbstractDownloadStrategy
case @tarball_path.compression_type case @tarball_path.compression_type
when :zip when :zip
quiet_safe_system '/usr/bin/unzip', {:quiet_flag => '-qq'}, @tarball_path with_system_path { quiet_safe_system 'unzip', {:quiet_flag => '-qq'}, @tarball_path }
chdir chdir
when :gzip, :bzip2, :compress, :tar when :gzip, :bzip2, :compress, :tar
# Assume these are also tarred # Assume these are also tarred
# TODO check if it's really a tar archive # TODO check if it's really a tar archive
safe_system '/usr/bin/tar', 'xf', @tarball_path with_system_path { safe_system 'tar', 'xf', @tarball_path }
chdir chdir
when :xz when :xz
raise "You must install XZutils: brew install xz" unless which "xz" raise "You must install XZutils: brew install xz" unless which "xz"
@ -178,7 +178,7 @@ end
class GzipOnlyDownloadStrategy < CurlDownloadStrategy class GzipOnlyDownloadStrategy < CurlDownloadStrategy
def stage def stage
FileUtils.mv @tarball_path, File.basename(@url) FileUtils.mv @tarball_path, File.basename(@url)
safe_system '/usr/bin/gunzip', '-f', File.basename(@url) with_system_path { safe_system 'gunzip', '-f', File.basename(@url) }
end end
end end

View File

@ -14,7 +14,7 @@ module FileUtils extend self
# /tmp volume to the other volume. So we let the user override the tmp # /tmp volume to the other volume. So we let the user override the tmp
# prefix if they need to. # prefix if they need to.
tmp = ENV['HOMEBREW_TEMP'].chuzzle || '/tmp' tmp = ENV['HOMEBREW_TEMP'].chuzzle || '/tmp'
tempd = `/usr/bin/mktemp -d #{tmp}/#{name}-XXXX`.chuzzle tempd = with_system_path { `mktemp -d #{tmp}/#{name}-XXXX` }.chuzzle
raise "Failed to create sandbox" if tempd.nil? raise "Failed to create sandbox" if tempd.nil?
prevd = pwd prevd = pwd
cd tempd cd tempd

View File

@ -99,6 +99,14 @@ module Homebrew
end end
end end
def with_system_path
old_path = ENV['PATH']
ENV['PATH'] = '/usr/bin:/bin'
yield
ensure
ENV['PATH'] = old_path
end
# Kernel.system but with exceptions # Kernel.system but with exceptions
def safe_system cmd, *args def safe_system cmd, *args
unless Homebrew.system cmd, *args unless Homebrew.system cmd, *args