Class: Chef::Provider::Directory

Inherits:
File show all
Defined in:
lib/chef/provider/directory.rb

Direct Known Subclasses

RemoteDirectory

Instance Attribute Summary

Attributes inherited from Chef::Provider

#current_resource, #new_resource, #node

Instance Method Summary collapse

Methods inherited from File

#action_create_if_missing, #action_touch, #backup, #compare_group, #compare_mode, #compare_owner, #generate_url, #set_group, #set_mode, #set_owner

Methods included from Mixin::GenerateURL

#generate_cookbook_url

Methods included from Mixin::Checksum

#checksum

Methods inherited from Chef::Provider

#action_nothing, build_from_file, #initialize

Methods included from Mixin::ConvertToClassName

#convert_to_class_name, #filename_to_qualified_string

Methods included from Mixin::RecipeDefinitionDSLCore

#method_missing

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::Mixin::RecipeDefinitionDSLCore

Instance Method Details

#action_createObject



41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/chef/provider/directory.rb', line 41

def action_create
  unless ::File.exists?(@new_resource.path)
    Chef::Log.info("Creating #{@new_resource} at #{@new_resource.path}")
    if @new_resource.recursive == true
      ::FileUtils.mkdir_p(@new_resource.path)
    else
      ::Dir.mkdir(@new_resource.path)
    end
    @new_resource.updated = true
  end
  set_owner if @new_resource.owner != nil
  set_group if @new_resource.group != nil
  set_mode if @new_resource.mode != nil
end

#action_deleteObject



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/chef/provider/directory.rb', line 56

def action_delete
  if ::File.directory?(@new_resource.path) && ::File.writable?(@new_resource.path)
    if @new_resource.recursive == true
      Chef::Log.info("Deleting #{@new_resource} recursively at #{@new_resource.path}")
      FileUtils.rm_rf(@new_resource.path)
    else
      Chef::Log.info("Deleting #{@new_resource} at #{@new_resource.path}")
      ::Dir.delete(@new_resource.path)
    end
    @new_resource.updated = true
  else
    raise RuntimeError, "Cannot delete #{@new_resource} at #{@new_resource_path}!" if ::File.exists?(@new_resource.path)
  end
end

#load_current_resourceObject



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/chef/provider/directory.rb', line 29

def load_current_resource
  @current_resource = Chef::Resource::Directory.new(@new_resource.name)
  @current_resource.path(@new_resource.path)
  if ::File.exist?(@current_resource.path) && ::File.directory?(@current_resource.path)
    cstats = ::File.stat(@current_resource.path)
    @current_resource.owner(cstats.uid)
    @current_resource.group(cstats.gid)
    @current_resource.mode("%o" % (cstats.mode & 007777))
  end
  @current_resource
end