| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | require "hbc/artifact/relocated" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  | module Hbc | 
					
						
							|  |  |  |   module Artifact | 
					
						
							|  |  |  |     class Moved < Relocated | 
					
						
							|  |  |  |       def self.english_description | 
					
						
							| 
									
										
										
										
											2017-04-06 00:33:31 +02:00
										 |  |  |         "#{english_name}s" | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-06 00:33:31 +02:00
										 |  |  |       def install_phase(**options) | 
					
						
							| 
									
										
										
										
											2017-11-16 10:40:32 -03:00
										 |  |  |         move(**options) | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-06 00:33:31 +02:00
										 |  |  |       def uninstall_phase(**options) | 
					
						
							| 
									
										
										
										
											2017-11-16 10:40:32 -03:00
										 |  |  |         move_back(**options) | 
					
						
							| 
									
										
										
										
											2017-04-06 00:33:31 +02:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def summarize_installed | 
					
						
							|  |  |  |         if target.exist? | 
					
						
							|  |  |  |           "#{printable_target} (#{target.abv})" | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           Formatter.error(printable_target, label: "Missing #{self.class.english_name}") | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |       private | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-16 10:40:32 -03:00
										 |  |  |       def move(force: false, command: nil, **options) | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |         if Utils.path_occupied?(target) | 
					
						
							| 
									
										
										
										
											2017-04-06 00:33:31 +02:00
										 |  |  |           message = "It seems there is already #{self.class.english_article} #{self.class.english_name} at '#{target}'" | 
					
						
							|  |  |  |           raise CaskError, "#{message}." unless force | 
					
						
							| 
									
										
										
										
											2017-03-10 09:33:48 +01:00
										 |  |  |           opoo "#{message}; overwriting." | 
					
						
							| 
									
										
										
										
											2017-11-06 21:27:02 -03:00
										 |  |  |           delete(target, force: force, command: command, **options) | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-03-10 09:33:48 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |         unless source.exist? | 
					
						
							| 
									
										
										
										
											2017-04-06 00:33:31 +02:00
										 |  |  |           raise CaskError, "It seems the #{self.class.english_name} source '#{source}' is not there." | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-06 00:33:31 +02:00
										 |  |  |         ohai "Moving #{self.class.english_name} '#{source.basename}' to '#{target}'." | 
					
						
							| 
									
										
										
										
											2017-03-10 09:33:48 +01:00
										 |  |  |         target.dirname.mkpath | 
					
						
							| 
									
										
										
										
											2017-04-01 01:53:29 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if target.parent.writable? | 
					
						
							|  |  |  |           FileUtils.move(source, target) | 
					
						
							|  |  |  |         else | 
					
						
							| 
									
										
										
										
											2017-04-06 00:33:31 +02:00
										 |  |  |           command.run("/bin/mv", args: [source, target], sudo: true) | 
					
						
							| 
									
										
										
										
											2017-04-01 01:53:29 +02:00
										 |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-06 00:33:31 +02:00
										 |  |  |         add_altname_metadata(target, source.basename, command: command) | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-16 10:40:32 -03:00
										 |  |  |       def move_back(skip: false, force: false, command: nil, **options) | 
					
						
							|  |  |  |         if Utils.path_occupied?(source) | 
					
						
							|  |  |  |           message = "It seems there is already #{self.class.english_article} #{self.class.english_name} at '#{source}'" | 
					
						
							|  |  |  |           raise CaskError, "#{message}." unless force | 
					
						
							|  |  |  |           opoo "#{message}; overwriting." | 
					
						
							|  |  |  |           delete(source, force: force, command: command, **options) | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         unless target.exist? | 
					
						
							|  |  |  |           return if skip | 
					
						
							|  |  |  |           raise CaskError, "It seems the #{self.class.english_name} source '#{target}' is not there." | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-14 07:56:59 +10:00
										 |  |  |         ohai "Backing #{self.class.english_name} '#{target.basename}' up to '#{source}'." | 
					
						
							| 
									
										
										
										
											2017-11-16 10:40:32 -03:00
										 |  |  |         source.dirname.mkpath | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-13 20:54:17 +10:00
										 |  |  |         if target.parent.writable? | 
					
						
							| 
									
										
										
										
											2018-01-21 19:10:30 +10:00
										 |  |  |           FileUtils.cp_r(target, source) | 
					
						
							| 
									
										
										
										
											2017-11-16 10:40:32 -03:00
										 |  |  |         else | 
					
						
							| 
									
										
										
										
											2018-01-21 19:10:30 +10:00
										 |  |  |           command.run("/bin/cp", args: ["-r", target, source], sudo: true) | 
					
						
							| 
									
										
										
										
											2017-11-16 10:40:32 -03:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2018-01-21 19:10:30 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  |         delete(target, force: force, command: command, **options) | 
					
						
							| 
									
										
										
										
											2017-11-16 10:40:32 -03:00
										 |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-06 21:27:02 -03:00
										 |  |  |       def delete(target, force: false, command: nil, **_) | 
					
						
							| 
									
										
										
										
											2017-04-06 00:33:31 +02:00
										 |  |  |         ohai "Removing #{self.class.english_name} '#{target}'." | 
					
						
							|  |  |  |         raise CaskError, "Cannot remove undeletable #{self.class.english_name}." if MacOS.undeletable?(target) | 
					
						
							| 
									
										
										
										
											2016-09-20 15:11:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-01 01:53:29 +02:00
										 |  |  |         return unless Utils.path_occupied?(target) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if target.parent.writable? && !force | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |           target.rmtree | 
					
						
							| 
									
										
										
										
											2017-04-01 01:53:29 +02:00
										 |  |  |         else | 
					
						
							| 
									
										
										
										
											2017-04-06 00:33:31 +02:00
										 |  |  |           Utils.gain_permissions_remove(target, command: command) | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |   end | 
					
						
							|  |  |  | end |