Class: Hbc::CurlDownloadStrategy

Inherits:
AbstractDownloadStrategy show all
Defined in:
Library/Homebrew/cask/lib/hbc/download_strategy.rb

Direct Known Subclasses

CurlPostDownloadStrategy

Instance Attribute Summary

Attributes inherited from AbstractDownloadStrategy

#cask, #name, #uri_object, #url, #version

Instance Method Summary collapse

Methods inherited from AbstractDownloadStrategy

#initialize

Constructor Details

This class inherits a constructor from Hbc::AbstractDownloadStrategy

Instance Method Details

#_fetchObject



93
94
95
# File 'Library/Homebrew/cask/lib/hbc/download_strategy.rb', line 93

def _fetch
  curl_download url, *cask_curl_args, to: temporary_path, user_agent: uri_object.user_agent
end

#cached_locationObject



75
76
77
# File 'Library/Homebrew/cask/lib/hbc/download_strategy.rb', line 75

def cached_location
  tarball_path
end

#clear_cacheObject



79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'Library/Homebrew/cask/lib/hbc/download_strategy.rb', line 79

def clear_cache
  [cached_location, temporary_path].each do |path|
    next unless path.exist?

    begin
      LockFile.new(path.basename).with_lock do
        path.unlink
      end
    rescue OperationInProgressError
      raise CurlDownloadStrategyError, "#{path} is in use by another process"
    end
  end
end

#fetchObject



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'Library/Homebrew/cask/lib/hbc/download_strategy.rb', line 97

def fetch
  ohai "Downloading #{@url}"
  if tarball_path.exist?
    puts "Already downloaded: #{tarball_path}"
  else
    had_incomplete_download = temporary_path.exist?
    begin
      LockFile.new(temporary_path.basename).with_lock do
        _fetch
      end
    rescue ErrorDuringExecution
      # 33 == range not supported
      # try wiping the incomplete download and retrying once
      if $CHILD_STATUS.exitstatus == 33 && had_incomplete_download
        ohai "Trying a full download"
        temporary_path.unlink
        had_incomplete_download = false
        retry
      end

      msg = @url
      msg.concat("\nThe incomplete download is cached at #{temporary_path}") if temporary_path.exist?
      raise CurlDownloadStrategyError, msg
    end
    ignore_interrupts { temporary_path.rename(tarball_path) }
  end
  tarball_path
end

#tarball_pathObject



67
68
69
# File 'Library/Homebrew/cask/lib/hbc/download_strategy.rb', line 67

def tarball_path
  @tarball_path ||= Hbc.cache.join("#{name}--#{version}#{ext}")
end

#temporary_pathObject



71
72
73
# File 'Library/Homebrew/cask/lib/hbc/download_strategy.rb', line 71

def temporary_path
  @temporary_path ||= tarball_path.sub(/$/, ".incomplete")
end