Class: CurlDownloadStrategy

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

Instance Attribute Summary collapse

Attributes inherited from AbstractDownloadStrategy

#meta, #name, #resource, #shutup, #version

Instance Method Summary collapse

Methods inherited from AbstractFileDownloadStrategy

#stage

Methods inherited from AbstractDownloadStrategy

#expand_safe_system_args, #ohai, #puts, #quiet_safe_system, #safe_system, #shutup!, #source_modified_time, #stage

Methods included from FileUtils

#make, mkdir, mktemp, #old_mkdir, #old_ruby, #ruby, #scons, #xcodebuild

Constructor Details

#initialize(name, resource) ⇒ CurlDownloadStrategy

Returns a new instance of CurlDownloadStrategy



313
314
315
316
317
318
# File 'Library/Homebrew/download_strategy.rb', line 313

def initialize(name, resource)
  super
  @mirrors = resource.mirrors.dup
  @tarball_path = HOMEBREW_CACHE/"#{name}-#{version}#{ext}"
  @temporary_path = Pathname.new("#{cached_location}.incomplete")
end

Instance Attribute Details

#mirrorsObject (readonly)

Returns the value of attribute mirrors



311
312
313
# File 'Library/Homebrew/download_strategy.rb', line 311

def mirrors
  @mirrors
end

#tarball_pathObject (readonly)

Returns the value of attribute tarball_path



311
312
313
# File 'Library/Homebrew/download_strategy.rb', line 311

def tarball_path
  @tarball_path
end

#temporary_pathObject (readonly)

Returns the value of attribute temporary_path



311
312
313
# File 'Library/Homebrew/download_strategy.rb', line 311

def temporary_path
  @temporary_path
end

Instance Method Details

#cached_locationObject



340
341
342
# File 'Library/Homebrew/download_strategy.rb', line 340

def cached_location
  tarball_path
end

#clear_cacheObject



344
345
346
347
# File 'Library/Homebrew/download_strategy.rb', line 344

def clear_cache
  super
  rm_rf(temporary_path)
end

#fetchObject



320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
# File 'Library/Homebrew/download_strategy.rb', line 320

def fetch
  ohai "Downloading #{@url}"

  if cached_location.exist?
    puts "Already downloaded: #{cached_location}"
  else
    begin
      _fetch
    rescue ErrorDuringExecution
      raise CurlDownloadStrategyError, @url
    end
    ignore_interrupts { temporary_path.rename(cached_location) }
  end
rescue CurlDownloadStrategyError
  raise if mirrors.empty?
  puts "Trying a mirror..."
  @url = mirrors.shift
  retry
end