mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-30 22:39:58 +02:00
Also consider wrapped errors when checking for file IsNotExist errors
Fixes #10534
This commit is contained in:
@@ -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
|
||||
|
@@ -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
|
||||
}
|
||||
}
|
||||
|
@@ -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.
|
||||
|
@@ -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
|
||||
}
|
||||
|
@@ -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
|
||||
}
|
||||
|
Reference in New Issue
Block a user