Class: Omnibus::NetFetcher

Inherits:
Fetcher
  • Object
show all
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)
TAR_EXTENSIONS =

tar probably has compression scheme linked in, otherwise for tarballs

%w(.tar .tar.gz .tgz tar.bz2 .tar.xz .txz .tar.lzma)
DIGESTS =

Digest types used for verifying file checksums

[:sha512, :sha256, :sha1, :md5]

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 inherited from Fetcher

#fetcher, #initialize, #version

Methods included from Util

#copy_file, #create_directory, #create_file, #create_link, included, #remove_directory, #remove_file, #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.


104
105
106
# File 'lib/omnibus/fetchers/net_fetcher.rb', line 104

def self.resolve_version(version, source)
  version
end

Instance Method Details

#checksumString

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


124
125
126
# File 'lib/omnibus/fetchers/net_fetcher.rb', line 124

def checksum
  source[digest_type]
end

#cleantrue, false

Clean the project directory by removing the contents from disk.


59
60
61
62
63
64
65
66
67
68
69
# File 'lib/omnibus/fetchers/net_fetcher.rb', line 59

def clean
  if File.exist?(project_dir)
    log.info(log_key) { "Cleaning project directory `#{project_dir}'" }
    FileUtils.rm_rf(project_dir)
    extract
    true
  else
    extract
    false
  end
end

#downloaded_fileString

The path on disk to the downloaded asset. This method requires the presence of a source_uri.


114
115
116
117
# File 'lib/omnibus/fetchers/net_fetcher.rb', line 114

def downloaded_file
  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.


78
79
80
81
82
83
84
85
# File 'lib/omnibus/fetchers/net_fetcher.rb', line 78

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

  create_required_directories
  download
  verify_checksum!
  extract
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.


39
40
41
# File 'lib/omnibus/fetchers/net_fetcher.rb', line 39

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.


93
94
95
# File 'lib/omnibus/fetchers/net_fetcher.rb', line 93

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.


49
50
51
# File 'lib/omnibus/fetchers/net_fetcher.rb', line 49

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