diff options
author | Alessio Caiazza <376774-nolith@users.noreply.gitlab.com> | 2021-09-30 11:09:01 +0300 |
---|---|---|
committer | Alessio Caiazza <376774-nolith@users.noreply.gitlab.com> | 2021-09-30 11:09:01 +0300 |
commit | dee99f0074625c3b1dfe07aa477e159344f89ac2 (patch) | |
tree | 7d2632aa28e9b7a6ca87a369f9a0815fc22347fb /internal/vfs | |
parent | 8bf69d0b47e766424634a52a27428cb26a0376c4 (diff) | |
parent | 5ba8177bf2acbd44676065185797ca69a6ef56bb (diff) |
Merge branch 'fix/os-errors' into 'master'
refactor: avoid os.Is.. in favor of errors.Is
See merge request gitlab-org/gitlab-pages!567
Diffstat (limited to 'internal/vfs')
-rw-r--r-- | internal/vfs/local/root_test.go | 8 | ||||
-rw-r--r-- | internal/vfs/local/vfs.go | 11 |
2 files changed, 11 insertions, 8 deletions
diff --git a/internal/vfs/local/root_test.go b/internal/vfs/local/root_test.go index 1cf505bf..a835bae3 100644 --- a/internal/vfs/local/root_test.go +++ b/internal/vfs/local/root_test.go @@ -2,7 +2,9 @@ package local import ( "context" + "errors" "io" + "io/fs" "os" "path/filepath" "testing" @@ -95,7 +97,7 @@ func TestReadlink(t *testing.T) { target, err := root.Readlink(ctx, test.path) if test.expectedIsNotExist { - require.Equal(t, test.expectedIsNotExist, os.IsNotExist(err), "IsNotExist") + require.Equal(t, test.expectedIsNotExist, errors.Is(err, fs.ErrNotExist), "IsNotExist") return } @@ -211,7 +213,7 @@ func TestLstat(t *testing.T) { fi, err := root.Lstat(ctx, test.path) if test.expectedIsNotExist { - require.Equal(t, test.expectedIsNotExist, os.IsNotExist(err), "IsNotExist") + require.Equal(t, test.expectedIsNotExist, errors.Is(err, fs.ErrNotExist), "IsNotExist") return } @@ -271,7 +273,7 @@ func TestOpen(t *testing.T) { } if test.expectedIsNotExist { - require.Equal(t, test.expectedIsNotExist, os.IsNotExist(err), "IsNotExist") + require.Equal(t, test.expectedIsNotExist, errors.Is(err, fs.ErrNotExist), "IsNotExist") return } diff --git a/internal/vfs/local/vfs.go b/internal/vfs/local/vfs.go index ea54e8e8..5cca94fd 100644 --- a/internal/vfs/local/vfs.go +++ b/internal/vfs/local/vfs.go @@ -3,6 +3,7 @@ package local import ( "context" "errors" + "io/fs" "os" "path/filepath" @@ -14,21 +15,21 @@ var errNotDirectory = errors.New("path needs to be a directory") type VFS struct{} -func (fs VFS) Root(ctx context.Context, path string) (vfs.Root, error) { +func (localFs VFS) Root(ctx context.Context, path string) (vfs.Root, error) { rootPath, err := filepath.Abs(path) if err != nil { return nil, err } rootPath, err = filepath.EvalSymlinks(rootPath) - if os.IsNotExist(err) { + if errors.Is(err, fs.ErrNotExist) { return nil, &vfs.ErrNotExist{Inner: err} } else if err != nil { return nil, err } fi, err := os.Lstat(rootPath) - if os.IsNotExist(err) { + if errors.Is(err, fs.ErrNotExist) { return nil, &vfs.ErrNotExist{Inner: err} } else if err != nil { return nil, err @@ -41,11 +42,11 @@ func (fs VFS) Root(ctx context.Context, path string) (vfs.Root, error) { return &Root{rootPath: rootPath}, nil } -func (fs *VFS) Name() string { +func (localFs *VFS) Name() string { return "local" } -func (fs *VFS) Reconfigure(*config.Config) error { +func (localFs *VFS) Reconfigure(*config.Config) error { // noop return nil } |