| 
									
										
										
										
											2016-04-08 16:28:43 +02:00
										 |  |  | #:  * `reinstall` <formula>: | 
					
						
							| 
									
										
										
										
											2016-08-17 01:19:40 +02:00
										 |  |  | #:    Uninstall and then install <formula>. | 
					
						
							| 
									
										
										
										
											2016-04-08 16:28:43 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-10-31 20:10:08 -05:00
										 |  |  | require "formula_installer" | 
					
						
							| 
									
										
										
										
											2016-07-29 20:31:32 -06:00
										 |  |  | require "development_tools" | 
					
						
							| 
									
										
										
										
											2013-02-17 13:23:41 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 22:41:47 -05:00
										 |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2016-09-26 01:44:51 +02:00
										 |  |  |   module_function | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-02-17 13:23:41 +00:00
										 |  |  |   def reinstall | 
					
						
							| 
									
										
										
										
											2016-07-06 11:07:24 +01:00
										 |  |  |     FormulaInstaller.prevent_build_flags unless DevelopmentTools.installed? | 
					
						
							| 
									
										
										
										
											2015-06-29 14:09:57 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-05 22:40:08 +03:00
										 |  |  |     ARGV.resolved_formulae.each do |f| | 
					
						
							|  |  |  |       if f.pinned? | 
					
						
							|  |  |  |         onoe "#{f.full_name} is pinned. You must unpin it to reinstall." | 
					
						
							|  |  |  |         next | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2017-03-29 11:25:27 +01:00
										 |  |  |       Migrator.migrate_if_needed(f) | 
					
						
							| 
									
										
										
										
											2016-09-05 22:40:08 +03:00
										 |  |  |       reinstall_formula(f) | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2014-03-15 10:40:18 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |   def reinstall_formula(f) | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-02-04 18:10:37 +01:00
										 |  |  |     build_options = BuildOptions.new(Options.create(ARGV.flags_only), f.options) | 
					
						
							|  |  |  |     options = build_options.used_options | 
					
						
							| 
									
										
										
										
											2016-12-10 13:07:03 +00:00
										 |  |  |     options |= f.build.used_options | 
					
						
							|  |  |  |     options &= f.options | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-15 10:40:18 -05:00
										 |  |  |     fi = FormulaInstaller.new(f) | 
					
						
							| 
									
										
										
										
											2017-02-04 18:10:37 +01:00
										 |  |  |     fi.options              = options | 
					
						
							|  |  |  |     fi.invalid_option_names = build_options.invalid_option_names | 
					
						
							|  |  |  |     fi.build_bottle         = ARGV.build_bottle? || (!f.bottled? && f.build.build_bottle?) | 
					
						
							|  |  |  |     fi.build_from_source    = ARGV.build_from_source? || ARGV.build_all_from_source? | 
					
						
							|  |  |  |     fi.force_bottle         = ARGV.force_bottle? | 
					
						
							|  |  |  |     fi.interactive          = ARGV.interactive? | 
					
						
							|  |  |  |     fi.git                  = ARGV.git? | 
					
						
							|  |  |  |     fi.verbose              = ARGV.verbose? | 
					
						
							|  |  |  |     fi.debug                = ARGV.debug? | 
					
						
							| 
									
										
										
										
											2014-03-15 10:40:18 -05:00
										 |  |  |     fi.prelude | 
					
						
							| 
									
										
										
										
											2016-12-10 13:07:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     oh1 "Reinstalling #{f.full_name} #{options.to_a.join " "}" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-15 10:40:18 -05:00
										 |  |  |     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) | 
					
						
							| 
									
										
										
										
											2016-09-22 20:12:28 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return unless path.directory? | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     path.rename keg | 
					
						
							|  |  |  |     keg.link unless formula.keg_only? | 
					
						
							| 
									
										
										
										
											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 |