| 
									
										
										
										
											2011-03-12 09:40:10 -08:00
										 |  |  | require 'formula' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # Downloads the tarballs for the given formulae to the Cache | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | module Homebrew extend self | 
					
						
							|  |  |  |   def fetch | 
					
						
							| 
									
										
										
										
											2012-02-04 00:01:29 -06:00
										 |  |  |     raise FormulaUnspecifiedError if ARGV.named.empty? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-14 14:57:21 -07:00
										 |  |  |     if ARGV.include? '--deps' | 
					
						
							|  |  |  |       bucket = [] | 
					
						
							|  |  |  |       ARGV.formulae.each do |f| | 
					
						
							|  |  |  |         bucket << f | 
					
						
							| 
									
										
										
										
											2013-01-23 00:26:29 -06:00
										 |  |  |         bucket << f.recursive_dependencies.map(&:to_formula) | 
					
						
							| 
									
										
										
										
											2011-04-14 14:57:21 -07:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2011-09-11 15:23:41 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-04-14 14:57:21 -07:00
										 |  |  |       bucket = bucket.flatten.uniq | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |       bucket = ARGV.formulae | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     puts "Fetching: #{bucket * ', '}" if bucket.size > 1
 | 
					
						
							| 
									
										
										
										
											2013-01-11 18:03:51 -06:00
										 |  |  |     bucket.each { |f| fetch_formula(f) } | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-04-14 14:57:21 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-11 18:03:51 -06:00
										 |  |  |   def already_fetched? f | 
					
						
							|  |  |  |     f.cached_download.exist? | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2012-04-05 21:11:14 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-11 18:03:51 -06:00
										 |  |  |   def fetch_formula f | 
					
						
							|  |  |  |     f.cached_download.rmtree if already_fetched?(f) && ARGV.force? | 
					
						
							|  |  |  |     tarball, _ = f.fetch | 
					
						
							| 
									
										
										
										
											2011-03-12 09:40:10 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-11 18:03:51 -06:00
										 |  |  |     # FIXME why are strategies returning different types? | 
					
						
							|  |  |  |     return unless tarball.is_a? Pathname | 
					
						
							| 
									
										
										
										
											2011-03-12 09:40:10 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-11 18:03:51 -06:00
										 |  |  |     puts "Downloaded to: #{tarball}" unless already_fetched?(f) | 
					
						
							|  |  |  |     puts Checksum::TYPES.map { |t| "#{t.to_s.upcase}: #{tarball.send(t)}" } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     f.verify_download_integrity(tarball) | 
					
						
							|  |  |  |   rescue ChecksumMismatchError => e | 
					
						
							|  |  |  |     Homebrew.failed = true | 
					
						
							|  |  |  |     opoo "Formula reports different #{e.hash_type}: #{e.expected}" | 
					
						
							| 
									
										
										
										
											2011-03-12 09:40:10 -08:00
										 |  |  |   end | 
					
						
							|  |  |  | end |