/** * Returns Fs_Node of canonicalized absolute pathname, resolving symlinks. * Unlike the realpath() PHP function, this returns a best-effort for non-existent files. * * Use Fs::NO_DEREFERENCE to not dereference. * * @param int $flags Fs::% options * @return Fs_Node * @throws Fs_Exception if Fs::ALWAYS_FOLLOW is not set */ public function realpath($flags = 0) { if ($flags & Fs::NO_DEREFERENCE) { $target = Fs::canonicalize($this->target(), dirname($this->_path)); if (is_link($target)) { return new static($target); } if (~$flags & Fs::ALWAYS_FOLLOW) { throw new Fs_Exception("Unable to resolve realpath of '{$this->_path}': File is a broken symlink."); } return Fs::unknown($target); } else { $file = $this->realpathBestEffort($flags); if (!$file) { throw new Fs_Exception("Unable to resolve realpath of '{$this->_path}': Too many levels of symbolic links."); } return $file; } }