From d830e17a126a5ea4b77d5f0771eeafbf8ed2b5e7 Mon Sep 17 00:00:00 2001 From: Max Howell Date: Wed, 7 Mar 2012 12:51:02 +0000 Subject: Protect against unwritable cache location --- Library/Homebrew/global.rb | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'Library/Homebrew') diff --git a/Library/Homebrew/global.rb b/Library/Homebrew/global.rb index 3f742db5c..b1e722b8b 100644 --- a/Library/Homebrew/global.rb +++ b/Library/Homebrew/global.rb @@ -9,16 +9,27 @@ ARGV.extend(HomebrewArgvExtension) HOMEBREW_VERSION = '0.8.1' HOMEBREW_WWW = 'http://mxcl.github.com/homebrew/' -HOMEBREW_CACHE = if ENV['HOMEBREW_CACHE'] - Pathname.new(ENV['HOMEBREW_CACHE']) -elsif Process.uid == 0 - # technically this is not the correct place, this cache is for *all users* - # so in that case, maybe we should always use it, root or not? - Pathname.new("/Library/Caches/Homebrew") -else - Pathname.new("~/Library/Caches/Homebrew").expand_path +def cache + if ENV['HOMEBREW_CACHE'] + Pathname.new(ENV['HOMEBREW_CACHE']) + else + root_library = Pathname.new("/Library/Caches/Homebrew") + if Process.uid == 0 + root_library + else + home_library = Pathname.new("~/Library/Caches/Homebrew").expand_path + if not home_library.writable? + root_library + else + home_library + end + end + end end +HOMEBREW_CACHE = cache +undef cache + # Where brews installed via URL are cached HOMEBREW_CACHE_FORMULA = HOMEBREW_CACHE+"Formula" -- cgit v1.2.3