Skip to content

Commit f431539

Browse files
tklausergopherbot
authored andcommitted
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 <[email protected]> Reviewed-by: Cherry Mui <[email protected]> Reviewed-by: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Auto-Submit: Tobias Klauser <[email protected]>
1 parent 7a21f79 commit f431539

File tree

5 files changed

+8
-42
lines changed

5 files changed

+8
-42
lines changed

src/cmd/go/internal/lockedfile/internal/filelock/filelock.go

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ package filelock
1010
import (
1111
"errors"
1212
"io/fs"
13-
"os"
1413
)
1514

1615
// A File provides the minimal set of methods required to lock an open file.
@@ -78,22 +77,7 @@ func (lt lockType) String() string {
7877

7978
// IsNotSupported returns a boolean indicating whether the error is known to
8079
// report that a function is not supported (possibly for a specific input).
81-
// It is satisfied by ErrNotSupported as well as some syscall errors.
80+
// It is satisfied by errors.ErrUnsupported as well as some syscall errors.
8281
func IsNotSupported(err error) bool {
83-
return isNotSupported(underlyingError(err))
84-
}
85-
86-
var ErrNotSupported = errors.New("operation not supported")
87-
88-
// underlyingError returns the underlying error for known os error types.
89-
func underlyingError(err error) error {
90-
switch err := err.(type) {
91-
case *fs.PathError:
92-
return err.Err
93-
case *os.LinkError:
94-
return err.Err
95-
case *os.SyscallError:
96-
return err.Err
97-
}
98-
return err
82+
return errors.Is(err, errors.ErrUnsupported)
9983
}

src/cmd/go/internal/lockedfile/internal/filelock/filelock_fcntl.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,3 @@ func setlkw(fd uintptr, lt lockType) error {
208208
}
209209
}
210210
}
211-
212-
func isNotSupported(err error) bool {
213-
return err == syscall.ENOSYS || err == syscall.ENOTSUP || err == syscall.EOPNOTSUPP || err == ErrNotSupported
214-
}

src/cmd/go/internal/lockedfile/internal/filelock/filelock_other.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66

77
package filelock
88

9-
import "io/fs"
9+
import (
10+
"errors"
11+
"io/fs"
12+
)
1013

1114
type lockType int8
1215

@@ -19,18 +22,14 @@ func lock(f File, lt lockType) error {
1922
return &fs.PathError{
2023
Op: lt.String(),
2124
Path: f.Name(),
22-
Err: ErrNotSupported,
25+
Err: errors.ErrUnsupported,
2326
}
2427
}
2528

2629
func unlock(f File) error {
2730
return &fs.PathError{
2831
Op: "Unlock",
2932
Path: f.Name(),
30-
Err: ErrNotSupported,
33+
Err: errors.ErrUnsupported,
3134
}
3235
}
33-
34-
func isNotSupported(err error) bool {
35-
return err == ErrNotSupported
36-
}

src/cmd/go/internal/lockedfile/internal/filelock/filelock_unix.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,3 @@ func lock(f File, lt lockType) (err error) {
3838
func unlock(f File) error {
3939
return lock(f, syscall.LOCK_UN)
4040
}
41-
42-
func isNotSupported(err error) bool {
43-
return err == syscall.ENOSYS || err == syscall.ENOTSUP || err == syscall.EOPNOTSUPP || err == ErrNotSupported
44-
}

src/cmd/go/internal/lockedfile/internal/filelock/filelock_windows.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,3 @@ func unlock(f File) error {
5555
}
5656
return nil
5757
}
58-
59-
func isNotSupported(err error) bool {
60-
switch err {
61-
case windows.ERROR_NOT_SUPPORTED, windows.ERROR_CALL_NOT_IMPLEMENTED, ErrNotSupported:
62-
return true
63-
default:
64-
return false
65-
}
66-
}

0 commit comments

Comments
 (0)