Class: Chef::Provider::CookbookFile

Inherits:
File show all
Includes:
Mixin::EnforceOwnershipAndPermissions
Defined in:
lib/chef/provider/cookbook_file.rb

Constant Summary

Constants included from Mixin::ShellOut

Mixin::ShellOut::DEPRECATED_OPTIONS

Instance Attribute Summary

Attributes inherited from Chef::Provider

#action, #current_resource, #new_resource, #run_context

Instance Method Summary collapse

Methods included from Mixin::EnforceOwnershipAndPermissions

#access_controls, #enforce_ownership_and_permissions

Methods inherited from File

#action_create_if_missing, #action_delete, #action_touch, #backup, #compare_content, #define_resource_requirements, #deploy_tempfile, #diff_current, #diff_current_from_content, #is_binary?, #set_all_access_controls, #set_content, #setup_acl, #update_new_file_state

Methods included from Mixin::ShellOut

#run_command_compatible_options, #shell_out, #shell_out!

Methods included from Mixin::Checksum

#checksum

Methods inherited from Chef::Provider

#action_nothing, #cleanup_after_converge, #cookbook_name, #define_resource_requirements, #events, #initialize, #node, #process_resource_requirements, #requirements, #resource_collection, #run_action, #set_updated_status, #whyrun_mode?

Methods included from DSL::Recipe

#method_missing

Methods included from Mixin::ConvertToClassName

#convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string, #snake_case_basename

Constructor Details

This class inherits a constructor from Chef::Provider

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Chef::DSL::Recipe

Instance Method Details

#action_createObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/chef/provider/cookbook_file.rb', line 38

def action_create
  if file_cache_location && content_stale? 
    description = []
    description << "create a new cookbook_file #{@new_resource.path}"
    description << diff_current(file_cache_location)
    converge_by(description) do
      Chef::Log.debug("#{@new_resource} has new contents")
      backup_new_resource
      deploy_tempfile do |tempfile|
        Chef::Log.debug("#{@new_resource} staging #{file_cache_location} to #{tempfile.path}")
        tempfile.close
        FileUtils.cp(file_cache_location, tempfile.path)
        enforce_tempfile_inheritance(tempfile.path)              
      end
      update_new_file_state
      Chef::Log.info("#{@new_resource} created file #{@new_resource.path}")
    end
  else
    set_all_access_controls
  end
end

#backup_new_resourceObject



74
75
76
77
78
# File 'lib/chef/provider/cookbook_file.rb', line 74

def backup_new_resource
  if ::File.exists?(@new_resource.path)
    backup @new_resource.path
  end
end

#content_stale?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/chef/provider/cookbook_file.rb', line 80

def content_stale?
  ( ! ::File.exist?(@new_resource.path)) || ( ! compare_content)
end

#file_cache_locationObject



60
61
62
63
64
65
# File 'lib/chef/provider/cookbook_file.rb', line 60

def file_cache_location
  @file_cache_location ||= begin
    cookbook = run_context.cookbook_collection[resource_cookbook]
    cookbook.preferred_filename_on_disk_location(node, :files, @new_resource.source, @new_resource.path)
  end
end

#load_current_resourceObject



33
34
35
36
# File 'lib/chef/provider/cookbook_file.rb', line 33

def load_current_resource
  @current_resource = Chef::Resource::CookbookFile.new(@new_resource.name)
  super
end

#resource_cookbookObject

Determine the cookbook to get the file from. If new resource sets an explicit cookbook, use it, otherwise fall back to the implicit cookbook i.e., the cookbook the resource was declared in.



70
71
72
# File 'lib/chef/provider/cookbook_file.rb', line 70

def resource_cookbook
  @new_resource.cookbook || @new_resource.cookbook_name
end

#whyrun_supported?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/chef/provider/cookbook_file.rb', line 29

def whyrun_supported?
  true
end