| 
									
										
										
										
											2018-09-03 20:17:29 +01:00
										 |  |  | require "cask/cmd/abstract_command" | 
					
						
							| 
									
										
										
										
											2018-08-09 15:00:19 +02:00
										 |  |  | require "cleanup" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | using CleanupRefinement | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  | module Cask | 
					
						
							| 
									
										
										
										
											2018-09-04 08:45:48 +01:00
										 |  |  |   class Cmd | 
					
						
							| 
									
										
										
										
											2018-08-09 15:00:19 +02:00
										 |  |  |     class Cleanup < AbstractCommand | 
					
						
							|  |  |  |       OUTDATED_DAYS = 10
 | 
					
						
							|  |  |  |       OUTDATED_TIMESTAMP = Time.now - (60 * 60 * 24 * OUTDATED_DAYS) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def self.help | 
					
						
							|  |  |  |         "cleans up cached downloads and tracker symlinks" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def self.visible | 
					
						
							|  |  |  |         false | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       attr_reader :cache_location | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def initialize(*args, cache_location: Cache.path) | 
					
						
							|  |  |  |         super(*args) | 
					
						
							|  |  |  |         @cache_location = Pathname.new(cache_location) | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def run | 
					
						
							| 
									
										
										
										
											2018-08-13 14:31:21 -07:00
										 |  |  |         odeprecated "`brew cask cleanup`", "`brew cleanup`", disable_on: Time.new(2018, 9, 30) | 
					
						
							| 
									
										
										
										
											2018-08-09 15:00:19 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         cleanup = Homebrew::Cleanup.new | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         casks(alternative: -> { Cask.to_a }).each do |cask| | 
					
						
							|  |  |  |           cleanup.cleanup_cask(cask) | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         return if cleanup.disk_cleanup_size.zero? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         disk_space = disk_usage_readable(cleanup.disk_cleanup_size) | 
					
						
							|  |  |  |         ohai "This operation has freed approximately #{disk_space} of disk space." | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |