mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-29 18:42:11 -05:00
Avoid race condition in target list init
As reported by Go's race detector. See #917
This commit is contained in:
parent
c33a8528f8
commit
dc7b7ef865
1 changed files with 42 additions and 34 deletions
|
@ -77,6 +77,7 @@ type Site struct {
|
||||||
Menus Menus
|
Menus Menus
|
||||||
timer *nitro.B
|
timer *nitro.B
|
||||||
Targets targetList
|
Targets targetList
|
||||||
|
targetListInit sync.Once
|
||||||
Completed chan bool
|
Completed chan bool
|
||||||
RunMode runmode
|
RunMode runmode
|
||||||
params map[string]interface{}
|
params map[string]interface{}
|
||||||
|
@ -1454,32 +1455,39 @@ func (s *Site) NewXMLBuffer() *bytes.Buffer {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Site) PageTarget() target.Output {
|
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 {
|
if s.Targets.Page == nil {
|
||||||
s.Targets.Page = &target.PagePub{
|
s.Targets.Page = &target.PagePub{
|
||||||
PublishDir: s.absPublishDir(),
|
PublishDir: s.absPublishDir(),
|
||||||
UglyUrls: viper.GetBool("UglyUrls"),
|
UglyUrls: viper.GetBool("UglyUrls"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return s.Targets.Page
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Site) FileTarget() target.Output {
|
|
||||||
if s.Targets.File == nil {
|
if s.Targets.File == nil {
|
||||||
s.Targets.File = &target.Filesystem{
|
s.Targets.File = &target.Filesystem{
|
||||||
PublishDir: s.absPublishDir(),
|
PublishDir: s.absPublishDir(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return s.Targets.File
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Site) AliasTarget() target.AliasPublisher {
|
|
||||||
if s.Targets.Alias == nil {
|
if s.Targets.Alias == nil {
|
||||||
s.Targets.Alias = &target.HTMLRedirectAlias{
|
s.Targets.Alias = &target.HTMLRedirectAlias{
|
||||||
PublishDir: s.absPublishDir(),
|
PublishDir: s.absPublishDir(),
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return s.Targets.Alias
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Site) WriteDestFile(path string, reader io.Reader) (err error) {
|
func (s *Site) WriteDestFile(path string, reader io.Reader) (err error) {
|
||||||
|
|
Loading…
Reference in a new issue