1
0
mirror of https://github.com/danog/gojekyll.git synced 2024-11-30 08:28:58 +01:00

Mutex the cache

This commit is contained in:
Oliver Steele 2017-07-13 19:01:44 -04:00
parent 8bee1ea96a
commit e5e96cef84

4
cache/cache.go vendored
View File

@ -7,9 +7,11 @@ import (
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath" "path/filepath"
"sync"
) )
var disableCache = false var disableCache = false
var cacheMx sync.Mutex
func init() { func init() {
s := os.Getenv("GOJEKYLL_DISABLE_CACHE") s := os.Getenv("GOJEKYLL_DISABLE_CACHE")
@ -51,6 +53,8 @@ func WithFile(header string, content string, fn func() (string, error)) (string,
if err := os.MkdirAll(filepath.Dir(cachefile), 0700); err != nil { if err := os.MkdirAll(filepath.Dir(cachefile), 0700); err != nil {
return "", err return "", err
} }
defer cacheMx.Unlock()
cacheMx.Lock()
if err := ioutil.WriteFile(cachefile, []byte(s), 0600); err != nil { if err := ioutil.WriteFile(cachefile, []byte(s), 0600); err != nil {
return "", err return "", err
} }