Files

Class/Module Index [+]

Quicksearch

Chef::ChefFS::FileSystem::CookbookDir

Attributes

versions[R]

Public Class Methods

new(name, parent, versions = nil) click to toggle source
# File lib/chef/chef_fs/file_system/cookbook_dir.rb, line 30
def initialize(name, parent, versions = nil)
  super(name, parent)
  @versions = versions
end

Public Instance Methods

add_child(child) click to toggle source
# File lib/chef/chef_fs/file_system/cookbook_dir.rb, line 49
def add_child(child)
  @children << child
end
api_path() click to toggle source
# File lib/chef/chef_fs/file_system/cookbook_dir.rb, line 53
def api_path
  "#{parent.api_path}/#{name}/_latest"
end
can_have_child?(name, is_dir) click to toggle source
# File lib/chef/chef_fs/file_system/cookbook_dir.rb, line 69
def can_have_child?(name, is_dir)
  # A cookbook's root may not have directories unless they are segment directories
  if is_dir
    return name != 'root_files' &&
           COOKBOOK_SEGMENT_INFO.keys.any? { |segment| segment.to_s == name }
  end
  true
end
chef_object() click to toggle source
# File lib/chef/chef_fs/file_system/cookbook_dir.rb, line 143
def chef_object
  # We cheat and cache here, because it seems like a good idea to keep
  # the cookbook view consistent with the directory structure.
  return @chef_object if @chef_object

  # The negative (not found) response is cached
  if @could_not_get_chef_object
    raise Chef::ChefFS::FileSystem::NotFoundError.new(@could_not_get_chef_object), "#{path_for_printing} not found"
  end

  begin
    # We want to fail fast, for now, because of the 500 issue :/
    # This will make things worse for parallelism, a little, because
    # Chef::Config is global and this could affect other requests while
    # this request is going on.  (We're not parallel yet, but we will be.)
    # Chef bug http://tickets.opscode.com/browse/CHEF-3066
    old_retry_count = Chef::Config[:http_retry_count]
    begin
      Chef::Config[:http_retry_count] = 0
      @chef_object ||= rest.get_rest(api_path)
    ensure
      Chef::Config[:http_retry_count] = old_retry_count
    end
  rescue Net::HTTPServerException
    if $!.response.code == "404"
      @could_not_get_chef_object = $!
      raise Chef::ChefFS::FileSystem::NotFoundError.new(@could_not_get_chef_object), "#{path_for_printing} not found"
    else
      raise
    end

  # Chef bug http://tickets.opscode.com/browse/CHEF-3066 ... instead of 404 we get 500 right now.
  # Remove this when that bug is fixed.
  rescue Net::HTTPFatalError
    if $!.response.code == "500"
      @could_not_get_chef_object = $!
      raise Chef::ChefFS::FileSystem::NotFoundError.new(@could_not_get_chef_object), "#{path_for_printing} not found"
    else
      raise
    end
  end
end
child(name) click to toggle source
# File lib/chef/chef_fs/file_system/cookbook_dir.rb, line 57
def child(name)
  # Since we're ignoring the rules and doing a network request here,
  # we need to make sure we don't rethrow the exception.  (child(name)
  # is not supposed to fail.)
  begin
    result = children.select { |child| child.name == name }.first
    return result if result
  rescue Chef::ChefFS::FileSystem::NotFoundError
  end
  return NonexistentFSObject.new(name, self)
end
children() click to toggle source
# File lib/chef/chef_fs/file_system/cookbook_dir.rb, line 78
def children
  if @children.nil?
    @children = []
    manifest = chef_object.manifest
    COOKBOOK_SEGMENT_INFO.each do |segment, segment_info|
      next unless manifest.has_key?(segment)

      # Go through each file in the manifest for the segment, and
      # add cookbook subdirs and files for it.
      manifest[segment].each do |segment_file|
        parts = segment_file[:path].split('/')
        # Get or create the path to the file
        container = self
        parts[0,parts.length-1].each do |part|
          old_container = container
          container = old_container.children.select { |child| part == child.name }.first
          if !container
            container = CookbookSubdir.new(part, old_container, segment_info[:ruby_only], segment_info[:recursive])
            old_container.add_child(container)
          end
        end
        # Create the file itself
        container.add_child(CookbookFile.new(parts[parts.length-1], container, segment_file))
      end
    end
  end
  @children
end
compare_to(other) click to toggle source
# File lib/chef/chef_fs/file_system/cookbook_dir.rb, line 124
def compare_to(other)
  if !other.dir?
    return [ !exists?, nil, nil ]
  end
  are_same = true
  Chef::ChefFS::CommandLine::diff_entries(self, other, nil, :name_only) do
    are_same = false
  end
  [ are_same, nil, nil ]
end
copy_from(other) click to toggle source
# File lib/chef/chef_fs/file_system/cookbook_dir.rb, line 135
def copy_from(other)
  parent.upload_cookbook_from(other)
end
dir?() click to toggle source
# File lib/chef/chef_fs/file_system/cookbook_dir.rb, line 107
def dir?
  exists?
end
exists?() click to toggle source
# File lib/chef/chef_fs/file_system/cookbook_dir.rb, line 116
def exists?
  if !@versions
    child = parent.children.select { |child| child.name == name }.first
    @versions = child.versions if child
  end
  !!@versions
end
read() click to toggle source
# File lib/chef/chef_fs/file_system/cookbook_dir.rb, line 111
def read
  # This will only be called if dir? is false, which means exists? is false.
  raise Chef::ChefFS::FileSystem::NotFoundError, path_for_printing
end
rest() click to toggle source
# File lib/chef/chef_fs/file_system/cookbook_dir.rb, line 139
def rest
  parent.rest
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.