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?
- Use
os.Open to open an os.File for a relative directory.
- Call
os.Chdir to change the current working directory.
- Call
ReadDir or Readdir on the File opened in step (1).
- 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.
What version of Go are you using (
go version)?Does this issue reproduce with the latest release?
Yes.
What did you do?
os.Opento open anos.Filefor a relative directory.os.Chdirto change the current working directory.ReadDirorReaddiron theFileopened in step (1).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 theFile.What did you see instead?
On Linux:
ReadDirproduces the directory contents relative to the current directory instead of the opened file.ReaddirproducesDirEntrycontents relative to the opened file, but calling theInfomethod on those entries attempts to open the wrong paths (compare os: File.Stat on Windows doesn't use file handle for directories #52747).It isn't clear to me how this can be fixed in general — it is possible to use
fdopendirto read the correct entries while the parent file is still open, but if the parent file is closed before theInfomethod is called on the returnedDirEntry, I don't see a standard API to reliably open the correct path.