mirror of
https://github.com/gohugoio/hugo.git
synced 2025-03-22 22:04:19 +00:00
tplimpl: Fix map data race in URLLock
This commit is contained in:
parent
79b34c2f1e
commit
42a4f6f9cb
1 changed files with 8 additions and 3 deletions
|
@ -46,12 +46,17 @@ type remoteLock struct {
|
||||||
|
|
||||||
// URLLock locks an URL during download
|
// URLLock locks an URL during download
|
||||||
func (l *remoteLock) URLLock(url string) {
|
func (l *remoteLock) URLLock(url string) {
|
||||||
|
var (
|
||||||
|
lock *sync.Mutex
|
||||||
|
ok bool
|
||||||
|
)
|
||||||
l.Lock()
|
l.Lock()
|
||||||
if _, ok := l.m[url]; !ok {
|
if lock, ok = l.m[url]; !ok {
|
||||||
l.m[url] = &sync.Mutex{}
|
lock = &sync.Mutex{}
|
||||||
|
l.m[url] = lock
|
||||||
}
|
}
|
||||||
l.Unlock()
|
l.Unlock()
|
||||||
l.m[url].Lock()
|
lock.Lock()
|
||||||
}
|
}
|
||||||
|
|
||||||
// URLUnlock unlocks an URL when the download has been finished. Use only in defer calls.
|
// URLUnlock unlocks an URL when the download has been finished. Use only in defer calls.
|
||||||
|
|
Loading…
Reference in a new issue