aboutsummaryrefslogtreecommitdiffhomepage
path: root/cache/filecache/filecache.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2019-10-21 09:37:46 +0200
committerBjørn Erik Pedersen <[email protected]>2019-10-21 09:51:51 +0200
commit180195aa342777fece1b29a08ec89456d7996c61 (patch)
tree8ae89c429d5ce16715e092e9bd09b4bfb84acf4e /cache/filecache/filecache.go
parent4b286b9d2722909d0682e50eeecdfe16c1f47fd8 (diff)
downloadhugo-180195aa342777fece1b29a08ec89456d7996c61.tar.gz
hugo-180195aa342777fece1b29a08ec89456d7996c61.zip
cache/filecache: Recover from file corruption
Fixes #6401
Diffstat (limited to 'cache/filecache/filecache.go')
-rw-r--r--cache/filecache/filecache.go12
1 files changed, 11 insertions, 1 deletions
diff --git a/cache/filecache/filecache.go b/cache/filecache/filecache.go
index bc0573d52..3628300fb 100644
--- a/cache/filecache/filecache.go
+++ b/cache/filecache/filecache.go
@@ -15,6 +15,7 @@ package filecache
import (
"bytes"
+ "errors"
"io"
"io/ioutil"
"os"
@@ -31,6 +32,9 @@ import (
"github.com/spf13/afero"
)
+// ErrFatal can be used to signal an unrecoverable error.
+var ErrFatal = errors.New("fatal filecache error")
+
const (
filecacheRootDirname = "filecache"
)
@@ -137,7 +141,13 @@ func (c *Cache) ReadOrCreate(id string,
if r := c.getOrRemove(id); r != nil {
err = read(info, r)
defer r.Close()
- return
+ if err == nil || err == ErrFatal {
+ // See https://github.com/gohugoio/hugo/issues/6401
+ // To recover from file corruption we handle read errors
+ // as the cache item was not found.
+ // Any file permission issue will also fail in the next step.
+ return
+ }
}
f, err := helpers.OpenFileForWriting(c.Fs, id)