os: Readlink docs should mention behavior for relative paths #57766
Labels
Documentation
Issues describing a change to documentation.
FrozenDueToAge
NeedsFix
The path to resolution is known, but the work has not been done.
Milestone
The documentation for
os.Readlink
currently says:While that is true, it also omits an important piece of information about “the destination”: if the symlink target is relative,
Readlink
will return that raw relative string directly. It will not do any additional work to make the path either absolute or relative to the current working directory. A reader who is not thinking very deeply about relative paths may well treat the result as a path, not a special symlink path blob.¹That is consistent with the Unix
readlink
system call, but then again, the Goos
package is different from the Unixsyscall
package for a reason. We should probably call this out more explicitly in the documentation, and perhaps provide an example of how to useReadlink
to correctly resolve a symlink to a filesystem path.¹ Per https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13,
“[T]he system shall prefix the remaining pathname, if any, with the contents of the symbolic link …. If the resulting pathname does not begin with a <slash>, the predecessor of the first filename of the pathname is taken to be the directory containing the symbolic link.”
The text was updated successfully, but these errors were encountered: