class FDB::DirectoryLayer

def remove_internal(db_or_tr, path, fail_on_nonexistent)

def remove_internal(db_or_tr, path, fail_on_nonexistent)
  db_or_tr.transact do |tr|
    check_version(tr, true)
    path = to_unicode_path(path)
    if path.empty?
      raise ArgumentError, 'The root directory cannot be removed.'
    end
    node = find(tr, path).prefetch_metadata(tr)
    if !node.exists?
      raise ArgumentError, 'The directory does not exist.' if fail_on_nonexistent
      next false
    end
    if node.is_in_partition?
      next node.get_contents(self).directory_layer
                  .remove_internal(tr, node.get_partition_subpath, fail_on_nonexistent)
    end
    remove_recursive(tr, node.subspace)
    remove_from_parent(tr, path)
    true
  end
end