| 
									
										
										
										
											2014-10-31 20:10:08 -05:00
										 |  |  | require "formula_installer" | 
					
						
							| 
									
										
										
										
											2013-02-17 13:23:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 22:41:47 -05:00
										 |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2013-02-17 13:23:41 +00:00
										 |  |  |   def reinstall | 
					
						
							| 
									
										
										
										
											2015-07-26 16:49:16 -04:00
										 |  |  |     FormulaInstaller.prevent_build_flags unless MacOS.has_apple_developer_tools? | 
					
						
							| 
									
										
										
										
											2015-06-29 14:09:57 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-17 21:10:28 +08:00
										 |  |  |     ARGV.resolved_formulae.each { |f| reinstall_formula(f) } | 
					
						
							| 
									
										
										
										
											2014-03-15 10:40:18 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |   def reinstall_formula(f) | 
					
						
							| 
									
										
										
										
											2014-03-15 10:40:18 -05:00
										 |  |  |     tab = Tab.for_formula(f) | 
					
						
							|  |  |  |     options = tab.used_options | f.build.used_options | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-05-27 21:12:07 +08:00
										 |  |  |     notice  = "Reinstalling #{f.full_name}" | 
					
						
							| 
									
										
										
										
											2014-03-15 10:40:18 -05:00
										 |  |  |     notice += " with #{options * ", "}" unless options.empty? | 
					
						
							|  |  |  |     oh1 notice | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-05 12:17:19 -05:00
										 |  |  |     if f.opt_prefix.directory? | 
					
						
							|  |  |  |       keg = Keg.new(f.opt_prefix.resolved_path) | 
					
						
							| 
									
										
										
										
											2014-03-15 10:40:18 -05:00
										 |  |  |       backup keg | 
					
						
							| 
									
										
										
										
											2013-08-28 04:51:24 -07:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2014-03-15 10:40:18 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     fi = FormulaInstaller.new(f) | 
					
						
							|  |  |  |     fi.options             = options | 
					
						
							| 
									
										
										
										
											2015-03-24 12:11:40 +00:00
										 |  |  |     fi.build_bottle        = ARGV.build_bottle? || (!f.bottled? && tab.build_bottle?) | 
					
						
							| 
									
										
										
										
											2014-03-15 10:40:18 -05:00
										 |  |  |     fi.build_from_source   = ARGV.build_from_source? | 
					
						
							|  |  |  |     fi.force_bottle        = ARGV.force_bottle? | 
					
						
							|  |  |  |     fi.verbose             = ARGV.verbose? | 
					
						
							|  |  |  |     fi.debug               = ARGV.debug? | 
					
						
							|  |  |  |     fi.prelude | 
					
						
							|  |  |  |     fi.install | 
					
						
							|  |  |  |     fi.finish | 
					
						
							|  |  |  |   rescue FormulaInstallationAlreadyAttemptedError | 
					
						
							|  |  |  |     # next | 
					
						
							|  |  |  |   rescue Exception | 
					
						
							|  |  |  |     ignore_interrupts { restore_backup(keg, f) } | 
					
						
							|  |  |  |     raise | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |     backup_path(keg).rmtree if backup_path(keg).exist? | 
					
						
							| 
									
										
										
										
											2013-08-28 04:51:24 -07:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |   def backup(keg) | 
					
						
							| 
									
										
										
										
											2013-08-28 04:51:24 -07:00
										 |  |  |     keg.unlink | 
					
						
							| 
									
										
										
										
											2013-09-05 14:59:33 +02:00
										 |  |  |     keg.rename backup_path(keg) | 
					
						
							| 
									
										
										
										
											2013-08-28 04:51:24 -07:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |   def restore_backup(keg, formula) | 
					
						
							| 
									
										
										
										
											2013-09-05 14:59:33 +02:00
										 |  |  |     path = backup_path(keg) | 
					
						
							| 
									
										
										
										
											2013-08-28 04:51:24 -07:00
										 |  |  |     if path.directory? | 
					
						
							| 
									
										
										
										
											2013-09-05 14:59:33 +02:00
										 |  |  |       path.rename keg | 
					
						
							| 
									
										
										
										
											2013-08-28 04:51:24 -07:00
										 |  |  |       keg.link unless formula.keg_only? | 
					
						
							| 
									
										
										
										
											2013-07-23 10:55:07 +02:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2013-02-17 13:23:41 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-08-28 04:51:24 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |   def backup_path(path) | 
					
						
							| 
									
										
										
										
											2013-09-05 14:59:33 +02:00
										 |  |  |     Pathname.new "#{path}.reinstall" | 
					
						
							| 
									
										
										
										
											2013-08-28 04:51:24 -07:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2013-02-17 13:23:41 +00:00
										 |  |  | end |