os: ReadDir
and Readdir
on a File
opened from a relative path try the wrong paths for FileInfo
structs
#62028
Labels
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What did you do?
os.Open
to open anos.File
for a relative directory.os.Chdir
to change the current working directory.ReadDir
orReaddir
on theFile
opened in step (1).FileInfo
s.(https://go.dev/play/p/bLLMvUJGu_u?v=gotip)
What did you expect to see?
The
FileInfo
s should correspond to the directory entries relative to theFile
.What did you see instead?
On Linux:
ReadDir
produces the directory contents relative to the current directory instead of the opened file.Readdir
producesDirEntry
contents relative to the opened file, but calling theInfo
method 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
fdopendir
to read the correct entries while the parent file is still open, but if the parent file is closed before theInfo
method is called on the returnedDirEntry
, I don't see a standard API to reliably open the correct path.The text was updated successfully, but these errors were encountered: