diff options
| author | Bryan C. Mills <bcmills@google.com> | 2023-12-04 15:32:01 -0500 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2023-12-07 17:27:54 +0000 |
| commit | bb34112d4df7b5dfd12fc83b8d1305631a7b8708 (patch) | |
| tree | df6e817d1136455672b11f491019bd728459d260 /src/os/file.go | |
| parent | 4601857c1c7f5f72c75366763ff71fdcbe5f84be (diff) | |
| download | go-bb34112d4df7b5dfd12fc83b8d1305631a7b8708.tar.xz | |
os: document Readlink behavior for relative links
Also provide a runnable example to illustrate that behavior.
This should help users to avoid the common mistake of expecting
os.Readlink to return an absolute path.
Fixes #57766.
Change-Id: I8f60aa111ebda0cae985758615019aaf26d5cb41
Reviewed-on: https://go-review.googlesource.com/c/go/+/546995
Auto-Submit: Bryan Mills <bcmills@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Carlos Amedee <carlos@golang.org>
Reviewed-by: Rob Pike <r@golang.org>
Diffstat (limited to 'src/os/file.go')
| -rw-r--r-- | src/os/file.go | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/src/os/file.go b/src/os/file.go index 6fd0550eeb..090ffba4dc 100644 --- a/src/os/file.go +++ b/src/os/file.go @@ -392,6 +392,15 @@ func Rename(oldpath, newpath string) error { return rename(oldpath, newpath) } +// Readlink returns the destination of the named symbolic link. +// If there is an error, it will be of type *PathError. +// +// If the link destination is relative, Readlink returns the relative path +// without resolving it to an absolute one. +func Readlink(name string) (string, error) { + return readlink(name) +} + // Many functions in package syscall return a count of -1 instead of 0. // Using fixCount(call()) instead of call() corrects the count. func fixCount(n int, err error) (int, error) { |
