| 
									
										
										
										
											2018-09-06 08:29:14 +02:00
										 |  |  | module Cask | 
					
						
							| 
									
										
										
										
											2017-03-06 21:49:35 +01:00
										 |  |  |   module Caskroom | 
					
						
							| 
									
										
										
										
											2018-05-18 13:35:41 +02:00
										 |  |  |     class << self | 
					
						
							|  |  |  |       module Compat | 
					
						
							|  |  |  |         def migrate_legacy_caskroom | 
					
						
							| 
									
										
										
										
											2018-06-09 09:42:49 +02:00
										 |  |  |           return if path.exist? | 
					
						
							| 
									
										
										
										
											2017-03-06 21:49:35 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-09 09:42:49 +02:00
										 |  |  |           legacy_caskroom_path = Pathname.new("/opt/homebrew-cask/Caskroom") | 
					
						
							|  |  |  |           return if path == legacy_caskroom_path | 
					
						
							|  |  |  |           return unless legacy_caskroom_path.exist? | 
					
						
							|  |  |  |           return if legacy_caskroom_path.symlink? | 
					
						
							| 
									
										
										
										
											2017-03-06 21:28:34 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-09 09:42:49 +02:00
										 |  |  |           ohai "Migrating Caskroom from #{legacy_caskroom_path} to #{path}." | 
					
						
							|  |  |  |           if path.parent.writable? | 
					
						
							|  |  |  |             FileUtils.mv legacy_caskroom_path, path | 
					
						
							| 
									
										
										
										
											2018-05-18 13:35:41 +02:00
										 |  |  |           else | 
					
						
							| 
									
										
										
										
											2018-06-09 09:42:49 +02:00
										 |  |  |             opoo "#{path.parent} is not writable, sudo is needed to move the Caskroom." | 
					
						
							|  |  |  |             SystemCommand.run("/bin/mv", args: [legacy_caskroom_path, path.parent], sudo: true) | 
					
						
							| 
									
										
										
										
											2018-05-18 13:35:41 +02:00
										 |  |  |           end | 
					
						
							| 
									
										
										
										
											2017-03-06 21:28:34 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-09 09:42:49 +02:00
										 |  |  |           ohai "Creating symlink from #{path} to #{legacy_caskroom_path}." | 
					
						
							|  |  |  |           if legacy_caskroom_path.parent.writable? | 
					
						
							|  |  |  |             FileUtils.ln_s path, legacy_caskroom_path | 
					
						
							| 
									
										
										
										
											2018-05-18 13:35:41 +02:00
										 |  |  |           else | 
					
						
							| 
									
										
										
										
											2018-06-09 09:42:49 +02:00
										 |  |  |             opoo "#{legacy_caskroom_path.parent} is not writable, sudo is needed to link the Caskroom." | 
					
						
							|  |  |  |             SystemCommand.run("/bin/ln", args: ["-s", path, legacy_caskroom_path], sudo: true) | 
					
						
							| 
									
										
										
										
											2018-05-18 13:35:41 +02:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-03-06 21:28:34 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-18 13:35:41 +02:00
										 |  |  |         def migrate_caskroom_from_repo_to_prefix | 
					
						
							| 
									
										
										
										
											2018-06-09 09:42:49 +02:00
										 |  |  |           repo_caskroom_path = HOMEBREW_REPOSITORY.join("Caskroom") | 
					
						
							|  |  |  |           return if path.exist? | 
					
						
							|  |  |  |           return unless repo_caskroom_path.directory? | 
					
						
							| 
									
										
										
										
											2017-03-06 21:28:34 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-05-18 13:35:41 +02:00
										 |  |  |           ohai "Moving Caskroom from HOMEBREW_REPOSITORY to HOMEBREW_PREFIX" | 
					
						
							| 
									
										
										
										
											2017-03-06 21:49:35 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-06-09 09:42:49 +02:00
										 |  |  |           if path.parent.writable? | 
					
						
							|  |  |  |             FileUtils.mv repo_caskroom_path, path | 
					
						
							| 
									
										
										
										
											2018-05-18 13:35:41 +02:00
										 |  |  |           else | 
					
						
							| 
									
										
										
										
											2018-06-09 09:42:49 +02:00
										 |  |  |             opoo "#{path.parent} is not writable, sudo is needed to move the Caskroom." | 
					
						
							|  |  |  |             SystemCommand.run("/bin/mv", args: [repo_caskroom_path, path.parent], sudo: true) | 
					
						
							| 
									
										
										
										
											2018-05-18 13:35:41 +02:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-03-06 21:49:35 +01:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2018-05-18 13:35:41 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |       prepend Compat | 
					
						
							| 
									
										
										
										
											2017-03-06 21:49:35 +01:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |