diff options
author | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2023-05-19 12:54:42 +0200 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2023-05-19 16:34:22 +0200 |
commit | 0a51dfac9e22b7b29bcbe52c3b0519771f6a07ca (patch) | |
tree | eb0afa09140dde34a5257b5d6e26fd990721df8b /commands/commandeer.go | |
parent | c371171ab81f0d2fd0f04af0faedd2c5ef53550e (diff) |
commands: Fix data race
By wrapping all use of the shared config in a lock.
Updates #10953
Diffstat (limited to 'commands/commandeer.go')
-rw-r--r-- | commands/commandeer.go | 13 |
1 files changed, 3 insertions, 10 deletions
diff --git a/commands/commandeer.go b/commands/commandeer.go index 222a2a020..5fb29d791 100644 --- a/commands/commandeer.go +++ b/commands/commandeer.go @@ -79,18 +79,12 @@ func Execute(args []string) error { } type commonConfig struct { - mu sync.Mutex + mu *sync.Mutex configs *allconfig.Configs cfg config.Provider fs *hugofs.Fs } -func (c *commonConfig) getFs() *hugofs.Fs { - c.mu.Lock() - defer c.mu.Unlock() - return c.fs -} - // This is the root command. type rootCommand struct { Printf func(format string, v ...interface{}) @@ -181,6 +175,7 @@ func (r *rootCommand) ConfigFromConfig(key int32, oldConf *commonConfig) (*commo } return &commonConfig{ + mu: oldConf.mu, configs: configs, cfg: oldConf.cfg, fs: fs, @@ -295,6 +290,7 @@ func (r *rootCommand) ConfigFromProvider(key int32, cfg config.Provider) (*commo } commonConfig := &commonConfig{ + mu: &sync.Mutex{}, configs: configs, cfg: cfg, fs: fs, @@ -309,9 +305,6 @@ func (r *rootCommand) ConfigFromProvider(key int32, cfg config.Provider) (*commo func (r *rootCommand) HugFromConfig(conf *commonConfig) (*hugolib.HugoSites, error) { h, _, err := r.hugoSites.GetOrCreate(r.configVersionID.Load(), func(key int32) (*hugolib.HugoSites, error) { - conf.mu.Lock() - defer conf.mu.Unlock() - depsCfg := deps.DepsCfg{Configs: conf.configs, Fs: conf.fs, Logger: r.logger} return hugolib.NewHugoSites(depsCfg) }) |