fix: unwrapping issues with os.Is* functions (#10949)

reduces  3 stat calls, reducing the
overall startup time significantly.
This commit is contained in:
Harshavardhana
2020-11-23 08:36:49 -08:00
committed by GitHub
parent 39f3d5493b
commit df93102235
22 changed files with 158 additions and 166 deletions

View File

@@ -103,7 +103,7 @@ func reliableMkdirAll(dirPath string, mode os.FileMode) (err error) {
// Creates all the parent directories, with mode 0777 mkdir honors system umask.
if err = os.MkdirAll(dirPath, mode); err != nil {
// Retry only for the first retryable error.
if os.IsNotExist(err) && i == 0 {
if osIsNotExist(err) && i == 0 {
i++
continue
}
@@ -131,8 +131,8 @@ func renameAll(srcFilePath, dstFilePath string) (err error) {
if err = reliableRename(srcFilePath, dstFilePath); err != nil {
switch {
case isSysErrNotDir(err) && !os.IsNotExist(err):
// Windows can have both isSysErrNotDir(err) and os.IsNotExist(err) returning
case isSysErrNotDir(err) && !osIsNotExist(err):
// Windows can have both isSysErrNotDir(err) and osIsNotExist(err) returning
// true if the source file path contains an inexistant directory. In that case,
// we want to return errFileNotFound instead, which will honored in subsequent
// switch cases
@@ -144,9 +144,9 @@ func renameAll(srcFilePath, dstFilePath string) (err error) {
return errFileAccessDenied
case isSysErrCrossDevice(err):
return fmt.Errorf("%w (%s)->(%s)", errCrossDeviceLink, srcFilePath, dstFilePath)
case os.IsNotExist(err):
case osIsNotExist(err):
return errFileNotFound
case os.IsExist(err):
case osIsExist(err):
// This is returned only when destination is a directory and we
// are attempting a rename from file to directory.
return errIsNotRegular
@@ -168,7 +168,7 @@ func reliableRename(srcFilePath, dstFilePath string) (err error) {
// After a successful parent directory create attempt a renameAll.
if err = os.Rename(srcFilePath, dstFilePath); err != nil {
// Retry only for the first retryable error.
if os.IsNotExist(err) && i == 0 {
if osIsNotExist(err) && i == 0 {
i++
continue
}