Skip to content

Commit 8768395

Browse files
authored
Merge pull request #1029 from andrewjamesbrown/refactor/modernize-os-isnotexist
refactor(execd): modernize os.IsNotExist to errors.Is(err, fs.ErrNotExist)
2 parents ec77bfc + 9503ac2 commit 8768395

5 files changed

Lines changed: 12 additions & 8 deletions

File tree

components/execd/pkg/runtime/workingdir.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
package runtime
1616

1717
import (
18+
"errors"
1819
"fmt"
20+
"io/fs"
1921
"os"
2022

2123
"github.com/alibaba/opensandbox/execd/pkg/util/pathutil"
@@ -31,8 +33,8 @@ func ValidateWorkingDir(cwd string) error {
3133
}
3234
fi, err := os.Stat(resolvedCwd)
3335
if err != nil {
34-
if os.IsNotExist(err) {
35-
return fmt.Errorf("working directory does not exist: %s", cwd)
36+
if errors.Is(err, fs.ErrNotExist) {
37+
return fmt.Errorf("working directory does not exist: %s: %w", cwd, err)
3638
}
3739
return fmt.Errorf("cannot access working directory %q: %w", cwd, err)
3840
}

components/execd/pkg/web/controller/filesystem.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ func (c *FilesystemController) SearchFiles() {
374374

375375
files := make([]model.FileInfo, 0, 16)
376376
err = filepath.Walk(path, func(filePath string, info os.FileInfo, err error) error {
377-
if os.IsNotExist(err) {
377+
if errors.Is(err, fs.ErrNotExist) {
378378
return nil
379379
}
380380
if err != nil {

components/execd/pkg/web/controller/filesystem_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ func (c *FilesystemController) SearchFiles() {
374374

375375
files := make([]model.FileInfo, 0, 16)
376376
err = filepath.Walk(path, func(filePath string, info os.FileInfo, err error) error {
377-
if os.IsNotExist(err) {
377+
if errors.Is(err, fs.ErrNotExist) {
378378
return nil
379379
}
380380
if err != nil {

components/execd/pkg/web/controller/utils.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package controller
2020
import (
2121
"errors"
2222
"fmt"
23+
"io/fs"
2324
"os"
2425
"os/user"
2526
"path/filepath"
@@ -40,7 +41,7 @@ func DeleteFile(filePath string) error {
4041

4142
fileInfo, err := os.Stat(absPath)
4243
if err != nil {
43-
if os.IsNotExist(err) {
44+
if errors.Is(err, fs.ErrNotExist) {
4445
return nil
4546
}
4647
return err
@@ -213,7 +214,7 @@ func GetFileInfo(filePath string) (model.FileInfo, error) {
213214

214215
fileInfo, err := os.Lstat(absPath)
215216
if err != nil {
216-
if os.IsNotExist(err) {
217+
if errors.Is(err, fs.ErrNotExist) {
217218
return model.FileInfo{}, fmt.Errorf("file not found: %s: %w", filePath, err)
218219
}
219220
return model.FileInfo{}, fmt.Errorf("error accessing file %s: %w", filePath, err)

components/execd/pkg/web/controller/utils_windows.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package controller
2020
import (
2121
"errors"
2222
"fmt"
23+
"io/fs"
2324
"os"
2425
"path/filepath"
2526
"strconv"
@@ -39,7 +40,7 @@ func DeleteFile(filePath string) error {
3940

4041
fileInfo, err := os.Stat(absPath)
4142
if err != nil {
42-
if os.IsNotExist(err) {
43+
if errors.Is(err, fs.ErrNotExist) {
4344
return nil
4445
}
4546
return err
@@ -173,7 +174,7 @@ func GetFileInfo(filePath string) (model.FileInfo, error) {
173174

174175
fileInfo, err := os.Lstat(absPath)
175176
if err != nil {
176-
if os.IsNotExist(err) {
177+
if errors.Is(err, fs.ErrNotExist) {
177178
return model.FileInfo{}, fmt.Errorf("file not found: %s: %w", filePath, err)
178179
}
179180
return model.FileInfo{}, fmt.Errorf("error accessing file %s: %w", filePath, err)

0 commit comments

Comments
 (0)