mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 21:00:57 +00:00
Merge pull request #1750 from JessonChan/staticfile_map_race
static file map race bug fixed
This commit is contained in:
commit
a40c0dd156
@ -93,12 +93,14 @@ type serveContentHolder struct {
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
staticFileMap = make(map[string]*serveContentHolder)
|
staticFileMap = make(map[string]*serveContentHolder)
|
||||||
mapLock sync.Mutex
|
mapLock sync.RWMutex
|
||||||
)
|
)
|
||||||
|
|
||||||
func openFile(filePath string, fi os.FileInfo, acceptEncoding string) (bool, string, *serveContentHolder, error) {
|
func openFile(filePath string, fi os.FileInfo, acceptEncoding string) (bool, string, *serveContentHolder, error) {
|
||||||
mapKey := acceptEncoding + ":" + filePath
|
mapKey := acceptEncoding + ":" + filePath
|
||||||
|
mapLock.RLock()
|
||||||
mapFile, _ := staticFileMap[mapKey]
|
mapFile, _ := staticFileMap[mapKey]
|
||||||
|
mapLock.RUnlock()
|
||||||
if isOk(mapFile, fi) {
|
if isOk(mapFile, fi) {
|
||||||
return mapFile.encoding != "", mapFile.encoding, mapFile, nil
|
return mapFile.encoding != "", mapFile.encoding, mapFile, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user