dirfs: use os.ReadLink instead of syscall variant (#1092)

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
This commit is contained in:
Takeshi Yoneda
2023-02-01 21:31:25 -08:00
committed by GitHub
parent ebc2d97c2a
commit 7955b1399d

View File

@@ -64,12 +64,20 @@ func (d *dirFS) Rename(from, to string) error {
// Readlink implements FS.Readlink
func (d *dirFS) Readlink(path string, buf []byte) (n int, err error) {
n, err = syscall.Readlink(d.join(path), buf)
// Note: do not use syscall.Readlink as that causes race on Windows.
// In any case, syscall.Readlink does almost the same logic as os.Readlink.
res, err := os.Readlink(d.join(path))
if err != nil {
err = unwrapOSError(err)
return
}
// We need to copy here, but syscall.Readlink does copy internally, so the cost is the same.
copy(buf, res)
n = len(res)
if n > len(buf) {
n = len(buf)
}
platform.SanitizeSeparator(buf[:n])
return
}