Class: Chef::Provider::Download
- Inherits:
-
Chef::Provider
- Object
- Chef::Provider
- Chef::Provider::Download
- Includes:
- Mixin::Checksum, Mixin::EnforceOwnershipAndPermissions, Garcon
- Defined in:
- lib/garcon/chef/provider/download.rb
Constant Summary
Constants included from Garcon
Instance Method Summary collapse
-
#action_create ⇒ undefined
(also: #action_create_if_missing)
Default, download the specified source file if it does not exist.
-
#action_delete ⇒ undefined
Use to delete a file.
-
#action_touch ⇒ undefined
Use to touch a file.
-
#initialize(name, run_context = nil) ⇒ Download
constructor
A new instance of Download.
-
#load_current_resource ⇒ Chef::Provider::Download
private
Load and return the current resource.
-
#load_new_resource_state ⇒ undefined
private
Reload the resource state when something changes.
-
#manage_symlink_access? ⇒ Boolean
Implementation components should follow symlinks when managing access control (e.g., use chmod instead of lchmod even if the path we’re managing is a symlink).
-
#whyrun_supported? ⇒ TrueClass, FalseClass
private
Boolean indicating if WhyRun is supported by this provider.
Methods included from Garcon
auto_terminate_all_executors?, auto_terminate_global_executors?, coercer, coercer=, config, configuration, crypto, crypto=, disable_auto_termination_of_all_executors!, disable_auto_termination_of_global_executors!, global_fast_executor, global_io_executor, global_timer_set, included, #inspect, kill_global_executors, monotonic_time, new_fast_executor, new_io_executor, physical_processor_count, processor_count, secret, secret=, shutdown_global_executors, #terminal_dimensions, timer, #to_s, wait_for_global_executors_termination, warn
Constructor Details
#initialize(name, run_context = nil) ⇒ Download
Returns a new instance of Download.
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/garcon/chef/provider/download.rb', line 93 def initialize(name, run_context = nil) super @resource_name = :download @provider = Chef::Provider::Download @ready = AtomicBoolean.new(installed?('aria2c')) @lock = ReadWriteLock.new make_ready unless ready? poll(300) { ready? } end |
Instance Method Details
#action_create ⇒ undefined Also known as: action_create_if_missing
Default, download the specified source file if it does not exist. If a file already exists (but does not match), use to update that file to match.
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/garcon/chef/provider/download.rb', line 155 def action_create if @current_resource.exist? && !access_controls.requires_changes? Chef::Log.debug "#{r.path} already exists - nothing to do" elsif @current_resource.exist? && access_controls.requires_changes? converge_by(access_controls.describe_changes) do access_controls.set_all end r.updated_by_last_action(true) else converge_by "Download #{r.path}" do backup unless ::File.symlink?(r.path) do_download end do_acl_changes load_resource_attributes_from_file(r) r.updated_by_last_action(true) load_new_resource_state r.exist = true end end |
#action_delete ⇒ undefined
Use to delete a file.
185 186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'lib/garcon/chef/provider/download.rb', line 185 def action_delete if @current_resource.exist? converge_by "Delete #{r.path}" do backup unless ::File.symlink?(r.path) ::File.delete(r.path) end r.updated_by_last_action(true) load_new_resource_state r.exist = false else Chef::Log.debug "#{r.path} does not exists - nothing to do" end end |
#action_touch ⇒ undefined
Use to touch a file. This updates the access (atime) and file modification (mtime) times for a file. (This action may be used with this resource, but is typically only used with the file resource.)
206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/garcon/chef/provider/download.rb', line 206 def action_touch if @current_resource.exist? converge_by "Update utime on #{r.path}" do time = Time.now ::File.utime(time, time, r.path) end r.updated_by_last_action(true) load_new_resource_state r.exist = true else Chef::Log.debug "#{r.path} does not exists - nothing to do" end end |
#load_current_resource ⇒ Chef::Provider::Download
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Load and return the current resource.
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/garcon/chef/provider/download.rb', line 131 def load_current_resource @current_resource ||= Chef::Resource::Download.new(r.name) @current_resource.path(r.path) if ::File.exist?(@current_resource.path) @current_resource.checksum(checksum(@current_resource.path)) if @current_resource.checksum == r.checksum @current_resource.exist = true else @current_resource.exist = false end else @current_resource.exist = false end @current_resource end |
#load_new_resource_state ⇒ undefined
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Reload the resource state when something changes
122 123 124 |
# File 'lib/garcon/chef/provider/download.rb', line 122 def load_new_resource_state r.exist = @current_resource.exist if r.exist.nil? end |
#manage_symlink_access? ⇒ Boolean
Implementation components should follow symlinks when managing access control (e.g., use chmod instead of lchmod even if the path we’re managing is a symlink).
224 225 226 |
# File 'lib/garcon/chef/provider/download.rb', line 224 def manage_symlink_access? false end |
#whyrun_supported? ⇒ TrueClass, FalseClass
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Boolean indicating if WhyRun is supported by this provider
113 114 115 |
# File 'lib/garcon/chef/provider/download.rb', line 113 def whyrun_supported? true end |