Method: Chef::ChefFS::ChefFSDataStore#delete_dir

Defined in:
lib/chef/chef_fs/chef_fs_data_store.rb

#delete_dir(path, *options) ⇒ Object



449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
# File 'lib/chef/chef_fs/chef_fs_data_store.rb', line 449

def delete_dir(path, *options)
  if use_memory_store?(path)
    @memory_store.delete_dir(path, *options)

  # DELETE /policies/POLICY
  elsif path[0] == "policies" && path.length == 2
    with_entry(path[0..0]) do |policies|
      # /policies:
      #   - a-1.0.0.json
      #   - a-1.0.1.json
      #   - b-2.0.0.json
      found_policy = false
      policies.children.each do |policy|
        # We want to delete just the ones that == POLICY
        next unless policy.name.rpartition("-")[0] == path[1]

        policy.delete(false)
        FileSystemCache.instance.delete!(policy.file_path)
        found_policy = true
      end
      raise ChefZero::DataStore::DataNotFoundError.new(path) unless found_policy
    end

  else
    with_entry(path) do |entry|

      entry.delete(options.include?(:recursive))
    rescue Chef::ChefFS::FileSystem::NotFoundError => e
      raise ChefZero::DataStore::DataNotFoundError.new(to_zero_path(e.entry), e)

    end
  end
end