mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -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
|
||||
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) {
|
||||
|
|
Loading…
Reference in a new issue