| 
									
										
										
										
											2018-10-06 00:31:10 -04:00
										 |  |  | #:  * `cleanup` [`--prune=`<days>] [`--dry-run`] [`-s`] [<formulae>|<casks>]: | 
					
						
							| 
									
										
										
										
											2018-08-09 15:00:19 +02:00
										 |  |  | #:    Remove stale lock files and outdated downloads for formulae and casks, | 
					
						
							|  |  |  | #:    and remove old versions of installed formulae. If arguments are specified, | 
					
						
							|  |  |  | #:    only do this for the specified formulae and casks. | 
					
						
							| 
									
										
										
										
											2016-04-08 16:28:43 +02:00
										 |  |  | #: | 
					
						
							|  |  |  | #:    If `--prune=`<days> is specified, remove all cache files older than <days>. | 
					
						
							|  |  |  | #: | 
					
						
							|  |  |  | #:    If `--dry-run` or `-n` is passed, show what would be removed, but do not | 
					
						
							|  |  |  | #:    actually remove anything. | 
					
						
							|  |  |  | #: | 
					
						
							| 
									
										
										
										
											2018-08-09 15:00:19 +02:00
										 |  |  | #:    If `-s` is passed, scrub the cache, including downloads for even the latest | 
					
						
							|  |  |  | #:    versions. Note downloads for any installed formula or cask will still not | 
					
						
							| 
									
										
										
										
											2018-09-17 01:18:31 +03:00
										 |  |  | #:    be deleted. If you want to delete those too: `rm -rf "$(brew --cache)"` | 
					
						
							| 
									
										
										
										
											2016-04-08 16:28:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-29 12:57:48 +01:00
										 |  |  | require "cleanup" | 
					
						
							| 
									
										
										
										
											2018-08-08 11:20:53 +02:00
										 |  |  | require "cli_parser" | 
					
						
							| 
									
										
										
										
											2010-09-11 20:22:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 22:41:47 -05:00
										 |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2016-09-26 01:44:51 +02:00
										 |  |  |   module_function | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-12 02:02:19 +05:30
										 |  |  |   def cleanup_args | 
					
						
							|  |  |  |     Homebrew::CLI::Parser.new do | 
					
						
							|  |  |  |       usage_banner <<~EOS | 
					
						
							|  |  |  |         `cleanup` [<options>] [<formulae>|<casks>] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         Remove stale lock files and outdated downloads for formulae and casks, | 
					
						
							|  |  |  |         and remove old versions of installed formulae. If arguments are specified, | 
					
						
							|  |  |  |         only do this for the specified formulae and casks. | 
					
						
							|  |  |  |       EOS | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       flag   "--prune=", | 
					
						
							|  |  |  |         description: "Remove all cache files older than specified <days>." | 
					
						
							|  |  |  |       switch "-n", "--dry-run", | 
					
						
							|  |  |  |         description: "Show what would be removed, but do not actually remove anything." | 
					
						
							|  |  |  |       switch "-s", | 
					
						
							|  |  |  |         description: "Scrub the cache, including downloads for even the latest versions. "\ | 
					
						
							|  |  |  |                      "Note downloads for any installed formula or cask will still not be deleted. "\ | 
					
						
							|  |  |  |                      "If you want to delete those too: `rm -rf \"$(brew --cache)\"`" | 
					
						
							|  |  |  |       switch :verbose | 
					
						
							|  |  |  |       switch :debug | 
					
						
							| 
									
										
										
										
											2013-05-15 12:45:35 -05:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2018-12-12 02:02:19 +05:30
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def cleanup | 
					
						
							|  |  |  |     cleanup_args.parse | 
					
						
							| 
									
										
										
										
											2015-11-17 16:51:56 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-08 11:20:53 +02:00
										 |  |  |     cleanup = Cleanup.new(*args.remaining, dry_run: args.dry_run?, scrub: args.s?, days: args.prune&.to_i) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     cleanup.clean! | 
					
						
							| 
									
										
										
										
											2016-09-22 20:12:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-08 11:20:53 +02:00
										 |  |  |     unless cleanup.disk_cleanup_size.zero? | 
					
						
							|  |  |  |       disk_space = disk_usage_readable(cleanup.disk_cleanup_size) | 
					
						
							|  |  |  |       if args.dry_run? | 
					
						
							|  |  |  |         ohai "This operation would free approximately #{disk_space} of disk space." | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         ohai "This operation has freed approximately #{disk_space} of disk space." | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2015-11-17 16:51:56 +05:30
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-03-21 04:13:13 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-08-08 11:20:53 +02:00
										 |  |  |     return if cleanup.unremovable_kegs.empty? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-15 02:28:32 +02:00
										 |  |  |     ofail <<~EOS | 
					
						
							| 
									
										
										
										
											2017-03-21 04:13:13 -05:00
										 |  |  |       Could not cleanup old kegs! Fix your permissions on: | 
					
						
							| 
									
										
										
										
											2018-08-08 11:20:53 +02:00
										 |  |  |         #{cleanup.unremovable_kegs.join "\n  "} | 
					
						
							| 
									
										
										
										
											2017-03-21 04:13:13 -05:00
										 |  |  |     EOS | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2012-08-10 16:33:47 -04:00
										 |  |  | end |