1
0
mirror of https://github.com/golang/go synced 2024-09-29 15:24:28 -06:00

cmd/go/internal/lockedfile/internal/filelock: use errors.ErrUnsupported

All platform specific errors are now covered by errors.ErrUnsupported.

Updates #41198

Change-Id: Ia9c0cad7c493305835bd5a1f349446cec409f686
Reviewed-on: https://go-review.googlesource.com/c/go/+/476917
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Tobias Klauser <tobias.klauser@gmail.com>
This commit is contained in:
Tobias Klauser 2023-03-16 22:05:06 +01:00 committed by Gopher Robot
parent 7a21f799a5
commit f4315391d7
5 changed files with 8 additions and 42 deletions

View File

@ -10,7 +10,6 @@ package filelock
import (
"errors"
"io/fs"
"os"
)
// A File provides the minimal set of methods required to lock an open file.
@ -78,22 +77,7 @@ func (lt lockType) String() string {
// IsNotSupported returns a boolean indicating whether the error is known to
// report that a function is not supported (possibly for a specific input).
// It is satisfied by ErrNotSupported as well as some syscall errors.
// It is satisfied by errors.ErrUnsupported as well as some syscall errors.
func IsNotSupported(err error) bool {
return isNotSupported(underlyingError(err))
}
var ErrNotSupported = errors.New("operation not supported")
// underlyingError returns the underlying error for known os error types.
func underlyingError(err error) error {
switch err := err.(type) {
case *fs.PathError:
return err.Err
case *os.LinkError:
return err.Err
case *os.SyscallError:
return err.Err
}
return err
return errors.Is(err, errors.ErrUnsupported)
}

View File

@ -208,7 +208,3 @@ func setlkw(fd uintptr, lt lockType) error {
}
}
}
func isNotSupported(err error) bool {
return err == syscall.ENOSYS || err == syscall.ENOTSUP || err == syscall.EOPNOTSUPP || err == ErrNotSupported
}

View File

@ -6,7 +6,10 @@
package filelock
import "io/fs"
import (
"errors"
"io/fs"
)
type lockType int8
@ -19,7 +22,7 @@ func lock(f File, lt lockType) error {
return &fs.PathError{
Op: lt.String(),
Path: f.Name(),
Err: ErrNotSupported,
Err: errors.ErrUnsupported,
}
}
@ -27,10 +30,6 @@ func unlock(f File) error {
return &fs.PathError{
Op: "Unlock",
Path: f.Name(),
Err: ErrNotSupported,
Err: errors.ErrUnsupported,
}
}
func isNotSupported(err error) bool {
return err == ErrNotSupported
}

View File

@ -38,7 +38,3 @@ func lock(f File, lt lockType) (err error) {
func unlock(f File) error {
return lock(f, syscall.LOCK_UN)
}
func isNotSupported(err error) bool {
return err == syscall.ENOSYS || err == syscall.ENOTSUP || err == syscall.EOPNOTSUPP || err == ErrNotSupported
}

View File

@ -55,12 +55,3 @@ func unlock(f File) error {
}
return nil
}
func isNotSupported(err error) bool {
switch err {
case windows.ERROR_NOT_SUPPORTED, windows.ERROR_CALL_NOT_IMPLEMENTED, ErrNotSupported:
return true
default:
return false
}
}