fix: skip access checks further for known buckets (#17934)

This commit is contained in:
Harshavardhana
2023-08-28 15:16:41 -07:00
committed by GitHub
parent 8a57b6bced
commit 7cafdc0512
3 changed files with 55 additions and 51 deletions

View File

@@ -38,8 +38,7 @@ func access(name string) error {
return nil
}
// Forked from Golang but chooses fast path upon os.Mkdir()
// error to avoid os.Lstat() call.
// Forked from Golang but chooses to avoid performing lookup
//
// osMkdirAll creates a directory named path,
// along with any necessary parents, and returns nil,
@@ -49,15 +48,6 @@ func access(name string) error {
// If path is already a directory, MkdirAll does nothing
// and returns nil.
func osMkdirAll(dirPath string, perm os.FileMode) error {
// Fast path: if we can tell whether path is a directory or file, stop with success or error.
err := Access(dirPath)
if err == nil {
return nil
}
if !osIsNotExist(err) {
return &os.PathError{Op: "mkdir", Path: dirPath, Err: err}
}
// Slow path: make sure parent exists and then call Mkdir for path.
i := len(dirPath)
for i > 0 && os.IsPathSeparator(dirPath[i-1]) { // Skip trailing path separator.
@@ -71,13 +61,13 @@ func osMkdirAll(dirPath string, perm os.FileMode) error {
if j > 1 {
// Create parent.
if err = osMkdirAll(dirPath[:j-1], perm); err != nil {
if err := osMkdirAll(dirPath[:j-1], perm); err != nil {
return err
}
}
// Parent now exists; invoke Mkdir and use its result.
if err = Mkdir(dirPath, perm); err != nil {
if err := Mkdir(dirPath, perm); err != nil {
if osIsExist(err) {
return nil
}