diff options
author | HyeonGyu Lee <vazrupe@naver.com> | 2019-08-15 16:33:47 +0900 |
---|---|---|
committer | Bjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com> | 2019-08-15 09:33:47 +0200 |
commit | ea9261e856c13c1d4ae05fcca08766d410b4b65c (patch) | |
tree | 70c68f81d682dff217848bee8b215369ad4a94ea /commands/commandeer.go | |
parent | 37f592980315de1890363d4234274a16567a6da0 (diff) |
commands: Make sure the hugo field is always initialized before it's used
Wrap the field to make it accessible after initialization.
Fixes #6193
Diffstat (limited to 'commands/commandeer.go')
-rw-r--r-- | commands/commandeer.go | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/commands/commandeer.go b/commands/commandeer.go index 015bf3678..55526a857 100644 --- a/commands/commandeer.go +++ b/commands/commandeer.go @@ -52,8 +52,9 @@ import ( type commandeerHugoState struct { *deps.DepsCfg - hugo *hugolib.HugoSites - fsCreate sync.Once + hugoSites *hugolib.HugoSites + fsCreate sync.Once + created chan struct{} } type commandeer struct { @@ -97,6 +98,17 @@ type commandeer struct { buildErr error } +func newCommandeerHugoState() *commandeerHugoState { + return &commandeerHugoState{ + created: make(chan struct{}), + } +} + +func (c *commandeerHugoState) hugo() *hugolib.HugoSites { + <-c.created + return c.hugoSites +} + func (c *commandeer) errCount() int { return int(c.logger.ErrorCounter.Count()) } @@ -154,7 +166,7 @@ func newCommandeer(mustHaveConfigFile, running bool, h *hugoBuilderCommon, f fla c := &commandeer{ h: h, ftch: f, - commandeerHugoState: &commandeerHugoState{}, + commandeerHugoState: newCommandeerHugoState(), doWithCommandeer: doWithCommandeer, visitedURLs: types.NewEvictingStringQueue(10), debounce: rebuildDebouncer, @@ -373,13 +385,15 @@ func (c *commandeer) loadConfig(mustHaveConfigFile, running bool) error { err = c.initFs(fs) if err != nil { + close(c.created) return } var h *hugolib.HugoSites h, err = hugolib.NewHugoSites(*c.DepsCfg) - c.hugo = h + c.hugoSites = h + close(c.created) }) |