class FDB::DirectoryLayer

def move(db_or_tr, old_path, new_path)

def move(db_or_tr, old_path, new_path)
  db_or_tr.transact do |tr|
    check_version(tr, true)
    old_path = to_unicode_path(old_path)
    new_path = to_unicode_path(new_path)
    if old_path == new_path[0...old_path.length]
      raise ArgumentError, 
        'The desination directory cannot be a subdirectory of the source directory.'
    end
    old_node = find(tr, old_path).prefetch_metadata(tr)
    new_node = find(tr, new_path).prefetch_metadata(tr)
    raise ArgumentError, 'The source directory does not exist.' unless old_node.exists?
    if old_node.is_in_partition? || new_node.is_in_partition?
      if !old_node.is_in_partition? || 
        !new_node.is_in_partition? || 
        old_node.path != new_node.path
      then
        raise ArgumentError, 'Cannot move between partitions'
      end
      next new_node
        .get_contents(self)
        .move(tr, old_node.get_partition_subpath, new_node.get_partition_subpath)
    end
    if new_node.exists?
      raise ArgumentError, 'The destination directory already exists. Remove it first.'
    end
    parent_node = find(tr, new_path[0...-1])
    if !parent_node.exists?
      raise ArgumentError, 
        'The parent directory of the destination directory does not exist. Create it first.'
    end
    
    tr[parent_node.subspace[@@SUBDIRS][new_path[-1]]] = 
      @node_subspace.unpack(old_node.subspace.key)[0]
    remove_from_parent(tr, old_path)
    contents_of_node(old_node.subspace, new_path, old_node.layer)
  end
end