diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2022-12-14 12:20:13 +0100 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2022-12-14 13:51:06 +0100 |
commit | ad2059878a8d6ace9669ccc5ff0a8d4e5811ad37 (patch) | |
tree | 34d88705ab22e5b54949a6ce48e028b1fc2ab7e6 /hugolib | |
parent | 87e898a17a52b5338bc9d554dd12b99a54aa2431 (diff) |
Also consider wrapped errors when checking for file IsNotExist errors
Fixes #10534
Diffstat (limited to 'hugolib')
-rw-r--r-- | hugolib/codeowners.go | 4 | ||||
-rw-r--r-- | hugolib/filesystems/basefs.go | 7 | ||||
-rw-r--r-- | hugolib/page.go | 3 | ||||
-rw-r--r-- | hugolib/pages_capture.go | 4 | ||||
-rw-r--r-- | hugolib/site.go | 20 |
5 files changed, 19 insertions, 19 deletions
diff --git a/hugolib/codeowners.go b/hugolib/codeowners.go index 17e956981..162ee16ae 100644 --- a/hugolib/codeowners.go +++ b/hugolib/codeowners.go @@ -15,9 +15,9 @@ package hugolib import ( "io" - "os" "path" + "github.com/gohugoio/hugo/common/herrors" "github.com/gohugoio/hugo/config" "github.com/gohugoio/hugo/resources/page" "github.com/hairyhenderson/go-codeowners" @@ -32,7 +32,7 @@ func findCodeOwnersFile(dir string) (io.Reader, error) { _, err := afs.Stat(f) if err != nil { - if os.IsNotExist(err) { + if herrors.IsNotExist(err) { continue } return nil, err diff --git a/hugolib/filesystems/basefs.go b/hugolib/filesystems/basefs.go index e0fed6f3e..5a98be47e 100644 --- a/hugolib/filesystems/basefs.go +++ b/hugolib/filesystems/basefs.go @@ -28,6 +28,7 @@ import ( "github.com/gohugoio/hugo/htesting" "github.com/gohugoio/hugo/hugofs/glob" + "github.com/gohugoio/hugo/common/herrors" "github.com/gohugoio/hugo/common/types" "github.com/gohugoio/hugo/common/loggers" @@ -295,15 +296,15 @@ func (s SourceFilesystems) StaticFs(lang string) afero.Fs { // StatResource looks for a resource in these filesystems in order: static, assets and finally content. // If found in any of them, it returns FileInfo and the relevant filesystem. -// Any non os.IsNotExist error will be returned. -// An os.IsNotExist error wil be returned only if all filesystems return such an error. +// Any non herrors.IsNotExist error will be returned. +// An herrors.IsNotExist error wil be returned only if all filesystems return such an error. // Note that if we only wanted to find the file, we could create a composite Afero fs, // but we also need to know which filesystem root it lives in. func (s SourceFilesystems) StatResource(lang, filename string) (fi os.FileInfo, fs afero.Fs, err error) { for _, fsToCheck := range []afero.Fs{s.StaticFs(lang), s.Assets.Fs, s.Content.Fs} { fs = fsToCheck fi, err = fs.Stat(filename) - if err == nil || !os.IsNotExist(err) { + if err == nil || !herrors.IsNotExist(err) { return } } diff --git a/hugolib/page.go b/hugolib/page.go index ec7b82277..5acfbc677 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -16,7 +16,6 @@ package hugolib import ( "bytes" "fmt" - "os" "path" "path/filepath" "sort" @@ -489,7 +488,7 @@ func (p *pageState) renderResources() (err error) { } if err := src.Publish(); err != nil { - if os.IsNotExist(err) { + if herrors.IsNotExist(err) { // The resource has been deleted from the file system. // This should be extremely rare, but can happen on live reload in server // mode when the same resource is member of different page bundles. diff --git a/hugolib/pages_capture.go b/hugolib/pages_capture.go index da7515fc2..b72ae7e85 100644 --- a/hugolib/pages_capture.go +++ b/hugolib/pages_capture.go @@ -16,11 +16,11 @@ package hugolib import ( "context" "fmt" - "os" pth "path" "path/filepath" "reflect" + "github.com/gohugoio/hugo/common/herrors" "github.com/gohugoio/hugo/common/maps" "github.com/gohugoio/hugo/parser/pageparser" @@ -318,7 +318,7 @@ func (c *pagesCollector) cloneFileInfo(fi hugofs.FileMetaInfo) hugofs.FileMetaIn func (c *pagesCollector) collectDir(dirname string, partial bool, inFilter func(fim hugofs.FileMetaInfo) bool) error { fi, err := c.fs.Stat(dirname) if err != nil { - if os.IsNotExist(err) { + if herrors.IsNotExist(err) { // May have been deleted. return nil } diff --git a/hugolib/site.go b/hugolib/site.go index cbfc4d836..8fb39a1ea 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -20,7 +20,6 @@ import ( "log" "mime" "net/url" - "os" "path" "path/filepath" "regexp" @@ -30,6 +29,7 @@ import ( "strings" "time" + "github.com/gohugoio/hugo/common/herrors" "github.com/gohugoio/hugo/common/htime" "github.com/gohugoio/hugo/common/hugio" "github.com/gohugoio/hugo/common/types" @@ -90,16 +90,16 @@ import ( // // 1. A list of Files is parsed and then converted into Pages. // -// 2. Pages contain sections (based on the file they were generated from), -// aliases and slugs (included in a pages frontmatter) which are the -// various targets that will get generated. There will be canonical -// listing. The canonical path can be overruled based on a pattern. +// 2. Pages contain sections (based on the file they were generated from), +// aliases and slugs (included in a pages frontmatter) which are the +// various targets that will get generated. There will be canonical +// listing. The canonical path can be overruled based on a pattern. // -// 3. Taxonomies are created via configuration and will present some aspect of -// the final page and typically a perm url. +// 3. Taxonomies are created via configuration and will present some aspect of +// the final page and typically a perm url. // -// 4. All Pages are passed through a template based on their desired -// layout based on numerous different elements. +// 4. All Pages are passed through a template based on their desired +// layout based on numerous different elements. // // 5. The entire collection of files is written to disk. type Site struct { @@ -954,7 +954,7 @@ func (s *Site) filterFileEvents(events []fsnotify.Event) []fsnotify.Event { // Throw away any directories isRegular, err := s.SourceSpec.IsRegularSourceFile(ev.Name) - if err != nil && os.IsNotExist(err) && (ev.Op&fsnotify.Remove == fsnotify.Remove || ev.Op&fsnotify.Rename == fsnotify.Rename) { + if err != nil && herrors.IsNotExist(err) && (ev.Op&fsnotify.Remove == fsnotify.Remove || ev.Op&fsnotify.Rename == fsnotify.Rename) { // Force keep of event isRegular = true } |