use Access() instead of Lstat() for frequent use (#11911)

using Lstat() is causing tiny memory allocations,
that are usually wasted and never used, instead
we can simply uses Access() call that does 0
memory allocations.
This commit is contained in:
Harshavardhana
2021-03-29 08:07:23 -07:00
committed by GitHub
parent 7c5b35d20f
commit d93c6cb9c7
9 changed files with 101 additions and 67 deletions
+9
View File
@@ -25,8 +25,17 @@ import (
"sync"
"syscall"
"unsafe"
"golang.org/x/sys/unix"
)
func access(name string) error {
if err := unix.Access(name, unix.R_OK|unix.W_OK); err != nil {
return &os.PathError{Op: "lstat", Path: name, Err: err}
}
return nil
}
// The buffer must be at least a block long.
// refer https://github.com/golang/go/issues/24015
const blockSize = 8 << 10 // 8192