summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Frei <freisim93@gmail.com>2022-12-21 23:42:22 +0100
committerGitHub <noreply@github.com>2022-12-21 23:42:22 +0100
commit634a3d0e3be4a706dfb58253da534e396cac714e (patch)
treea983e934bf4a8ed94f1d1c9c992700e8b7899ef7
parent09f4d865ae8fb47bc90d54b03cc2f2e01f70dc8d (diff)
lib/fs: Use io/fs errors as recommended in std lib (#8726)
-rw-r--r--lib/fs/filesystem.go20
-rw-r--r--lib/ignore/ignore_test.go4
2 files changed, 15 insertions, 9 deletions
diff --git a/lib/fs/filesystem.go b/lib/fs/filesystem.go
index 219788fb72..57fce0d0a6 100644
--- a/lib/fs/filesystem.go
+++ b/lib/fs/filesystem.go
@@ -10,6 +10,7 @@ import (
"context"
"errors"
"io"
+ "io/fs"
"os"
"path/filepath"
"strings"
@@ -192,20 +193,25 @@ const OptWriteOnly = os.O_WRONLY
// as an error by any function.
var SkipDir = filepath.SkipDir
-// IsExist is the equivalent of os.IsExist
-var IsExist = os.IsExist
+func IsExist(err error) bool {
+ return errors.Is(err, ErrExist)
+}
-// IsExist is the equivalent of os.ErrExist
-var ErrExist = os.ErrExist
+// ErrExist is the equivalent of os.ErrExist
+var ErrExist = fs.ErrExist
// 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
-var ErrNotExist = os.ErrNotExist
+var ErrNotExist = fs.ErrNotExist
// 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
var IsPathSeparator = os.IsPathSeparator
diff --git a/lib/ignore/ignore_test.go b/lib/ignore/ignore_test.go
index 32bfa4a781..231b926e93 100644
--- a/lib/ignore/ignore_test.go
+++ b/lib/ignore/ignore_test.go
@@ -996,8 +996,8 @@ func TestIssue4901(t *testing.T) {
if err == nil {
t.Fatal("expected an error")
}
- if fs.IsNotExist(err) {
- t.Fatal("unexpected error type")
+ if err == fs.ErrNotExist {
+ t.Fatalf("unexpected error type: %T", err)
}
if !IsParseError(err) {
t.Fatal("failure to load included file should be a parse error")