Move HOMEBREW_CACHE to ~/Library/Caches (#292)
* cleanup: accept cache as an argument. * config: move default HOMEBREW_CACHE to ~/Library. * brew.1: document new default Homebrew cache. * update-report: migrate legacy Homebrew cache.
This commit is contained in:
parent
8486f6e04d
commit
a9abbab917
@ -43,9 +43,9 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.cleanup_cache
|
def self.cleanup_cache(cache=HOMEBREW_CACHE)
|
||||||
return unless HOMEBREW_CACHE.directory?
|
return unless cache.directory?
|
||||||
HOMEBREW_CACHE.children.each do |path|
|
cache.children.each do |path|
|
||||||
if path.to_s.end_with? ".incomplete"
|
if path.to_s.end_with? ".incomplete"
|
||||||
cleanup_path(path) { path.unlink }
|
cleanup_path(path) { path.unlink }
|
||||||
next
|
next
|
||||||
|
|||||||
@ -2,6 +2,7 @@ require "formula_versions"
|
|||||||
require "migrator"
|
require "migrator"
|
||||||
require "formulary"
|
require "formulary"
|
||||||
require "descriptions"
|
require "descriptions"
|
||||||
|
require "cleanup"
|
||||||
|
|
||||||
module Homebrew
|
module Homebrew
|
||||||
def update_preinstall_header
|
def update_preinstall_header
|
||||||
@ -69,6 +70,8 @@ module Homebrew
|
|||||||
updated = true
|
updated = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
migrate_legacy_cache_if_necessary
|
||||||
|
|
||||||
if !updated
|
if !updated
|
||||||
if !ARGV.include?("--preinstall") && !ENV["HOMEBREW_UPDATE_FAILED"]
|
if !ARGV.include?("--preinstall") && !ENV["HOMEBREW_UPDATE_FAILED"]
|
||||||
puts "Already up-to-date."
|
puts "Already up-to-date."
|
||||||
@ -101,6 +104,52 @@ module Homebrew
|
|||||||
ENV["HOMEBREW_UPDATE_BEFORE_HOMEBREW_HOMEBREW_CORE"] = revision
|
ENV["HOMEBREW_UPDATE_BEFORE_HOMEBREW_HOMEBREW_CORE"] = revision
|
||||||
ENV["HOMEBREW_UPDATE_AFTER_HOMEBREW_HOMEBREW_CORE"] = revision
|
ENV["HOMEBREW_UPDATE_AFTER_HOMEBREW_HOMEBREW_CORE"] = revision
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def migrate_legacy_cache_if_necessary
|
||||||
|
legacy_cache = Pathname.new "/Library/Caches/Homebrew"
|
||||||
|
return if HOMEBREW_CACHE.to_s == legacy_cache.to_s
|
||||||
|
return unless legacy_cache.directory?
|
||||||
|
return unless legacy_cache.readable_real?
|
||||||
|
|
||||||
|
migration_attempted_file = legacy_cache/".migration_attempted"
|
||||||
|
return if migration_attempted_file.exist?
|
||||||
|
|
||||||
|
return unless legacy_cache.writable_real?
|
||||||
|
FileUtils.touch migration_attempted_file
|
||||||
|
|
||||||
|
# Cleanup to avoid copying files unnecessarily
|
||||||
|
ohai "Cleaning up #{legacy_cache}..."
|
||||||
|
Cleanup.cleanup_cache legacy_cache
|
||||||
|
|
||||||
|
# This directory could have been compromised if it's world-writable/
|
||||||
|
# a symlink/owned by another user so don't copy files in those cases.
|
||||||
|
return if legacy_cache.world_writable?
|
||||||
|
return if legacy_cache.symlink?
|
||||||
|
return if !legacy_cache.owned? && legacy_cache.lstat.uid != 0
|
||||||
|
|
||||||
|
ohai "Migrating #{legacy_cache} to #{HOMEBREW_CACHE}..."
|
||||||
|
HOMEBREW_CACHE.mkpath
|
||||||
|
legacy_cache.cd do
|
||||||
|
legacy_cache.entries.each do |f|
|
||||||
|
next if [".", "..", ".migration_attempted"].include? "#{f}"
|
||||||
|
begin
|
||||||
|
FileUtils.cp_r f, HOMEBREW_CACHE
|
||||||
|
rescue
|
||||||
|
@migration_failed ||= true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if @migration_failed
|
||||||
|
opoo <<-EOS.undent
|
||||||
|
Failed to migrate #{legacy_cache} to
|
||||||
|
#{HOMEBREW_CACHE}. Please do so manually.
|
||||||
|
EOS
|
||||||
|
else
|
||||||
|
ohai "Deleting #{legacy_cache}..."
|
||||||
|
FileUtils.rm_rf legacy_cache
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
class Reporter
|
class Reporter
|
||||||
|
|||||||
@ -1,27 +1,4 @@
|
|||||||
def cache
|
HOMEBREW_CACHE = Pathname.new(ENV["HOMEBREW_CACHE"] || "~/Library/Caches/Homebrew").expand_path
|
||||||
if ENV["HOMEBREW_CACHE"]
|
|
||||||
Pathname.new(ENV["HOMEBREW_CACHE"]).expand_path
|
|
||||||
else
|
|
||||||
# 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? && home_cache.writable_real?
|
|
||||||
home_cache
|
|
||||||
else
|
|
||||||
Pathname.new("/Library/Caches/Homebrew").extend Module.new {
|
|
||||||
def mkpath
|
|
||||||
unless exist?
|
|
||||||
super
|
|
||||||
chmod 0775
|
|
||||||
end
|
|
||||||
end
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
HOMEBREW_CACHE = cache
|
|
||||||
undef cache
|
|
||||||
|
|
||||||
# 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"
|
||||||
|
|||||||
@ -118,8 +118,7 @@ can take several different forms:
|
|||||||
* `HOMEBREW_CACHE`:
|
* `HOMEBREW_CACHE`:
|
||||||
If set, instructs Homebrew to use the given directory as the download cache.
|
If set, instructs Homebrew to use the given directory as the download cache.
|
||||||
|
|
||||||
*Default:* `~/Library/Caches/Homebrew` if it exists; otherwise,
|
*Default:* `~/Library/Caches/Homebrew`.
|
||||||
`/Library/Caches/Homebrew`.
|
|
||||||
|
|
||||||
* `HOMEBREW_CURL_VERBOSE`:
|
* `HOMEBREW_CURL_VERBOSE`:
|
||||||
If set, Homebrew will pass `--verbose` when invoking `curl`(1).
|
If set, Homebrew will pass `--verbose` when invoking `curl`(1).
|
||||||
|
|||||||
@ -523,8 +523,7 @@ Homebrew developers. Please do not file issues if you encounter errors when
|
|||||||
using this environment variable.</p></dd>
|
using this environment variable.</p></dd>
|
||||||
<dt><code>HOMEBREW_CACHE</code></dt><dd><p>If set, instructs Homebrew to use the given directory as the download cache.</p>
|
<dt><code>HOMEBREW_CACHE</code></dt><dd><p>If set, instructs Homebrew to use the given directory as the download cache.</p>
|
||||||
|
|
||||||
<p><em>Default:</em> <code>~/Library/Caches/Homebrew</code> if it exists; otherwise,
|
<p><em>Default:</em> <code>~/Library/Caches/Homebrew</code>.</p></dd>
|
||||||
<code>/Library/Caches/Homebrew</code>.</p></dd>
|
|
||||||
<dt><code>HOMEBREW_CURL_VERBOSE</code></dt><dd><p>If set, Homebrew will pass <code>--verbose</code> when invoking <code>curl</code>(1).</p></dd>
|
<dt><code>HOMEBREW_CURL_VERBOSE</code></dt><dd><p>If set, Homebrew will pass <code>--verbose</code> when invoking <code>curl</code>(1).</p></dd>
|
||||||
<dt><code>HOMEBREW_DEBUG</code></dt><dd><p>If set, any commands that can emit debugging information will do so.</p></dd>
|
<dt><code>HOMEBREW_DEBUG</code></dt><dd><p>If set, any commands that can emit debugging information will do so.</p></dd>
|
||||||
<dt><code>HOMEBREW_DEBUG_INSTALL</code></dt><dd><p>When <code>brew install -d</code> or <code>brew install -i</code> drops into a shell,
|
<dt><code>HOMEBREW_DEBUG_INSTALL</code></dt><dd><p>When <code>brew install -d</code> or <code>brew install -i</code> drops into a shell,
|
||||||
|
|||||||
@ -720,7 +720,7 @@ If set, instructs Homebrew to compile from source even when a formula provides a
|
|||||||
If set, instructs Homebrew to use the given directory as the download cache\.
|
If set, instructs Homebrew to use the given directory as the download cache\.
|
||||||
.
|
.
|
||||||
.IP
|
.IP
|
||||||
\fIDefault:\fR \fB~/Library/Caches/Homebrew\fR if it exists; otherwise, \fB/Library/Caches/Homebrew\fR\.
|
\fIDefault:\fR \fB~/Library/Caches/Homebrew\fR\.
|
||||||
.
|
.
|
||||||
.TP
|
.TP
|
||||||
\fBHOMEBREW_CURL_VERBOSE\fR
|
\fBHOMEBREW_CURL_VERBOSE\fR
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user