Commit a5128da6 authored by Alexander Morozov's avatar Alexander Morozov

markdown: fix race in accessing map

Signed-off-by: default avatarAlexander Morozov <lk4d4@docker.com>
parent dc4a5ae1
...@@ -126,8 +126,11 @@ func (md Markdown) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error ...@@ -126,8 +126,11 @@ func (md Markdown) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error
} }
} }
cfg.RLock()
filepath, ok := cfg.StaticFiles[fpath]
cfg.RUnlock()
// if static site is generated, attempt to use it // if static site is generated, attempt to use it
if filepath, ok := cfg.StaticFiles[fpath]; ok { if ok {
if fs1, err := os.Stat(filepath); err == nil { if fs1, err := os.Stat(filepath); err == nil {
// if markdown has not been modified since static page // if markdown has not been modified since static page
// generation, serve the static page // generation, serve the static page
......
...@@ -153,7 +153,9 @@ func (md Markdown) generatePage(c *Config, requestPath string, content []byte) e ...@@ -153,7 +153,9 @@ func (md Markdown) generatePage(c *Config, requestPath string, content []byte) e
return err return err
} }
c.Lock()
c.StaticFiles[requestPath] = filePath c.StaticFiles[requestPath] = filePath
c.Unlock()
} }
return nil return nil
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment