class Omnibus::FileFetcher
Public Class Methods
@return [String, nil]
# File lib/omnibus/fetchers/file_fetcher.rb, line 87 def self.resolve_version(version, source) version end
Public Instance Methods
Clean the given path by removing the project directory.
@return [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.
# File lib/omnibus/fetchers/file_fetcher.rb, line 51 def clean true end
Fetch any new files by copying them to the project_dir
.
@return [void]
# 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 if the local file checksum is different than the path file checksum.
@return [true, false]
# File lib/omnibus/fetchers/file_fetcher.rb, line 27 def fetch_required? target_shasum != destination_shasum end
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.
@return [String]
# File lib/omnibus/fetchers/file_fetcher.rb, line 80 def version_for_cache "file:#{source_file}|shasum:#{destination_shasum}" end
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.
@return [String]
# File lib/omnibus/fetchers/file_fetcher.rb, line 37 def version_guid "file:#{source_file}" end
Private Instance Methods
The shasum of the file outside of the project.
@return [String]
# File lib/omnibus/fetchers/file_fetcher.rb, line 127 def destination_shasum @destination_shasum ||= digest(source_file, :sha256) end
The path on disk to pull the file from.
@return [String]
# File lib/omnibus/fetchers/file_fetcher.rb, line 98 def source_file source[:file] end
The path on disk where the file is stored.
@return [String]
# File lib/omnibus/fetchers/file_fetcher.rb, line 107 def target_file File.join(project_dir, File.basename(source_file)) end
The shasum of the file inside the project.
@return [String, nil]
# File lib/omnibus/fetchers/file_fetcher.rb, line 116 def target_shasum @target_shasum ||= digest(target_file, :sha256) rescue Errno::ENOENT @target_shasum = nil end