Skip to content

os: ReadDir and Readdir on a File opened from a relative path try the wrong paths for FileInfo structs #62028

@bcmills

Description

@bcmills

What version of Go are you using (go version)?

$ go version
devel go1.22-98bacdeafe Mon Aug 14 12:51:16 2023 +0000

Does this issue reproduce with the latest release?

Yes.

What did you do?

  1. Use os.Open to open an os.File for a relative directory.
  2. Call os.Chdir to change the current working directory.
  3. Call ReadDir or Readdir on the File opened in step (1).
  4. Inspect the resulting FileInfos.

(https://go.dev/play/p/bLLMvUJGu_u?v=gotip)

What did you expect to see?

The FileInfos should correspond to the directory entries relative to the File.

What did you see instead?

On Linux:

It isn't clear to me how this can be fixed in general — it is possible to use fdopendir to read the correct entries while the parent file is still open, but if the parent file is closed before the Info method is called on the returned DirEntry, I don't see a standard API to reliably open the correct path.

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions