Class: CurlDownloadStrategy
- Inherits:
-
AbstractFileDownloadStrategy
- Object
- AbstractDownloadStrategy
- AbstractFileDownloadStrategy
- CurlDownloadStrategy
- Includes:
- Utils::Curl
- Defined in:
- Library/Homebrew/download_strategy.rb
Overview
Strategy for downloading files using curl
.
Direct Known Subclasses
CurlApacheMirrorDownloadStrategy, CurlPostDownloadStrategy, NoUnzipCurlDownloadStrategy
Instance Attribute Summary collapse
- #mirrors ⇒ Object readonly
Attributes inherited from AbstractDownloadStrategy
#cache, #cached_location, #source_modified_time, #url
Instance Method Summary collapse
- #clear_cache ⇒ Object
-
#fetch ⇒ Object
Download and cache the file at AbstractFileDownloadStrategy#cached_location.
-
#initialize(url, name, version, **meta) ⇒ CurlDownloadStrategy
constructor
A new instance of CurlDownloadStrategy.
Methods included from Utils::Curl
curl, curl_args, curl_check_http_content, curl_download, curl_executable, curl_http_content_headers_and_checksum, curl_output, curl_with_workarounds, http_status_ok?, url_protected_by_cloudflare?, url_protected_by_incapsula?
Methods inherited from AbstractFileDownloadStrategy
#basename, #cached_location, #symlink_location, #temporary_path
Methods inherited from AbstractDownloadStrategy
#basename, #quiet?, #shutup!, #stage
Methods included from Context
current, current=, #debug?, #quiet?, #verbose?, #with_context
Constructor Details
#initialize(url, name, version, **meta) ⇒ CurlDownloadStrategy
Returns a new instance of CurlDownloadStrategy.
337 338 339 340 |
# File 'Library/Homebrew/download_strategy.rb', line 337 def initialize(url, name, version, **) super @mirrors = .fetch(:mirrors, []) end |
Instance Attribute Details
#mirrors ⇒ Object (readonly)
335 336 337 |
# File 'Library/Homebrew/download_strategy.rb', line 335 def mirrors @mirrors end |
Instance Method Details
#clear_cache ⇒ Object
393 394 395 396 |
# File 'Library/Homebrew/download_strategy.rb', line 393 def clear_cache super rm_rf(temporary_path) end |
#fetch ⇒ Object
Download and cache the file at AbstractFileDownloadStrategy#cached_location.
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 |
# File 'Library/Homebrew/download_strategy.rb', line 345 def fetch download_lock = LockFile.new(temporary_path.basename) download_lock.lock urls = [url, *mirrors] begin url = urls.shift ohai "Downloading #{url}" resolved_url, _, url_time = resolve_url_basename_time(url) fresh = if cached_location.exist? && url_time url_time <= cached_location.mtime elsif version.respond_to?(:latest?) !version.latest? else true end if cached_location.exist? && fresh puts "Already downloaded: #{cached_location}" else begin _fetch(url: url, resolved_url: resolved_url) rescue ErrorDuringExecution raise CurlDownloadStrategyError, url end ignore_interrupts do cached_location.dirname.mkpath temporary_path.rename(cached_location) symlink_location.dirname.mkpath end end FileUtils.ln_s cached_location.relative_path_from(symlink_location.dirname), symlink_location, force: true rescue CurlDownloadStrategyError raise if urls.empty? puts "Trying a mirror..." retry end ensure download_lock&.unlock download_lock&.path&.unlink end |