diff options
author | Bjørn Erik Pedersen <[email protected]> | 2020-06-16 10:42:41 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2020-06-16 11:48:10 +0200 |
commit | 6408c1cbc87f03fc9e92471165886ddbe7cdbeae (patch) | |
tree | abec79e04cb66f376d83d122a795ad1923b9bc54 /hugolib/hugo_sites.go | |
parent | 522ba1cd98ac67482061448c3a7528e68a720f0d (diff) | |
download | hugo-6408c1cbc87f03fc9e92471165886ddbe7cdbeae.tar.gz hugo-6408c1cbc87f03fc9e92471165886ddbe7cdbeae.zip |
Fix server data race/nil pointer in withMaps
Fixes #7392
Diffstat (limited to 'hugolib/hugo_sites.go')
-rw-r--r-- | hugolib/hugo_sites.go | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/hugolib/hugo_sites.go b/hugolib/hugo_sites.go index 3183242b7..16de27b0d 100644 --- a/hugolib/hugo_sites.go +++ b/hugolib/hugo_sites.go @@ -78,7 +78,8 @@ type HugoSites struct { // As loaded from the /data dirs data map[string]interface{} - content *pageMaps + contentInit sync.Once + content *pageMaps // Keeps track of bundle directories and symlinks to enable partial rebuilding. ContentChanges *contentChangeMap @@ -92,6 +93,13 @@ type HugoSites struct { *testCounters } +func (h *HugoSites) getContentMaps() *pageMaps { + h.contentInit.Do(func() { + h.content = newPageMaps(h) + }) + return h.content +} + // Only used in tests. type testCounters struct { contentRenderCounter uint64 @@ -253,7 +261,7 @@ func (h *HugoSites) PrintProcessingStats(w io.Writer) { func (h *HugoSites) GetContentPage(filename string) page.Page { var p page.Page - h.content.walkBundles(func(b *contentNode) bool { + h.getContentMaps().walkBundles(func(b *contentNode) bool { if b.p == nil || b.fi == nil { return false } @@ -706,7 +714,7 @@ func (h *HugoSites) renderCrossSitesArtifacts() error { } func (h *HugoSites) removePageByFilename(filename string) { - h.content.withMaps(func(m *pageMap) error { + h.getContentMaps().withMaps(func(m *pageMap) error { m.deleteBundleMatching(func(b *contentNode) bool { if b.p == nil { return false @@ -897,7 +905,7 @@ func (h *HugoSites) findPagesByKindIn(kind string, inPages page.Pages) page.Page } func (h *HugoSites) resetPageState() { - h.content.walkBundles(func(n *contentNode) bool { + h.getContentMaps().walkBundles(func(n *contentNode) bool { if n.p == nil { return false } @@ -914,7 +922,7 @@ func (h *HugoSites) resetPageState() { } func (h *HugoSites) resetPageStateFromEvents(idset identity.Identities) { - h.content.walkBundles(func(n *contentNode) bool { + h.getContentMaps().walkBundles(func(n *contentNode) bool { if n.p == nil { return false } |