Skip to content

proposal: path/filepath: add Resolve, replacing EvalSymlinks #42201

@ianlancetaylor

Description

@ianlancetaylor

This is a new proposal to replace #37113, which was closed for non-technical reasons.

Paraphrasing @rsc, the proposal is a new function in the path/filepath package:

// Resolve returns the path name as an absolute path that does not contain any symlinks.
// Resolve calls Clean on the result.
func Resolve(path string) string

The expectation is that on Unix systems this will be essentially filepath.Abs(filepath.EvalSymlinks(path)) and on Windows it will essentially acquire a handle for the path and call GetFinalPathNameByHandle.

Objections to this approach (in my own words, apologies if I misrepresent some position):

  • We should instead make EvalSymlinks work better on Windows, such that filepath.Abs(filepath.EvalSymlinks(path)) will suffice on both Unix and Windows systems. This may involve changing EvalSymlinks to call GetFinalPathNameByHandle. However, any such change to EvalSymlinks on Windows may break programs that currently work on Windows.
  • It will be tempting to think that the proposed Resolve function will return a canonical path, but it will not, neither on Unix nor Windows (on Unix it will not be canonical due to hard links and multiple mounts). Therefore this function will mislead people into writing buggy programs. In particular, os.SameFile can return true for two different paths returned by Resolve.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions