diff options
| author | Max Howell | 2012-03-06 20:12:42 +0000 |
|---|---|---|
| committer | Max Howell | 2012-03-06 20:28:06 +0000 |
| commit | 6da4a9a6f4428ee1f9ab9cdaf53b82dc8f1ab1dc (patch) | |
| tree | e4d193c474c1744eb0286c2a116ec1490768ec61 /Library/Homebrew/cmd/cleanup.rb | |
| parent | 1cdad6f20136783842cb8ed918a0beedf6eaa2dc (diff) | |
| download | homebrew-6da4a9a6f4428ee1f9ab9cdaf53b82dc8f1ab1dc.tar.bz2 | |
`brew cleanup` cleans up the download-cache
Manpage updated.
The -s switch is "scrub" and removes downloads for uninstall formula which are downloads for the latest version of that formula still.
Please NOTE cache is NOT cleaned if a formula argument is provided. I couldn't be bothered. Patches welcome :)
Closes #2923.
Diffstat (limited to 'Library/Homebrew/cmd/cleanup.rb')
| -rw-r--r-- | Library/Homebrew/cmd/cleanup.rb | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/Library/Homebrew/cmd/cleanup.rb b/Library/Homebrew/cmd/cleanup.rb index 0aec10f56..0f2a1875d 100644 --- a/Library/Homebrew/cmd/cleanup.rb +++ b/Library/Homebrew/cmd/cleanup.rb @@ -2,6 +2,7 @@ require 'formula' require 'cmd/prune' module Homebrew extend self + def cleanup if ARGV.named.empty? HOMEBREW_CELLAR.children.each do |rack| @@ -12,8 +13,9 @@ module Homebrew extend self # instead of core formulae. end end + clean_cache # seems like a good time to do some additional cleanup - Homebrew.prune unless ARGV.include? '-n' + Homebrew.prune unless ARGV.switch? 'n' else ARGV.formulae.each do |f| cleanup_formula f @@ -35,9 +37,8 @@ module Homebrew extend self if f.installed? and f.rack.directory? f.rack.children.each do |keg| if f.installed_prefix != keg - print "Removing #{keg}..." - rm_rf keg unless ARGV.include? '-n' - puts + puts "Removing #{keg}..." + rm_rf keg unless ARGV.switch? 'n' end end elsif f.rack.children.length > 1 @@ -47,4 +48,17 @@ module Homebrew extend self end end + def clean_cache + HOMEBREW_CACHE.children.each do |pn| + pn.stem =~ /^(.+)-(.+)$/ # greedy so works even if formula-name has hyphens in it + if $1 and $2 + f = Formula.factory($1) rescue nil + if not f or (f.version != $2 or ARGV.switch? "s" and not f.installed?) + puts "Removing #{pn}..." + rm pn unless ARGV.switch? 'n' + end + end + end + end + end |
