Add a cross process build lock and use it in the archetype content builder

Fixes #9048
This commit is contained in:
Bjørn Erik Pedersen
2021-10-17 11:54:55 +02:00
parent c7957c90e8
commit ba35e69856
7 changed files with 79 additions and 32 deletions

View File

@@ -44,19 +44,17 @@ import (
// Build builds all sites. If filesystem events are provided,
// this is considered to be a potential partial rebuild.
func (h *HugoSites) Build(config BuildCfg, events ...fsnotify.Event) error {
if h.running {
// Make sure we don't trigger rebuilds in parallel.
h.runningMu.Lock()
defer h.runningMu.Unlock()
} else {
defer func() {
h.Close()
}()
}
ctx, task := trace.NewTask(context.Background(), "Build")
defer task.End()
if !config.NoBuildLock {
unlock, err := h.BaseFs.LockBuild()
if err != nil {
return errors.Wrap(err, "failed to acquire a build lock")
}
defer unlock()
}
errCollector := h.StartErrorCollector()
errs := make(chan error)