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

@@ -579,7 +579,7 @@ func (c *commandeer) serverBuild() error {
func (c *commandeer) copyStatic() (map[string]uint64, error) {
m, err := c.doWithPublishDirs(c.copyStaticTo)
if err == nil || os.IsNotExist(err) {
if err == nil || herrors.IsNotExist(err) {
return m, nil
}
return m, err
@@ -899,7 +899,7 @@ func (c *commandeer) newWatcher(pollIntervalStr string, dirList ...string) (*wat
}
unlock()
case err := <-watcher.Errors():
if err != nil && !os.IsNotExist(err) {
if err != nil && !herrors.IsNotExist(err) {
c.logger.Errorln("Error while watching:", err)
}
}

View File

@@ -14,9 +14,9 @@
package commands
import (
"os"
"path/filepath"
"github.com/gohugoio/hugo/common/herrors"
"github.com/gohugoio/hugo/hugolib/filesystems"
"github.com/fsnotify/fsnotify"
@@ -95,7 +95,7 @@ func (s *staticSyncer) syncsStaticEvents(staticEvents []fsnotify.Event) error {
// the source of that static file. In this case Hugo will incorrectly remove that file
// from the published directory.
if ev.Op&fsnotify.Rename == fsnotify.Rename || ev.Op&fsnotify.Remove == fsnotify.Remove {
if _, err := sourceFs.Fs.Stat(relPath); os.IsNotExist(err) {
if _, err := sourceFs.Fs.Stat(relPath); herrors.IsNotExist(err) {
// If file doesn't exist in any static dir, remove it
logger.Println("File no longer exists in static dir, removing", relPath)
_ = c.Fs.PublishDirStatic.RemoveAll(relPath)