| 
									
										
										
										
											2016-05-09 15:37:01 +02:00
										 |  |  | #:  * `fetch` [`--force`] [`--retry`] [`-v`] [`--devel`|`--HEAD`] [`--deps`] [`--build-from-source`|`--force-bottle`] <formulae>: | 
					
						
							| 
									
										
										
										
											2016-04-08 16:28:43 +02:00
										 |  |  | #:    Download the source packages for the given <formulae>. | 
					
						
							| 
									
										
										
										
											2016-04-10 20:46:54 +02:00
										 |  |  | #:    For tarballs, also print SHA-256 checksums. | 
					
						
							| 
									
										
										
										
											2016-04-08 16:28:43 +02:00
										 |  |  | #: | 
					
						
							|  |  |  | #:    If `--HEAD` or `--devel` is passed, fetch that version instead of the | 
					
						
							|  |  |  | #:    stable version. | 
					
						
							|  |  |  | #: | 
					
						
							| 
									
										
										
										
											2016-05-06 11:03:38 -04:00
										 |  |  | #:    If `-v` is passed, do a verbose VCS checkout, if the URL represents a VCS. | 
					
						
							| 
									
										
										
										
											2016-04-08 16:28:43 +02:00
										 |  |  | #:    This is useful for seeing if an existing VCS cache has been updated. | 
					
						
							|  |  |  | #: | 
					
						
							|  |  |  | #:    If `--force` is passed, remove a previously cached version and re-fetch. | 
					
						
							|  |  |  | #: | 
					
						
							| 
									
										
										
										
											2016-05-09 15:37:01 +02:00
										 |  |  | #:    If `--retry` is passed, retry if a download fails or re-download if the | 
					
						
							|  |  |  | #:    checksum of a previously cached version no longer matches. | 
					
						
							|  |  |  | #: | 
					
						
							| 
									
										
										
										
											2016-04-08 16:28:43 +02:00
										 |  |  | #:    If `--deps` is passed, also download dependencies for any listed <formulae>. | 
					
						
							|  |  |  | #: | 
					
						
							|  |  |  | #:    If `--build-from-source` is passed, download the source rather than a | 
					
						
							|  |  |  | #:    bottle. | 
					
						
							|  |  |  | #: | 
					
						
							|  |  |  | #:    If `--force-bottle` is passed, download a bottle if it exists for the current | 
					
						
							|  |  |  | #:    version of OS X, even if it would not be used during installation. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  | require "formula" | 
					
						
							| 
									
										
										
										
											2011-03-12 09:40:10 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-18 22:41:47 -05:00
										 |  |  | module Homebrew | 
					
						
							| 
									
										
										
										
											2011-03-12 09:40:10 -08:00
										 |  |  |   def fetch | 
					
						
							| 
									
										
										
										
											2012-02-04 00:01:29 -06:00
										 |  |  |     raise FormulaUnspecifiedError if ARGV.named.empty? | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     if ARGV.include? "--deps" | 
					
						
							| 
									
										
										
										
											2011-04-14 14:57:21 -07:00
										 |  |  |       bucket = [] | 
					
						
							|  |  |  |       ARGV.formulae.each do |f| | 
					
						
							|  |  |  |         bucket << f | 
					
						
							| 
									
										
										
										
											2013-05-16 14:06:25 -05:00
										 |  |  |         bucket.concat f.recursive_dependencies.map(&:to_formula) | 
					
						
							| 
									
										
										
										
											2011-04-14 14:57:21 -07:00
										 |  |  |       end | 
					
						
							| 
									
										
										
										
											2013-05-16 14:06:25 -05:00
										 |  |  |       bucket.uniq! | 
					
						
							| 
									
										
										
										
											2011-04-14 14:57:21 -07:00
										 |  |  |     else | 
					
						
							|  |  |  |       bucket = ARGV.formulae | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     puts "Fetching: #{bucket * ", "}" if bucket.size > 1
 | 
					
						
							| 
									
										
										
										
											2013-08-06 19:53:43 -07:00
										 |  |  |     bucket.each do |f| | 
					
						
							| 
									
										
										
										
											2014-10-19 13:54:00 +01:00
										 |  |  |       f.print_tap_action :verb => "Fetching" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-03 11:00:39 +02:00
										 |  |  |       fetched_bottle = false | 
					
						
							| 
									
										
										
										
											2014-03-10 14:56:02 -05:00
										 |  |  |       if fetch_bottle?(f) | 
					
						
							| 
									
										
										
										
											2015-12-03 11:00:39 +02:00
										 |  |  |         begin | 
					
						
							|  |  |  |           fetch_formula(f.bottle) | 
					
						
							|  |  |  |         rescue Exception => e | 
					
						
							|  |  |  |           raise if ARGV.homebrew_developer? || e.is_a?(Interrupt) | 
					
						
							|  |  |  |           fetched_bottle = false | 
					
						
							|  |  |  |           onoe e.message | 
					
						
							|  |  |  |           opoo "Bottle fetch failed: fetching the source." | 
					
						
							|  |  |  |         else | 
					
						
							|  |  |  |           fetched_bottle = true | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       unless fetched_bottle | 
					
						
							| 
									
										
										
										
											2014-03-10 14:56:02 -05:00
										 |  |  |         fetch_formula(f) | 
					
						
							| 
									
										
										
										
											2014-03-13 19:51:23 -05:00
										 |  |  |         f.resources.each { |r| fetch_resource(r) } | 
					
						
							| 
									
										
										
										
											2015-08-17 17:08:23 +02:00
										 |  |  |         f.patchlist.each { |p| fetch_patch(p) if p.external? } | 
					
						
							| 
									
										
										
										
											2013-08-06 19:53:43 -07:00
										 |  |  |       end | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2013-01-11 18:03:51 -06:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2011-04-14 14:57:21 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |   def fetch_bottle?(f) | 
					
						
							| 
									
										
										
										
											2016-01-19 10:14:59 +00:00
										 |  |  |     return true if ARGV.force_bottle? && f.bottle | 
					
						
							|  |  |  |     return false unless f.bottle && f.pour_bottle? | 
					
						
							| 
									
										
										
										
											2016-05-06 12:02:13 -07:00
										 |  |  |     return false if ARGV.build_formula_from_source?(f) | 
					
						
							| 
									
										
										
										
											2014-03-10 14:56:02 -05:00
										 |  |  |     return false unless f.bottle.compatible_cellar? | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |     true | 
					
						
							| 
									
										
										
										
											2014-03-10 14:56:02 -05:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |   def fetch_resource(r) | 
					
						
							| 
									
										
										
										
											2013-08-06 19:53:43 -07:00
										 |  |  |     puts "Resource: #{r.name}" | 
					
						
							|  |  |  |     fetch_fetchable r | 
					
						
							|  |  |  |   rescue ChecksumMismatchError => e | 
					
						
							| 
									
										
										
										
											2014-03-08 17:21:37 +00:00
										 |  |  |     retry if retry_fetch? r | 
					
						
							| 
									
										
										
										
											2013-08-06 19:53:43 -07:00
										 |  |  |     opoo "Resource #{r.name} reports different #{e.hash_type}: #{e.expected}" | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |   def fetch_formula(f) | 
					
						
							| 
									
										
										
										
											2013-08-06 19:53:43 -07:00
										 |  |  |     fetch_fetchable f | 
					
						
							|  |  |  |   rescue ChecksumMismatchError => e | 
					
						
							| 
									
										
										
										
											2014-03-01 12:28:45 +00:00
										 |  |  |     retry if retry_fetch? f | 
					
						
							| 
									
										
										
										
											2013-08-06 19:53:43 -07:00
										 |  |  |     opoo "Formula reports different #{e.hash_type}: #{e.expected}" | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |   def fetch_patch(p) | 
					
						
							| 
									
										
										
										
											2014-03-13 19:51:23 -05:00
										 |  |  |     fetch_fetchable p | 
					
						
							|  |  |  |   rescue ChecksumMismatchError => e | 
					
						
							|  |  |  |     Homebrew.failed = true | 
					
						
							|  |  |  |     opoo "Patch reports different #{e.hash_type}: #{e.expected}" | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-06 19:53:43 -07:00
										 |  |  |   private | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |   def retry_fetch?(f) | 
					
						
							| 
									
										
										
										
											2014-08-22 22:55:10 -05:00
										 |  |  |     @fetch_failed ||= Set.new | 
					
						
							| 
									
										
										
										
											2014-09-10 22:08:34 -05:00
										 |  |  |     if ARGV.include?("--retry") && @fetch_failed.add?(f) | 
					
						
							| 
									
										
										
										
											2014-08-22 22:55:10 -05:00
										 |  |  |       ohai "Retrying download" | 
					
						
							|  |  |  |       f.clear_cache | 
					
						
							|  |  |  |       true | 
					
						
							|  |  |  |     else | 
					
						
							| 
									
										
										
										
											2014-03-01 12:28:45 +00:00
										 |  |  |       Homebrew.failed = true | 
					
						
							| 
									
										
										
										
											2014-08-22 22:55:10 -05:00
										 |  |  |       false | 
					
						
							| 
									
										
										
										
											2014-03-01 12:28:45 +00:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-03 13:09:07 +01:00
										 |  |  |   def fetch_fetchable(f) | 
					
						
							| 
									
										
										
										
											2013-10-31 14:28:49 -05:00
										 |  |  |     f.clear_cache if ARGV.force? | 
					
						
							| 
									
										
										
										
											2013-10-31 14:28:49 -05:00
										 |  |  | 
 | 
					
						
							|  |  |  |     already_fetched = f.cached_download.exist? | 
					
						
							| 
									
										
										
										
											2014-08-16 08:48:28 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     begin | 
					
						
							|  |  |  |       download = f.fetch | 
					
						
							| 
									
										
										
										
											2014-08-22 22:55:10 -05:00
										 |  |  |     rescue DownloadError | 
					
						
							| 
									
										
										
										
											2014-08-16 08:48:28 +01:00
										 |  |  |       retry if retry_fetch? f | 
					
						
							| 
									
										
										
										
											2014-08-22 22:55:10 -05:00
										 |  |  |       raise | 
					
						
							| 
									
										
										
										
											2014-08-16 08:48:28 +01:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2011-03-12 09:40:10 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-16 14:06:26 -05:00
										 |  |  |     return unless download.file? | 
					
						
							| 
									
										
										
										
											2011-03-12 09:40:10 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-10-31 14:28:49 -05:00
										 |  |  |     puts "Downloaded to: #{download}" unless already_fetched | 
					
						
							| 
									
										
										
										
											2016-03-20 13:53:48 +08:00
										 |  |  |     puts Checksum::TYPES.map { |t| "#{t.to_s.upcase}: #{download.send(t)}" } | 
					
						
							| 
									
										
										
										
											2013-01-11 18:03:51 -06:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-16 14:06:26 -05:00
										 |  |  |     f.verify_download_integrity(download) | 
					
						
							| 
									
										
										
										
											2011-03-12 09:40:10 -08:00
										 |  |  |   end | 
					
						
							|  |  |  | end |