class PoiseArchive::ArchiveProviders::Base
The provider base class for `poise_archive`.
@see PoiseArchive::Resources::PoiseArchive::Resource
@provides poise_archive
Public Class Methods
provides?(node, resource)
click to toggle source
Override normal provider resolution to also check file extension if one was specified in the provider.
@api private
Calls superclass method
# File lib/poise_archive/archive_providers/base.rb, line 50 def self.provides?(node, resource) super && (!@provides_extension || @provides_extension.match(resource.path)) end
provides_extension(match)
click to toggle source
Set the file extension this provider will handle.
@param match [RegExp] Regular expression to match against the archive
file name.
@return [void] @example
class MyProvider < Base provides_extension(/\.hqx$/) end
# File lib/poise_archive/archive_providers/base.rb, line 41 def self.provides_extension(match) provides(:poise_archive) @provides_extension = match end
Public Instance Methods
action_unpack()
click to toggle source
`unpack` action for `poise_archive`.
@return [void]
# File lib/poise_archive/archive_providers/base.rb, line 57 def action_unpack if new_resource.is_url? download_resource = download_file # Check if the download resource updated, if not don't run the rest # of the unpack for idempotence. I could also check # new_resource.updated? but this seems more future proof. return if !download_resource.updated_by_last_action? end converge_by("unpack archive #{new_resource.path} to #{new_resource.destination}") do notifying_block do create_directory end empty_directory unpack_archive end end
Private Instance Methods
create_directory()
click to toggle source
Make sure the destination directory exists.
@return [void]
# File lib/poise_archive/archive_providers/base.rb, line 99 def create_directory directory new_resource.destination do group new_resource.group if new_resource.group owner new_resource.user if new_resource.user # There is explicitly no mode being set here. If a non-default mode # is needed, you should manage that outside of poise_archive. end end
download_file()
click to toggle source
Download the source file to a cache path.
@return [Chef::Resource]
# File lib/poise_archive/archive_providers/base.rb, line 79 def download_file # resource_state used for closure breaking on the notifying block. resource_state = [] notifying_block do # TODO handle cookbook:// for cookbook_file "downloads". resource_state << remote_file(new_resource.absolute_path) do source new_resource.path retries 5 # As a default, could be overridden by source_properties. new_resource.merged_source_properties.each do |key, value| send(key, value) end end end # Return the download resource for state tracking. resource_state.first end
empty_directory()
click to toggle source
Remove all existing content from the destination so we can unpack the new content.
@return [void]
# File lib/poise_archive/archive_providers/base.rb, line 112 def empty_directory # If you want to keep it, not my problem. return if new_resource.keep_existing dest = new_resource.destination Dir.entries(dest).each do |entry| next if entry == '.' || entry == '..' FileUtils.remove_entry_secure(::File.join(dest, entry)) end end
unpack_archive()
click to toggle source
Run the provider-specific unpack behavior.
@abstract @return [void]
# File lib/poise_archive/archive_providers/base.rb, line 126 def unpack_archive raise NotImplementedError end