cleanup: make --force less aggressive
Change behavior for `brew cleanup` as follows: - If `--force` is supplied, remove only outdated keg-only packages. - If `--prune=<days>` is supplied, remove both logs and cached downloads older than the specified number of days. Use `--prune=all` to remove all logs and cached downloads irrespective of age. - By default, remove logs after 14 days and cached downloads never. Also centralizes handling of `--prune`, thus removing duplicate logic. This is motivated by commit 17eee232838d4639b25f863aa342b1dda61b81bc that made `--force` much more aggressive and made it override whatever was specified via `--prune`, completely removing all: - outdated keg-only packages - cached downloads irrespective of age - logs irrespective of age This made it impossible to remove outdated keg-only packages without also deleting all cached downloads, which is at least inconvenient for people with limited bandwidth wanting to rebuild packages later. Closes Homebrew/homebrew#42970. Signed-off-by: Mike McQuaid <mike@mikemcquaid.com>
This commit is contained in:
parent
ccb613df69
commit
e85e57b217
@ -19,14 +19,8 @@ module Homebrew
|
|||||||
|
|
||||||
def cleanup_logs
|
def cleanup_logs
|
||||||
return unless HOMEBREW_LOGS.directory?
|
return unless HOMEBREW_LOGS.directory?
|
||||||
prune = ARGV.value "prune"
|
|
||||||
if prune
|
|
||||||
time = Time.now - 60 * 60 * 24 * prune.to_i
|
|
||||||
else
|
|
||||||
time = Time.now - 60 * 60 * 24 * 7 * 2 # two weeks
|
|
||||||
end
|
|
||||||
HOMEBREW_LOGS.subdirs.each do |dir|
|
HOMEBREW_LOGS.subdirs.each do |dir|
|
||||||
cleanup_path(dir) { dir.rmtree } if ARGV.force? || (dir.mtime < time)
|
cleanup_path(dir) { dir.rmtree } if prune?(:logs, dir.mtime)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -61,10 +55,8 @@ module Homebrew
|
|||||||
|
|
||||||
def cleanup_cache
|
def cleanup_cache
|
||||||
return unless HOMEBREW_CACHE.directory?
|
return unless HOMEBREW_CACHE.directory?
|
||||||
prune = ARGV.value "prune"
|
|
||||||
time = Time.now - 60 * 60 * 24 * prune.to_i
|
|
||||||
HOMEBREW_CACHE.children.each do |path|
|
HOMEBREW_CACHE.children.each do |path|
|
||||||
if ARGV.force? || (prune && path.mtime < time)
|
if prune?(:cache, path.mtime)
|
||||||
if path.file?
|
if path.file?
|
||||||
cleanup_path(path) { path.unlink }
|
cleanup_path(path) { path.unlink }
|
||||||
elsif path.directory? && path.to_s.include?("--")
|
elsif path.directory? && path.to_s.include?("--")
|
||||||
@ -129,6 +121,29 @@ module Homebrew
|
|||||||
quiet_system "find", *args
|
quiet_system "find", *args
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def prune?(kind, time)
|
||||||
|
unless @cleanup_prune_limit
|
||||||
|
# Infer and cache prune limits for cleanup: Use '--prune' or fall back to
|
||||||
|
# defaults (never prune download cache and prune logs after two weeks).
|
||||||
|
days = ARGV.value "prune"
|
||||||
|
offset = Time.now
|
||||||
|
@cleanup_prune_limit = {}
|
||||||
|
{ :cache => nil, :logs => 14 }.each do |k, days_default|
|
||||||
|
@cleanup_prune_limit[k] = if days == "all"
|
||||||
|
"all"
|
||||||
|
elsif days
|
||||||
|
offset - 60 * 60 * 24 * days.to_i
|
||||||
|
elsif days_default
|
||||||
|
offset - 60 * 60 * 24 * days_default
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if limit = @cleanup_prune_limit[kind]
|
||||||
|
limit == "all" || time < limit
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def eligible_for_cleanup?(formula)
|
def eligible_for_cleanup?(formula)
|
||||||
# It used to be the case that keg-only kegs could not be cleaned up, because
|
# It used to be the case that keg-only kegs could not be cleaned up, because
|
||||||
# older brews were built against the full path to the keg-only keg. Then we
|
# older brews were built against the full path to the keg-only keg. Then we
|
||||||
|
Loading…
x
Reference in New Issue
Block a user