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'] if ENV['HOMEBREW_CACHE']
Pathname.new(ENV['HOMEBREW_CACHE']) Pathname.new(ENV['HOMEBREW_CACHE'])
else else
root_library = Pathname.new("/Library/Caches/Homebrew") # we do this for historic reasons, however the cache *should* be the same
if Process.uid == 0 # directory whichever user is used and whatever instance of brew is executed
root_library home_cache = Pathname.new("~/Library/Caches/Homebrew").expand_path
if home_cache.directory? and home_cache.writable?
home_cache
else else
home_library = Pathname.new("~/Library/Caches/Homebrew").expand_path root_cache = Pathname.new("/Library/Caches/Homebrew")
if not home_library.writable? class << root_cache
root_library alias :oldmkpath :mkpath
else def mkpath
home_library unless exist?
oldmkpath
chmod 0777
end
end
end end
root_cache
end end
end end
end end
HOMEBREW_CACHE = cache 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 # Where brews installed via URL are cached
HOMEBREW_CACHE_FORMULA = HOMEBREW_CACHE+"Formula" HOMEBREW_CACHE_FORMULA = HOMEBREW_CACHE+"Formula"