Skip to content

os: Root documentation does not mention relative paths #79051

Description

@AlekSi

Go version

go version go1.26.2 darwin/arm64

Output of go env in your module/workspace:

Not relevant.

What did you do?

  1. Read https://pkg.go.dev/os#Root documentation.
  2. Run https://go.dev/play/p/q9mW-k5sg-X
  3. Got confused.

What did you see happen?

2009/11/10 23:00:00 root    /tmp/860037159
2009/11/10 23:00:00 mkdirat /tmp/860037159/123: path escapes from parent

What did you expect to see?

Root documentation says (relevant bits):

Root may be used to only access files within a single directory tree.

Methods on Root can only access files and directories beneath a root directory. If any component of a file name passed to a method of Root references a location outside the root, the method returns an error. File names may reference the directory itself (.).

Methods on Root will follow symbolic links, but symbolic links may not reference a location outside the root. Symbolic links must not be absolute.

/tmp/860037159 and /tmp/860037159/123 are within a single directory tree. /tmp/860037159/123 is beneath a root directory /tmp/860037159. There are no symbolic links. So what I do is correct according to the documentation.

I guess what documentation fails to mention is that the arguments to root methods must be relative paths, even if there are no symbolic links. If the current behavior is intentional, it should be documented; "within a single directory tree" and " beneath a root directory" are not enough.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.NeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions