Class: AbstractFileDownloadStrategy Abstract Private

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

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

This class is abstract.

Abstract superclass for all download strategies downloading a single file.

Instance Attribute Summary

Attributes inherited from AbstractDownloadStrategy

#cache, #source_modified_time, #url

Instance Method Summary collapse

Methods inherited from AbstractDownloadStrategy

#clear_cache, #fetch, #initialize, #quiet?, #shutup!, #stage

Methods included from Context

current, current=, #debug?, #quiet?, #verbose?, #with_context

Constructor Details

This class inherits a constructor from AbstractDownloadStrategy

Instance Method Details

#basenameObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.


275
276
277
# File 'Library/Homebrew/download_strategy.rb', line 275

def basename
  cached_location.basename.sub(/^[\da-f]{64}--/, "")
end

#cached_locationObject

Path for storing the completed download.


261
262
263
264
265
266
267
268
269
270
271
272
273
# File 'Library/Homebrew/download_strategy.rb', line 261

def cached_location
  return @cached_location if defined?(@cached_location)

  url_sha256 = Digest::SHA256.hexdigest(url)
  downloads = Pathname.glob(HOMEBREW_CACHE/"downloads/#{url_sha256}--*")
                      .reject { |path| path.extname.end_with?(".incomplete") }

  @cached_location = if downloads.count == 1
    downloads.first
  else
    HOMEBREW_CACHE/"downloads/#{url_sha256}--#{resolved_basename}"
  end
end

Path of the symlink (whose name includes the resource name, version and extension) pointing to #cached_location.


251
252
253
254
255
256
# File 'Library/Homebrew/download_strategy.rb', line 251

def symlink_location
  return @symlink_location if defined?(@symlink_location)

  ext = Pathname(parse_basename(url)).extname
  @symlink_location = @cache/"#{name}--#{version}#{ext}"
end

#temporary_pathObject

Path for storing an incomplete download while the download is still in progress.


243
244
245
# File 'Library/Homebrew/download_strategy.rb', line 243

def temporary_path
  @temporary_path ||= Pathname.new("#{cached_location}.incomplete")
end