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 .bz2 .tar.xz .txz)

Constants included from Util

Util::SHELLOUT_OPTIONS

Instance Attribute Summary

Attributes inherited from Fetcher

#software

Instance Method Summary collapse

Methods inherited from Fetcher

#initialize

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

Constructor Details

This class inherits a constructor from Omnibus::Fetcher

Instance Method Details

#checksumString

The checksum (md5) as defined by the user in the software definition.


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

def checksum
  source[:md5]
end

#cleantrue, false

Clean the project directory by removing the contents from disk.


55
56
57
58
59
60
61
62
63
64
65
# File 'lib/omnibus/fetchers/net_fetcher.rb', line 55

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.


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

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.


74
75
76
77
78
79
80
81
# File 'lib/omnibus/fetchers/net_fetcher.rb', line 74

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.


35
36
37
# File 'lib/omnibus/fetchers/net_fetcher.rb', line 35

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

#version_for_cacheString

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


89
90
91
# File 'lib/omnibus/fetchers/net_fetcher.rb', line 89

def version_for_cache
  "download_url:#{source[:url]}|md5:#{source[:md5]}"
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.


45
46
47
# File 'lib/omnibus/fetchers/net_fetcher.rb', line 45

def version_guid
  "md5:#{checksum}"
end