Class: Omnibus::FileFetcher

Inherits:
Fetcher
  • Object
show all
Defined in:
lib/omnibus/fetchers/file_fetcher.rb

Constant Summary

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

#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?

Returns:

  • (String, nil)


87
88
89
# File 'lib/omnibus/fetchers/file_fetcher.rb', line 87

def self.resolve_version(version, source)
  version
end

Instance Method Details

#cleantrue, false

Clean the given path by removing the project directory.

Returns:

  • (true, false)

    true if the directory was cleaned, false otherwise. Since we do not currently use the cache to sync files and always fetch from source, there is no need to clean anything. The fetch step (which needs to be called before clean) would have already removed anything extraneous.



51
52
53
# File 'lib/omnibus/fetchers/file_fetcher.rb', line 51

def clean
  true
end

#fetchvoid

This method returns an undefined value.

Fetch any new files by copying them to the project_dir.



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

def fetch
  log.info(log_key) { "Copying from `#{source_file}'" }

  create_required_directories
  FileUtils.cp(source_file, target_file)
  # Reset target shasum on every fetch
  @target_shasum = nil
  target_shasum
end

#fetch_required?true, false

Fetch if the local file checksum is different than the path file checksum.

Returns:

  • (true, false)


27
28
29
# File 'lib/omnibus/fetchers/file_fetcher.rb', line 27

def fetch_required?
  target_shasum != destination_shasum
end

#version_for_cacheString

The version for this item in the cache. The is the shasum of the file on disk.

This method is called before clean but after fetch. Since fetch automatically cleans, target vs. destination sha doesn’t matter. Change this if that assumption changes.

Returns:

  • (String)


80
81
82
# File 'lib/omnibus/fetchers/file_fetcher.rb', line 80

def version_for_cache
  "file:#{source_file}|shasum:#{destination_shasum}"
end

#version_guidString

The version identifier for this file. This is computed using the file on disk to the source and the shasum of that file on disk.

Returns:

  • (String)


37
38
39
# File 'lib/omnibus/fetchers/file_fetcher.rb', line 37

def version_guid
  "file:#{source_file}"
end