diff options
| author | Martin Afanasjew | 2015-08-15 15:19:36 +0200 |
|---|---|---|
| committer | Mike McQuaid | 2015-08-16 16:47:24 +0100 |
| commit | e85e57b217939a47ba8d7f1adfec192b47d96ec0 (patch) | |
| tree | be0867c5e704fb21aade9e8d2c0d9d957507ff91 /Library/Homebrew/cmd | |
| parent | ccb613df69980c31bdae9acc5a3cd64a644f1fa2 (diff) | |
| download | brew-e85e57b217939a47ba8d7f1adfec192b47d96ec0.tar.bz2 | |
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>
Diffstat (limited to 'Library/Homebrew/cmd')
| -rw-r--r-- | Library/Homebrew/cmd/cleanup.rb | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/Library/Homebrew/cmd/cleanup.rb b/Library/Homebrew/cmd/cleanup.rb index 8d5354673..955a6e3da 100644 --- a/Library/Homebrew/cmd/cleanup.rb +++ b/Library/Homebrew/cmd/cleanup.rb @@ -19,14 +19,8 @@ module Homebrew def cleanup_logs 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| - cleanup_path(dir) { dir.rmtree } if ARGV.force? || (dir.mtime < time) + cleanup_path(dir) { dir.rmtree } if prune?(:logs, dir.mtime) end end @@ -61,10 +55,8 @@ module Homebrew def cleanup_cache return unless HOMEBREW_CACHE.directory? - prune = ARGV.value "prune" - time = Time.now - 60 * 60 * 24 * prune.to_i HOMEBREW_CACHE.children.each do |path| - if ARGV.force? || (prune && path.mtime < time) + if prune?(:cache, path.mtime) if path.file? cleanup_path(path) { path.unlink } elsif path.directory? && path.to_s.include?("--") @@ -129,6 +121,29 @@ module Homebrew quiet_system "find", *args 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) # 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 |
