diff options
| author | Max Howell | 2012-03-07 12:51:02 +0000 | 
|---|---|---|
| committer | Max Howell | 2012-03-07 12:51:02 +0000 | 
| commit | 599cc70f39417b67b5902642f09dbba13ab42ace (patch) | |
| tree | e8bcceaf1e698ef9300822f8a41208e614c5190c /Library/Homebrew/global.rb | |
| parent | a633812f95980ec86d3b9e0547470fa5b8eec469 (diff) | |
| download | homebrew-599cc70f39417b67b5902642f09dbba13ab42ace.tar.bz2 | |
Protect against unwritable cache location
Diffstat (limited to 'Library/Homebrew/global.rb')
| -rw-r--r-- | Library/Homebrew/global.rb | 27 | 
1 files changed, 19 insertions, 8 deletions
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"  | 
