Also consider wrapped errors when checking for file IsNotExist errors

Fixes #10534
This commit is contained in:
Bjørn Erik Pedersen
2022-12-14 12:20:13 +01:00
parent 87e898a17a
commit ad2059878a
21 changed files with 110 additions and 48 deletions

View File

@@ -19,6 +19,7 @@ import (
"path/filepath"
"strings"
"github.com/gohugoio/hugo/common/herrors"
"github.com/spf13/afero"
)
@@ -224,7 +225,7 @@ func (l *baseFileDecoratorFile) Readdir(c int) (ofi []os.FileInfo, err error) {
// We need to resolve any symlink info.
fi, _, err := lstatIfPossible(l.fs.Fs, filename)
if err != nil {
if os.IsNotExist(err) {
if herrors.IsNotExist(err) {
continue
}
return nil, err

View File

@@ -19,6 +19,7 @@ import (
"path/filepath"
"strings"
"github.com/gohugoio/hugo/common/herrors"
"github.com/gohugoio/hugo/hugofs/files"
radix "github.com/armon/go-radix"
@@ -45,7 +46,7 @@ func NewRootMappingFs(fs afero.Fs, rms ...RootMapping) (*RootMappingFs, error) {
fi, err := fs.Stat(rm.To)
if err != nil {
if os.IsNotExist(err) {
if herrors.IsNotExist(err) {
continue
}
return nil, err

View File

@@ -21,6 +21,7 @@ import (
"errors"
"github.com/gohugoio/hugo/common/herrors"
"github.com/spf13/afero"
)
@@ -161,7 +162,7 @@ func (fs *SliceFs) pickFirst(name string) (os.FileInfo, int, error) {
return fi, i, nil
}
if !os.IsNotExist(err) {
if !herrors.IsNotExist(err) {
// Real error
return nil, -1, err
}
@@ -175,7 +176,7 @@ func (fs *SliceFs) readDirs(name string, startIdx, count int) ([]os.FileInfo, er
collect := func(lfs *FileMeta) ([]os.FileInfo, error) {
d, err := lfs.Fs.Open(name)
if err != nil {
if !os.IsNotExist(err) {
if !herrors.IsNotExist(err) {
return nil, err
}
return nil, nil

View File

@@ -20,6 +20,7 @@ import (
"sort"
"strings"
"github.com/gohugoio/hugo/common/herrors"
"github.com/gohugoio/hugo/common/loggers"
"errors"
@@ -118,7 +119,7 @@ func (w *Walkway) Walk() error {
} else {
info, _, err := lstatIfPossible(w.fs, w.root)
if err != nil {
if os.IsNotExist(err) {
if herrors.IsNotExist(err) {
return nil
}
@@ -154,7 +155,7 @@ func (w *Walkway) checkErr(filename string, err error) bool {
return true
}
if os.IsNotExist(err) {
if herrors.IsNotExist(err) {
// The file may be removed in process.
// This may be a ERROR situation, but it is not possible
// to determine as a general case.