method

realpath_rec

Importance_0
v1_8_7_72 - Show latest stable - 0 notes - Class: Pathname
realpath_rec(prefix, unresolved, h) private

No documentation

This method has no description. You can help the Ruby community by adding new notes.

Hide source
# File lib/pathname.rb, line 403
  def realpath_rec(prefix, unresolved, h)
    resolved = []
    until unresolved.empty?
      n = unresolved.shift
      if n == '.'
        next
      elsif n == '..'
        resolved.pop
      else
        path = prepend_prefix(prefix, File.join(*(resolved + [n])))
        if h.include? path
          if h[path] == :resolving
            raise Errno::ELOOP.new(path)
          else
            prefix, *resolved = h[path]
          end
        else
          s = File.lstat(path)
          if s.symlink?
            h[path] = :resolving
            link_prefix, link_names = split_names(File.readlink(path))
            if link_prefix == ''
              prefix, *resolved = h[path] = realpath_rec(prefix, resolved + link_names, h)
            else
              prefix, *resolved = h[path] = realpath_rec(link_prefix, link_names, h)
            end
          else
            resolved << n
            h[path] = [prefix, *resolved]
          end
        end
      end
    end
    return prefix, *resolved
  end
Register or log in to add new notes.