hugolib: Fix deletion of orphaned sections
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 20 Feb 2020 12:40:16 +0000 (13:40 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Thu, 20 Feb 2020 12:40:16 +0000 (13:40 +0100)
Avoid deleting inside the recursive walk.

Fixes #6920

hugolib/content_map.go

index 279c8e43ab1101815470b921c7e927fba37a6cad..efa2254b2a778dbb391f999cfc0b07ff92e02422 100644 (file)
@@ -596,6 +596,7 @@ func (m *contentMap) deleteBundleMatching(matches func(b *contentNode) bool) {
 
 // Deletes any empty root section that's not backed by a content file.
 func (m *contentMap) deleteOrphanSections() {
+       var sectionsToDelete []string
 
        m.sections.Walk(func(s string, v interface{}) bool {
                n := v.(*contentNode)
@@ -612,11 +613,15 @@ func (m *contentMap) deleteOrphanSections() {
                prefixBundle := s + cmBranchSeparator
 
                if !(m.sections.hasPrefix(s+"/") || m.pages.hasPrefix(prefixBundle) || m.resources.hasPrefix(prefixBundle)) {
-                       m.sections.Delete(s)
+                       sectionsToDelete = append(sectionsToDelete, s)
                }
 
                return false
        })
+
+       for _, s := range sectionsToDelete {
+               m.sections.Delete(s)
+       }
 }
 
 func (m *contentMap) deletePage(s string) {