Avoid race condition in target list init

As reported by Go's race detector.

See #917
This commit is contained in:
bep 2015-02-20 18:38:35 +01:00
parent c33a8528f8
commit dc7b7ef865

View file

@ -77,6 +77,7 @@ type Site struct {
Menus Menus
timer *nitro.B
Targets targetList
targetListInit sync.Once
Completed chan bool
RunMode runmode
params map[string]interface{}
@ -1454,32 +1455,39 @@ func (s *Site) NewXMLBuffer() *bytes.Buffer {
}
func (s *Site) PageTarget() target.Output {
s.initTargetList()
return s.Targets.Page
}
func (s *Site) FileTarget() target.Output {
s.initTargetList()
return s.Targets.File
}
func (s *Site) AliasTarget() target.AliasPublisher {
s.initTargetList()
return s.Targets.Alias
}
func (s *Site) initTargetList() {
s.targetListInit.Do(func() {
if s.Targets.Page == nil {
s.Targets.Page = &target.PagePub{
PublishDir: s.absPublishDir(),
UglyUrls: viper.GetBool("UglyUrls"),
}
}
return s.Targets.Page
}
func (s *Site) FileTarget() target.Output {
if s.Targets.File == nil {
s.Targets.File = &target.Filesystem{
PublishDir: s.absPublishDir(),
}
}
return s.Targets.File
}
func (s *Site) AliasTarget() target.AliasPublisher {
if s.Targets.Alias == nil {
s.Targets.Alias = &target.HTMLRedirectAlias{
PublishDir: s.absPublishDir(),
}
}
return s.Targets.Alias
})
}
func (s *Site) WriteDestFile(path string, reader io.Reader) (err error) {