simplifying if-else chains to switches (#6208)

This commit is contained in:
Oleg Kovalov
2018-08-06 19:26:40 +02:00
committed by kannappanr
parent a82500f162
commit 37de2dbd3b
14 changed files with 120 additions and 138 deletions

View File

@@ -130,20 +130,23 @@ func renameAll(srcFilePath, dstFilePath string) (err error) {
}
if err = reliableRename(srcFilePath, dstFilePath); err != nil {
if isSysErrNotDir(err) {
switch {
case isSysErrNotDir(err):
return errFileAccessDenied
} else if isSysErrPathNotFound(err) {
case isSysErrPathNotFound(err):
// This is a special case should be handled only for
// windows, because windows API does not return "not a
// directory" error message. Handle this specifically here.
return errFileAccessDenied
} else if isSysErrCrossDevice(err) {
case isSysErrCrossDevice(err):
return fmt.Errorf("%s (%s)->(%s)", errCrossDeviceLink, srcFilePath, dstFilePath)
} else if os.IsNotExist(err) {
case os.IsNotExist(err):
return errFileNotFound
default:
return err
}
}
return err
return nil
}
// Reliably retries os.RenameAll if for some reason os.RenameAll returns