import (
"errors"
"io/fs"
- "os"
)
// A File provides the minimal set of methods required to lock an open file.
// 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)
}
package filelock
-import "io/fs"
+import (
+ "errors"
+ "io/fs"
+)
type lockType int8
return &fs.PathError{
Op: lt.String(),
Path: f.Name(),
- Err: ErrNotSupported,
+ Err: errors.ErrUnsupported,
}
}
return &fs.PathError{
Op: "Unlock",
Path: f.Name(),
- Err: ErrNotSupported,
+ Err: errors.ErrUnsupported,
}
}
-
-func isNotSupported(err error) bool {
- return err == ErrNotSupported
-}
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
-}