| 
									
										
										
										
											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 | 
					
						
							|  |  |  |         "#{artifact_english_name}s" | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |       def install_phase | 
					
						
							| 
									
										
										
										
											2017-03-10 09:33:48 +01:00
										 |  |  |         each_artifact(&method(:move)) | 
					
						
							| 
									
										
										
										
											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
										 |  |  |       def uninstall_phase | 
					
						
							| 
									
										
										
										
											2017-03-10 09:33:48 +01:00
										 |  |  |         each_artifact(&method(:delete)) | 
					
						
							| 
									
										
										
										
											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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |       def move | 
					
						
							|  |  |  |         if Utils.path_occupied?(target) | 
					
						
							| 
									
										
										
										
											2017-03-10 09:33:48 +01:00
										 |  |  |           message = "It seems there is already #{self.class.artifact_english_article} #{self.class.artifact_english_name} at '#{target}'" | 
					
						
							| 
									
										
										
										
											2017-05-21 00:15:56 +02:00
										 |  |  |           raise CaskError, "#{message}." unless force? | 
					
						
							| 
									
										
										
										
											2017-03-10 09:33:48 +01:00
										 |  |  |           opoo "#{message}; overwriting." | 
					
						
							|  |  |  |           delete | 
					
						
							| 
									
										
										
										
											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-03-10 09:33:48 +01:00
										 |  |  |           raise CaskError, "It seems the #{self.class.artifact_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-03-10 09:33:48 +01:00
										 |  |  |         ohai "Moving #{self.class.artifact_english_name} '#{source.basename}' to '#{target}'." | 
					
						
							|  |  |  |         target.dirname.mkpath | 
					
						
							| 
									
										
										
										
											2017-04-01 01:53:29 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if target.parent.writable? | 
					
						
							|  |  |  |           FileUtils.move(source, target) | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           SystemCommand.run("/bin/mv", args: [source, target], sudo: true) | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-10 09:33:48 +01:00
										 |  |  |         add_altname_metadata target, source.basename.to_s | 
					
						
							| 
									
										
										
										
											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
										 |  |  |       def delete | 
					
						
							| 
									
										
										
										
											2017-03-10 09:33:48 +01:00
										 |  |  |         ohai "Removing #{self.class.artifact_english_name} '#{target}'." | 
					
						
							|  |  |  |         raise CaskError, "Cannot remove undeletable #{self.class.artifact_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 | 
					
						
							|  |  |  |           Utils.gain_permissions_remove(target, command: @command) | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |       def summarize_artifact(artifact_spec) | 
					
						
							|  |  |  |         load_specification artifact_spec | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |         if target.exist? | 
					
						
							| 
									
										
										
										
											2016-08-30 21:38:13 +02:00
										 |  |  |           "#{printable_target} (#{target.abv})" | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |         else | 
					
						
							| 
									
										
										
										
											2016-08-30 21:38:13 +02:00
										 |  |  |           Formatter.error(printable_target, label: "Missing #{self.class.artifact_english_name}") | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |   end | 
					
						
							|  |  |  | end |