Class: Chef::Provider::Download

Inherits:
Chef::Provider show all
Includes:
Mixin::Checksum, Mixin::EnforceOwnershipAndPermissions, Garcon
Defined in:
lib/garcon/chef/provider/download.rb

Constant Summary

Constants included from Garcon

Garcon::VERSION

Instance Method Summary collapse

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_createundefined 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.

Returns:

  • (undefined)


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_deleteundefined

Use to delete a file.

Returns:

  • (undefined)


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_touchundefined

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.)

Returns:

  • (undefined)


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_resourceChef::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_stateundefined

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

Returns:

  • (undefined)


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

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).

Returns:



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

Returns:



113
114
115
# File 'lib/garcon/chef/provider/download.rb', line 113

def whyrun_supported?
  true
end