| 
									
										
										
										
											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 Symlinked < Relocated | 
					
						
							|  |  |  |       def self.link_type_english_name | 
					
						
							|  |  |  |         "Symlink" | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |       def self.english_description | 
					
						
							|  |  |  |         "#{artifact_english_name} #{link_type_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(:link)) | 
					
						
							| 
									
										
										
										
											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(:unlink)) | 
					
						
							| 
									
										
										
										
											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
										 |  |  |       private | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def link | 
					
						
							| 
									
										
										
										
											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.link_type_english_name.downcase} source '#{source}' is not there." | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if target.exist? && !target.symlink? | 
					
						
							|  |  |  |           raise CaskError, "It seems there is already #{self.class.artifact_english_article} #{self.class.artifact_english_name} at '#{target}'; not linking." | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-03-10 09:33:48 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         ohai "Linking #{self.class.artifact_english_name} '#{source.basename}' to '#{target}'." | 
					
						
							|  |  |  |         create_filesystem_link(source, target) | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       def unlink | 
					
						
							|  |  |  |         return unless target.symlink? | 
					
						
							|  |  |  |         ohai "Unlinking #{self.class.artifact_english_name} '#{target}'." | 
					
						
							|  |  |  |         target.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
										 |  |  |       def create_filesystem_link(source, target) | 
					
						
							| 
									
										
										
										
											2017-03-10 09:33:48 +01:00
										 |  |  |         target.dirname.mkpath | 
					
						
							|  |  |  |         @command.run!("/bin/ln", args: ["-h", "-f", "-s", "--", source, target]) | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |         add_altname_metadata source, target.basename.to_s | 
					
						
							|  |  |  |       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
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-10 09:33:48 +01:00
										 |  |  |         if target.symlink? && target.exist? && target.readlink.exist? | 
					
						
							| 
									
										
										
										
											2016-08-30 21:38:13 +02:00
										 |  |  |           "#{printable_target} -> #{target.readlink} (#{target.readlink.abv})" | 
					
						
							|  |  |  |         else | 
					
						
							| 
									
										
										
										
											2017-03-10 09:33:48 +01:00
										 |  |  |           string = if target.symlink? | 
					
						
							| 
									
										
										
										
											2016-10-14 20:11:33 +02:00
										 |  |  |             "#{printable_target} -> #{target.readlink}" | 
					
						
							|  |  |  |           else | 
					
						
							|  |  |  |             printable_target | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-08-30 21:38:13 +02:00
										 |  |  |           Formatter.error(string, label: "Broken Link") | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2016-09-24 13:52:43 +02:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2016-08-18 22:11:42 +03:00
										 |  |  |   end | 
					
						
							|  |  |  | end |