Go version
go version go1.26.4 darwin/arm64
Output of go env in your module/workspace:
What did you do?
os.MkdirAll was introduced in commit 66f5e89. Where both the fast path and slow path used Lstat.
To fix issue #1149, https://golang.org/cl/3564041 modified the fast path to use Stat instead of Lstat. However, the slow path was left unmodified and still using Lstat.
There is a potential race between os.MkdirAll and symlink to directory created by external actor. In the slow path of os.MkdirAll, when Mkdir returned EEXIST, Lstat on a symlink to directory, the check dir.IsDir() failed, and EEXIST is returned from MkdirAll.
Reproducer: https://go.dev/play/p/n8CPIyX3_Ty
I suggest that we should use Stat instead of Lstat in MkdirAll for consistency.
What did you see happen?
2009/11/10 23:00:00 mkdir foo: file exists
2009/11/10 23:00:00 mkdir foo: file exists
2009/11/10 23:00:00 mkdir foo: file exists
What did you expect to see?
empty log
Go version
go version go1.26.4 darwin/arm64
Output of
go envin your module/workspace:What did you do?
os.MkdirAllwas introduced in commit 66f5e89. Where both the fast path and slow path usedLstat.To fix issue #1149, https://golang.org/cl/3564041 modified the fast path to use
Statinstead ofLstat. However, the slow path was left unmodified and still usingLstat.There is a potential race between
os.MkdirAlland symlink to directory created by external actor. In the slow path ofos.MkdirAll, whenMkdirreturnedEEXIST,Lstaton a symlink to directory, the checkdir.IsDir()failed, andEEXISTis returned fromMkdirAll.Reproducer: https://go.dev/play/p/n8CPIyX3_Ty
I suggest that we should use
Statinstead ofLstatinMkdirAllfor consistency.What did you see happen?
What did you expect to see?
empty log