cache/filecache: Recover from file corruption

Fixes #6401
This commit is contained in:
Bjørn Erik Pedersen
2019-10-21 09:37:46 +02:00
parent 4b286b9d27
commit 180195aa34
2 changed files with 61 additions and 1 deletions

View File

@@ -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)