mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 13:30:56 +00:00
isOk to check whether the file is latest
This commit is contained in:
parent
d963bb79bd
commit
5d01afe3a6
@ -100,15 +100,13 @@ var (
|
|||||||
|
|
||||||
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
|
||||||
mapFile, ok := staticFileMap[mapKey]
|
mapFile, _ := staticFileMap[mapKey]
|
||||||
if ok {
|
if isOk(mapFile, fi) {
|
||||||
if mapFile.modTime == fi.ModTime() && mapFile.size == fi.Size() {
|
|
||||||
return mapFile.encoding != "", mapFile.encoding, mapFile, nil
|
return mapFile.encoding != "", mapFile.encoding, mapFile, nil
|
||||||
}
|
}
|
||||||
}
|
|
||||||
mapLock.Lock()
|
mapLock.Lock()
|
||||||
defer mapLock.Unlock()
|
defer mapLock.Unlock()
|
||||||
if mapFile, ok = staticFileMap[mapKey]; !ok {
|
if mapFile, _ = staticFileMap[mapKey]; !isOk(mapFile, fi) {
|
||||||
file, err := os.Open(filePath)
|
file, err := os.Open(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, "", nil, err
|
return false, "", nil, err
|
||||||
@ -126,6 +124,13 @@ func openFile(filePath string, fi os.FileInfo, acceptEncoding string) (bool, str
|
|||||||
return mapFile.encoding != "", mapFile.encoding, mapFile, nil
|
return mapFile.encoding != "", mapFile.encoding, mapFile, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func isOk(s *serveContentHolder, fi os.FileInfo) bool {
|
||||||
|
if s == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return s.modTime == fi.ModTime() && s.size == fi.Size()
|
||||||
|
}
|
||||||
|
|
||||||
// isStaticCompress detect static files
|
// isStaticCompress detect static files
|
||||||
|
|
||||||
func isStaticCompress(filePath string) bool {
|
func isStaticCompress(filePath string) bool {
|
||||||
|
Loading…
Reference in New Issue
Block a user