Module: Chef::ChefFS::FileSystem

Defined in:
lib/chef/chef_fs/file_system.rb,
lib/chef/chef_fs/file_system/exceptions.rb,
lib/chef/chef_fs/file_system/base_fs_dir.rb,
lib/chef/chef_fs/file_system/base_fs_object.rb,
lib/chef/chef_fs/file_system/repository/acl.rb,
lib/chef/chef_fs/file_system/multiplexed_dir.rb,
lib/chef/chef_fs/file_system/repository/node.rb,
lib/chef/chef_fs/file_system/repository/role.rb,
lib/chef/chef_fs/file_system/repository/user.rb,
lib/chef/chef_fs/file_system/repository/group.rb,
lib/chef/chef_fs/file_system/memory/memory_dir.rb,
lib/chef/chef_fs/file_system/repository/client.rb,
lib/chef/chef_fs/file_system/repository/policy.rb,
lib/chef/chef_fs/file_system/memory/memory_file.rb,
lib/chef/chef_fs/file_system/memory/memory_root.rb,
lib/chef/chef_fs/file_system/chef_server/acl_dir.rb,
lib/chef/chef_fs/file_system/repository/acls_dir.rb,
lib/chef/chef_fs/file_system/repository/data_bag.rb,
lib/chef/chef_fs/file_system/chef_server/acls_dir.rb,
lib/chef/chef_fs/file_system/repository/base_file.rb,
lib/chef/chef_fs/file_system/repository/container.rb,
lib/chef/chef_fs/file_system/repository/directory.rb,
lib/chef/chef_fs/file_system/repository/nodes_dir.rb,
lib/chef/chef_fs/file_system/repository/roles_dir.rb,
lib/chef/chef_fs/file_system/repository/users_dir.rb,
lib/chef/chef_fs/file_system/chef_server/acl_entry.rb,
lib/chef/chef_fs/file_system/chef_server/nodes_dir.rb,
lib/chef/chef_fs/file_system/chef_server/org_entry.rb,
lib/chef/chef_fs/file_system/nonexistent_fs_object.rb,
lib/chef/chef_fs/file_system/repository/client_key.rb,
lib/chef/chef_fs/file_system/repository/groups_dir.rb,
lib/chef/chef_fs/file_system/repository/clients_dir.rb,
lib/chef/chef_fs/file_system/repository/environment.rb,
lib/chef/chef_fs/file_system/repository/acls_sub_dir.rb,
lib/chef/chef_fs/file_system/repository/policies_dir.rb,
lib/chef/chef_fs/file_system/repository/policy_group.rb,
lib/chef/chef_fs/file_system/chef_server/cookbook_dir.rb,
lib/chef/chef_fs/file_system/chef_server/data_bag_dir.rb,
lib/chef/chef_fs/file_system/chef_server/policies_dir.rb,
lib/chef/chef_fs/file_system/repository/cookbooks_dir.rb,
lib/chef/chef_fs/file_system/repository/data_bag_item.rb,
lib/chef/chef_fs/file_system/repository/data_bags_dir.rb,
lib/chef/chef_fs/file_system/chef_server/cookbook_file.rb,
lib/chef/chef_fs/file_system/chef_server/cookbooks_dir.rb,
lib/chef/chef_fs/file_system/chef_server/data_bags_dir.rb,
lib/chef/chef_fs/file_system/chef_server/rest_list_dir.rb,
lib/chef/chef_fs/file_system/repository/containers_dir.rb,
lib/chef/chef_fs/file_system/chef_server/data_bag_entry.rb,
lib/chef/chef_fs/file_system/repository/client_keys_dir.rb,
lib/chef/chef_fs/file_system/chef_server/cookbook_subdir.rb,
lib/chef/chef_fs/file_system/chef_server/rest_list_entry.rb,
lib/chef/chef_fs/file_system/repository/environments_dir.rb,
lib/chef/chef_fs/file_system/chef_server/environments_dir.rb,
lib/chef/chef_fs/file_system/chef_server/policies_acl_dir.rb,
lib/chef/chef_fs/file_system/repository/file_system_entry.rb,
lib/chef/chef_fs/file_system/repository/policy_groups_dir.rb,
lib/chef/chef_fs/file_system/chef_server/cookbooks_acl_dir.rb,
lib/chef/chef_fs/file_system/chef_server/policy_groups_dir.rb,
lib/chef/chef_fs/file_system/chef_server/policy_group_entry.rb,
lib/chef/chef_fs/file_system/repository/client_keys_sub_dir.rb,
lib/chef/chef_fs/file_system/chef_server/chef_server_root_dir.rb,
lib/chef/chef_fs/file_system/chef_server/cookbook_artifact_dir.rb,
lib/chef/chef_fs/file_system/chef_server/policy_revision_entry.rb,
lib/chef/chef_fs/file_system/repository/cookbook_artifacts_dir.rb,
lib/chef/chef_fs/file_system/chef_server/cookbook_artifacts_dir.rb,
lib/chef/chef_fs/file_system/chef_server/versioned_cookbook_dir.rb,
lib/chef/chef_fs/file_system/repository/versioned_cookbooks_dir.rb,
lib/chef/chef_fs/file_system/chef_server/versioned_cookbooks_dir.rb,
lib/chef/chef_fs/file_system/chef_server/organization_invites_entry.rb,
lib/chef/chef_fs/file_system/chef_server/organization_members_entry.rb,
lib/chef/chef_fs/file_system/repository/chef_repository_file_system_root_dir.rb,
lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb,
lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_entry.rb,
lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_artifact_dir.rb,
lib/chef/chef_fs/file_system/repository/chef_repository_file_system_versioned_cookbook_dir.rb

Defined Under Namespace

Modules: ChefServer, Memory, Repository Classes: AlreadyExistsError, BaseFSDir, BaseFSObject, CookbookFrozenError, DefaultEnvironmentCannotBeModifiedError, FileSystemError, Lister, MultiplexedDir, MustDeleteRecursivelyError, NonexistentFSObject, NotFoundError, OperationFailedError, OperationNotAllowedError, PairLister, RubyFileError

Class Method Summary collapse

Class Method Details

.child_pairs(a, b) ⇒ Object

Get entries for children of either a or b, with matching pairs matched up.

==== Returns

An array of child pairs.

[ [ a_child, b_child ], ... ]

If a child is only in a or only in b, the other child entry will be retrieved by name (and will most likely be a "nonexistent child").

==== Example

Chef::ChefFS::FileSystem.child_pairs(a, b).length

220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'lib/chef/chef_fs/file_system.rb', line 220

def self.child_pairs(a, b)
  # If both are directories, recurse into them and diff the children instead of returning ourselves.
  result = []
  a_children_names = Set.new
  a.children.each do |a_child|
    a_children_names << a_child.bare_name
    result << [ a_child, b.child(a_child.bare_name) ]
  end

  # Check b for children that aren't in a
  b.children.each do |b_child|
    if !a_children_names.include?(b_child.bare_name)
      result << [ a.child(b_child.bare_name), b_child ]
    end
  end
  result
end

.compare(a, b) ⇒ Object


238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/chef/chef_fs/file_system.rb', line 238

def self.compare(a, b)
  are_same, a_value, b_value = a.compare_to(b)
  if are_same.nil?
    are_same, b_value, a_value = b.compare_to(a)
  end
  if are_same.nil?
    # TODO these reads can be parallelized
    begin
      a_value = a.read if a_value.nil?
    rescue Chef::ChefFS::FileSystem::NotFoundError
      a_value = :none
    end
    begin
      b_value = b.read if b_value.nil?
    rescue Chef::ChefFS::FileSystem::NotFoundError
      b_value = :none
    end
    are_same = (a_value == b_value)
  end
  [ are_same, a_value, b_value ]
end

.copy_to(pattern, src_root, dest_root, recurse_depth, options, ui = nil, format_path = nil) ⇒ Object

Copy everything matching the given pattern from src to dest.

After this method completes, everything in dest matching the given pattern will look identical to src.

==== Attributes

  • +pattern+ - Chef::ChefFS::FilePattern to match children under
  • +src_root+ - the root from which things will be copied
  • +dest_root+ - the root to which things will be copied
  • +recurse_depth+ - the maximum depth to copy things. +nil+ means infinite depth. 0 means no recursion.
  • +options+ - hash of options:
    • +purge+ - if +true+, items in +dest+ that are not in +src+ will be deleted from +dest+. If +false+, these items will be left alone.
    • +force+ - if +true+, matching files are always copied from +src+ to +dest+. If +false+, they will only be copied if actually different (which will take time to determine).
    • +dry_run+ - if +true+, action will not actually be taken; things will be printed out instead.

==== Examples

Chef::ChefFS::FileSystem.copy_to(FilePattern.new('/cookbooks'),
  chef_fs, local_fs, nil, true) do |message|
  puts message
end

137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/chef/chef_fs/file_system.rb', line 137

def self.copy_to(pattern, src_root, dest_root, recurse_depth, options, ui = nil, format_path = nil)
  found_result = false
  error = false
  parallel_do(list_pairs(pattern, src_root, dest_root)) do |src, dest|
    found_result = true
    new_dest_parent = get_or_create_parent(dest, options, ui, format_path)
    child_error = copy_entries(src, dest, new_dest_parent, recurse_depth, options, ui, format_path)
    error ||= child_error
  end
  if !found_result && pattern.exact_path
    ui.error "#{pattern}: No such file or directory on remote or local" if ui
    error = true
  end
  error
end

.list(root, pattern) ⇒ Object

Returns a list of all things under (and including) this entry that match the given pattern.

==== Attributes

  • +root+ - Entry to start listing under
  • +pattern+ - Chef::ChefFS::FilePattern to match children under

34
35
36
# File 'lib/chef/chef_fs/file_system.rb', line 34

def self.list(root, pattern)
  Lister.new(root, pattern)
end

.list_pairs(pattern, a_root, b_root) ⇒ Object

Yield entries for children that are in either +a_root+ or +b_root+, with matching pairs matched up.

==== Yields

Yields matching entries in pairs:

[ a_entry, b_entry ]

==== Example

Chef::ChefFS::FileSystem.list_pairs(FilePattern.new('**x.txt', a_root, b_root)).each do |a, b|
  ...
end

168
169
170
# File 'lib/chef/chef_fs/file_system.rb', line 168

def self.list_pairs(pattern, a_root, b_root)
  PairLister.new(pattern, a_root, b_root)
end

.resolve_path(entry, path) ⇒ Object

Resolve the given path against the entry, returning the entry at the end of the path.

==== Attributes

  • +entry+ - the entry to start looking under. Relative paths will be resolved from here.
  • +path+ - the path to resolve. If it starts with +/+, the path will be resolved starting from +entry.root+.

==== Examples

Chef::ChefFS::FileSystem.resolve_path(root_path, 'cookbooks/java/recipes/default.rb')

94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/chef/chef_fs/file_system.rb', line 94

def self.resolve_path(entry, path)
  return entry if path.length == 0
  return resolve_path(entry.root, path) if path[0, 1] == "/" && entry.root != entry
  if path[0, 1] == "/"
    path = path[1, path.length - 1]
  end

  result = entry
  Chef::ChefFS::PathUtils.split(path).each do |part|
    result = result.child(part)
  end
  result
end