Fix panic when specifying multiple excludeFiles directives
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 25 Oct 2021 10:18:00 +0000 (12:18 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Mon, 25 Oct 2021 17:50:18 +0000 (19:50 +0200)
Fixes #9076

hugolib/mount_filters_test.go
modules/collect.go
modules/config.go

index 5e409fcaa19a89f69b4509ceb1bb5cab06a82a8f..5f41577155f634ff3b232df6ad8c5c5079b376c0 100644 (file)
@@ -62,7 +62,7 @@ includeFiles = "/mydata/**"
 [[module.mounts]]
 source = 'assets'
 target = 'assets'
-excludeFiles = "/**exclude.*"
+excludeFiles = ["/**exclude.*", "/moooo.*"]
 [[module.mounts]]
 source = 'i18n'
 target = 'i18n'
index 8798f45b118f6e35f32f8993d3ce707db1d9f16d..44d714a67aa2f87884b5a9931a504c4885038c31 100644 (file)
@@ -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
 }
index f80a456cfc933aa3018143e7bf0316b6dac59352..fc4d617f9cfc9eca7487d90119ed1e5f36b16ee7 100644 (file)
@@ -15,6 +15,7 @@ package modules
 
 import (
        "fmt"
+       "path"
        "path/filepath"
        "strings"
 
@@ -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]
 }