Class: Omnibus::NetFetcher

Inherits:
Fetcher
  • Object
show all
Includes:
DownloadHelpers
Defined in:
lib/omnibus/fetchers/net_fetcher.rb

Constant Summary collapse

WIN_7Z_EXTENSIONS =

Use 7-zip to extract 7z/zip for Windows

%w{.7z .zip}.freeze
COMPRESSED_TAR_EXTENSIONS =

tar probably has compression scheme linked in, otherwise for tarballs

%w{.tar.gz .tgz tar.bz2 .tar.xz .txz .tar.lzma}.freeze
TAR_EXTENSIONS =
COMPRESSED_TAR_EXTENSIONS + [".tar"]
ALL_EXTENSIONS =
WIN_7Z_EXTENSIONS + TAR_EXTENSIONS
DIGESTS =

Digest types used for verifying file checksums

%i{sha512 sha256 sha1 md5}.freeze

Constants included from Util

Util::SHELLOUT_OPTIONS

Instance Attribute Summary

Attributes inherited from Fetcher

#build_dir, #described_version, #name, #project_dir, #resolved_version, #source

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DownloadHelpers

included

Methods inherited from Fetcher

#fetcher, #initialize, #version

Methods included from Util

#compiler_safe_path, #copy_file, #create_directory, #create_file, #create_link, included, #path_key, #remove_directory, #remove_file, #retry_block, #shellout, #shellout!, #windows_safe_path

Methods included from Logging

included

Methods included from Digestable

#digest, #digest_directory, included

Constructor Details

This class inherits a constructor from Omnibus::Fetcher

Class Method Details

.resolve_version(version, source) ⇒ String

Returned the resolved version for the manifest. Since this is a remote URL, there is no resolution, the version is what we said it is.

Returns:

  • (String)


110
111
112
# File 'lib/omnibus/fetchers/net_fetcher.rb', line 110

def self.resolve_version(version, source)
  version
end

Instance Method Details

#checksumString

The checksum as defined by the user in the software definition.

Returns:

  • (String)


132
133
134
# File 'lib/omnibus/fetchers/net_fetcher.rb', line 132

def checksum
  source[digest_type]
end

#cleantrue, false

Clean the project directory if it exists and actually extract the downloaded file.

Returns:

  • (true, false)

    true if the project directory was removed, false otherwise



64
65
66
67
68
69
70
71
72
73
# File 'lib/omnibus/fetchers/net_fetcher.rb', line 64

def clean
  needs_cleaning = File.exist?(project_dir)
  if needs_cleaning
    log.info(log_key) { "Cleaning project directory `#{project_dir}'" }
    FileUtils.rm_rf(project_dir)
  end
  create_required_directories
  deploy
  needs_cleaning
end

#downloaded_fileString

The path on disk to the downloaded asset. The filename is defined by source :cached_name. If ommited, then it comes from the software’s source :url value

Returns:

  • (String)


121
122
123
124
125
# File 'lib/omnibus/fetchers/net_fetcher.rb', line 121

def downloaded_file
  filename = source[:cached_name] if source[:cached_name]
  filename ||= File.basename(source[:url], "?*")
  File.join(Config.cache_dir, filename)
end

#fetchvoid

This method returns an undefined value.

Fetch the given software definition. This method always fetches the file, even if it already exists on disk! You should use #fetch_required? to guard against this check in your implementation.



82
83
84
85
86
87
88
# File 'lib/omnibus/fetchers/net_fetcher.rb', line 82

def fetch
  log.info(log_key) { "Downloading from `#{download_url}'" }

  create_required_directories
  download
  verify_checksum!
end

#fetch_required?true, false

A fetch is required if the downloaded_file (such as a tarball) does not exist on disk, or if the checksum of the downloaded file is different than the given checksum.

Returns:

  • (true, false)


43
44
45
# File 'lib/omnibus/fetchers/net_fetcher.rb', line 43

def fetch_required?
  !(File.exist?(downloaded_file) && digest(downloaded_file, digest_type) == checksum)
end

#version_for_cacheString

The version for this item in the cache. This is the digest of downloaded file and the URL where it was downloaded from.

This method is called before clean but after fetch. Do not ever use the contents of the project_dir here.

Returns:

  • (String)


99
100
101
# File 'lib/omnibus/fetchers/net_fetcher.rb', line 99

def version_for_cache
  "download_url:#{source[:url]}|#{digest_type}:#{checksum}"
end

#version_guidString

The version identifier for this remote location. This is computed using the name of the software, the version of the software, and the checksum.

Returns:

  • (String)


53
54
55
# File 'lib/omnibus/fetchers/net_fetcher.rb', line 53

def version_guid
  "#{digest_type}:#{checksum}"
end