Class: CurlDownloadStrategy

Inherits:
AbstractFileDownloadStrategy show all
Defined in:
brew/Library/Homebrew/download_strategy.rb

Instance Attribute Summary collapse

Attributes inherited from AbstractDownloadStrategy

#cache, #cached_location, #source_modified_time, #url

Instance Method Summary collapse

Methods inherited from AbstractFileDownloadStrategy

#basename, #cached_location, #symlink_location, #temporary_path

Methods inherited from AbstractDownloadStrategy

#basename, #ohai, #puts, #shutup!, #stage

Constructor Details

#initialize(url, name, version, **meta) ⇒ CurlDownloadStrategy

Returns a new instance of CurlDownloadStrategy



279
280
281
282
# File 'brew/Library/Homebrew/download_strategy.rb', line 279

def initialize(url, name, version, **meta)
  super
  @mirrors = meta.fetch(:mirrors, [])
end

Instance Attribute Details

#mirrorsObject (readonly)

Returns the value of attribute mirrors



277
278
279
# File 'brew/Library/Homebrew/download_strategy.rb', line 277

def mirrors
  @mirrors
end

Instance Method Details

#clear_cacheObject



331
332
333
334
# File 'brew/Library/Homebrew/download_strategy.rb', line 331

def clear_cache
  super
  rm_rf(temporary_path)
end

#fetchObject



284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
# File 'brew/Library/Homebrew/download_strategy.rb', line 284

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
end