Use /Library/Caches/Homebrew

We don't penalise existing users; if ~/Library/Caches/Homebrew already exists and is writable, we select that.

This is the correct choice, the cache should be the same directory whichever user is used and whatever instance of brew is invoked.

The Cache directory is set to 0777 this allows any user to write to it and fixes Homebrew/homebrew#10857.
This commit is contained in:
Max Howell 2012-03-13 23:33:30 +00:00
parent b8edc0cd73
commit 6ded0d0cbb

View File

@ -13,22 +13,29 @@ 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
# we do this for historic reasons, however the cache *should* be the same
# directory whichever user is used and whatever instance of brew is executed
home_cache = Pathname.new("~/Library/Caches/Homebrew").expand_path
if home_cache.directory? and home_cache.writable?
home_cache
else
home_library = Pathname.new("~/Library/Caches/Homebrew").expand_path
if not home_library.writable?
root_library
else
home_library
root_cache = Pathname.new("/Library/Caches/Homebrew")
class << root_cache
alias :oldmkpath :mkpath
def mkpath
unless exist?
oldmkpath
chmod 0777
end
end
end
root_cache
end
end
end
HOMEBREW_CACHE = cache
undef cache
undef cache # we use a function to prevent adding home_cache to the global scope
# Where brews installed via URL are cached
HOMEBREW_CACHE_FORMULA = HOMEBREW_CACHE+"Formula"