class Chef::Provider::Download

Public Class Methods

new(name, run_context = nil) click to toggle source
Calls superclass method
# 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

Public Instance Methods

action_create() click to toggle source

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.

@return [undefined]

@api public

# 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
Also aliased as: action_create_if_missing
action_create_if_missing()
Alias for: action_create
action_delete() click to toggle source

Use to delete a file.

@return [undefined]

@api public

# 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() click to toggle source

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

@return [undefined]

@api public

# 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() click to toggle source

Load and return the current resource.

@return [Chef::Provider::Download]

@api private

# 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() click to toggle source

Reload the resource state when something changes

@return [undefined]

@api private

# File lib/garcon/chef/provider/download.rb, line 122
def load_new_resource_state
  r.exist = @current_resource.exist if r.exist.nil?
end
whyrun_supported?() click to toggle source

Boolean indicating if WhyRun is supported by this provider

@return [TrueClass, FalseClass]

@api private

# File lib/garcon/chef/provider/download.rb, line 113
def whyrun_supported?
  true
end