| 
									
										
										
										
											2012-02-01 22:36:07 -06:00
										 |  |  | require 'keg' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | module Homebrew extend self | 
					
						
							|  |  |  |   # $n and $d are used by the ObserverPathnameExtension to keep track of | 
					
						
							|  |  |  |   # certain filesystem actions. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def prune | 
					
						
							|  |  |  |     $n = 0
 | 
					
						
							|  |  |  |     $d = 0
 | 
					
						
							|  |  |  |     dirs = [] | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-11-05 18:08:52 -06:00
										 |  |  |     Keg::PRUNEABLE_DIRECTORIES.map{ |d| HOMEBREW_PREFIX/d }.each do |path| | 
					
						
							| 
									
										
										
										
											2012-04-17 17:08:36 -05:00
										 |  |  |       next unless path.directory? | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |       path.find do |path| | 
					
						
							|  |  |  |         path.extend ObserverPathnameExtension | 
					
						
							|  |  |  |         if path.symlink? | 
					
						
							| 
									
										
										
										
											2012-02-01 22:36:07 -06:00
										 |  |  |           unless path.resolved_path_exists? | 
					
						
							|  |  |  |             if ENV['HOMEBREW_KEEP_INFO'] and path.to_s =~ Keg::INFOFILE_RX | 
					
						
							|  |  |  |               path.uninstall_info | 
					
						
							|  |  |  |             end | 
					
						
							|  |  |  |             path.unlink | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  |         elsif path.directory? | 
					
						
							|  |  |  |           dirs << path | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     dirs.sort.reverse_each{ |d| d.rmdir_if_possible } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if $n == 0 and $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 | 
					
						
							|  |  |  | end |