mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-22 10:58:57 +00:00
lib/fs: Use io/fs errors as recommended in std lib (#8726)
This commit is contained in:
parent
09f4d865ae
commit
634a3d0e3b
@ -10,6 +10,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@ -192,20 +193,25 @@ const OptWriteOnly = os.O_WRONLY
|
|||||||
// as an error by any function.
|
// as an error by any function.
|
||||||
var SkipDir = filepath.SkipDir
|
var SkipDir = filepath.SkipDir
|
||||||
|
|
||||||
// IsExist is the equivalent of os.IsExist
|
func IsExist(err error) bool {
|
||||||
var IsExist = os.IsExist
|
return errors.Is(err, ErrExist)
|
||||||
|
}
|
||||||
|
|
||||||
// IsExist is the equivalent of os.ErrExist
|
// ErrExist is the equivalent of os.ErrExist
|
||||||
var ErrExist = os.ErrExist
|
var ErrExist = fs.ErrExist
|
||||||
|
|
||||||
// IsNotExist is the equivalent of os.IsNotExist
|
// IsNotExist is the equivalent of os.IsNotExist
|
||||||
var IsNotExist = os.IsNotExist
|
func IsNotExist(err error) bool {
|
||||||
|
return errors.Is(err, ErrNotExist)
|
||||||
|
}
|
||||||
|
|
||||||
// ErrNotExist is the equivalent of os.ErrNotExist
|
// ErrNotExist is the equivalent of os.ErrNotExist
|
||||||
var ErrNotExist = os.ErrNotExist
|
var ErrNotExist = fs.ErrNotExist
|
||||||
|
|
||||||
// IsPermission is the equivalent of os.IsPermission
|
// IsPermission is the equivalent of os.IsPermission
|
||||||
var IsPermission = os.IsPermission
|
func IsPermission(err error) bool {
|
||||||
|
return errors.Is(err, fs.ErrPermission)
|
||||||
|
}
|
||||||
|
|
||||||
// IsPathSeparator is the equivalent of os.IsPathSeparator
|
// IsPathSeparator is the equivalent of os.IsPathSeparator
|
||||||
var IsPathSeparator = os.IsPathSeparator
|
var IsPathSeparator = os.IsPathSeparator
|
||||||
|
@ -996,8 +996,8 @@ func TestIssue4901(t *testing.T) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatal("expected an error")
|
t.Fatal("expected an error")
|
||||||
}
|
}
|
||||||
if fs.IsNotExist(err) {
|
if err == fs.ErrNotExist {
|
||||||
t.Fatal("unexpected error type")
|
t.Fatalf("unexpected error type: %T", err)
|
||||||
}
|
}
|
||||||
if !IsParseError(err) {
|
if !IsParseError(err) {
|
||||||
t.Fatal("failure to load included file should be a parse error")
|
t.Fatal("failure to load included file should be a parse error")
|
||||||
|
Loading…
Reference in New Issue
Block a user