Skip to content

Commit

Permalink
Fix panic when specifying multiple excludeFiles directives
Browse files Browse the repository at this point in the history
Fixes #9076
  • Loading branch information
bep committed Oct 25, 2021
1 parent b959ecb commit 64e1613
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion hugolib/mount_filters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ includeFiles = "/mydata/**"
[[module.mounts]]
source = 'assets'
target = 'assets'
excludeFiles = "/**exclude.*"
excludeFiles = ["/**exclude.*", "/moooo.*"]
[[module.mounts]]
source = 'i18n'
target = 'i18n'
Expand Down
6 changes: 3 additions & 3 deletions modules/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,13 @@ func (m *ModulesConfig) finalize(logger loggers.Logger) error {

func filterUnwantedMounts(mounts []Mount) []Mount {
// Remove duplicates
seen := make(map[Mount]bool)
seen := make(map[string]bool)
tmp := mounts[:0]
for _, m := range mounts {
if !seen[m] {
if !seen[m.key()] {
tmp = append(tmp, m)
}
seen[m] = true
seen[m.key()] = true
}
return tmp
}
Expand Down
6 changes: 6 additions & 0 deletions modules/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package modules

import (
"fmt"
"path"
"path/filepath"
"strings"

Expand Down Expand Up @@ -386,6 +387,11 @@ type Mount struct {
ExcludeFiles interface{}
}

// Used as key to remove duplicates.
func (m Mount) key() string {
return path.Join(m.Lang, m.Source, m.Target)
}

func (m Mount) Component() string {
return strings.Split(m.Target, fileSeparator)[0]
}
Expand Down

0 comments on commit 64e1613

Please sign in to comment.