diff options
| author | Jack Nagel | 2013-05-15 12:45:39 -0500 |
|---|---|---|
| committer | Jack Nagel | 2013-05-15 12:57:01 -0500 |
| commit | e237dd274cce6764816b682c79b85c5f5757d696 (patch) | |
| tree | d81450bc13f3fc283364ac28a173ff79acc18545 /Library/Homebrew/cmd | |
| parent | 24acea9c7671cb905597e7be3c1c29afc36f6d0d (diff) | |
| download | homebrew-e237dd274cce6764816b682c79b85c5f5757d696.tar.bz2 | |
prune: add dry-run mode
Diffstat (limited to 'Library/Homebrew/cmd')
| -rw-r--r-- | Library/Homebrew/cmd/prune.rb | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/Library/Homebrew/cmd/prune.rb b/Library/Homebrew/cmd/prune.rb index 7eb04c989..46c74a305 100644 --- a/Library/Homebrew/cmd/prune.rb +++ b/Library/Homebrew/cmd/prune.rb @@ -10,16 +10,20 @@ module Homebrew extend self $d = 0 dirs = [] - Keg::PRUNEABLE_DIRECTORIES.each do |dir| - next unless dir.directory? + Keg::PRUNEABLE_DIRECTORIES.select(&:directory?).each do |dir| dir.find do |path| - path.extend ObserverPathnameExtension + path.extend(ObserverPathnameExtension) if path.symlink? unless path.resolved_path_exists? if ENV['HOMEBREW_KEEP_INFO'] and path.to_s =~ Keg::INFOFILE_RX - path.uninstall_info + path.uninstall_info unless ARGV.dry_run? + end + + if ARGV.dry_run? + puts "Would remove (broken link): #{path}" + else + path.unlink end - path.unlink end elsif path.directory? dirs << path @@ -27,16 +31,22 @@ module Homebrew extend self end end - dirs.sort.reverse_each{ |d| d.rmdir_if_possible } + dirs.sort.reverse_each do |d| + if ARGV.dry_run? && d.children.empty? + puts "Would remove (empty directory): #{d}" + else + d.rmdir_if_possible + end + end - repair_taps + repair_taps unless ARGV.dry_run? - if $n == 0 and $d == 0 + if $n == 0 && $d == 0 puts "Nothing pruned" if ARGV.verbose? else print "Pruned #{$n} symbolic links " print "and #{$d} directories " if $d > 0 puts "from #{HOMEBREW_PREFIX}" - end + end unless ARGV.dry_run? end end |
