1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-25 23:01:28 +00:00

fix(Template): error handling when reading files

This commit is contained in:
Viktor Vassilyev 2018-11-06 20:41:05 +06:00
parent 3447798494
commit 68b0bd98fd
2 changed files with 14 additions and 0 deletions

7
fs.go
View File

@ -40,6 +40,13 @@ func walk(fs http.FileSystem, path string, info os.FileInfo, walkFn filepath.Wal
dir, err := fs.Open(path) dir, err := fs.Open(path)
defer dir.Close() defer dir.Close()
if err == nil {
err1 := walkFn(path, info, err)
if err1 != nil {
return err1
}
return err
}
dirs, err := dir.Readdir(-1) dirs, err := dir.Readdir(-1)
err1 := walkFn(path, info, err) err1 := walkFn(path, info, err)
// If err != nil, walk can't walk into this directory. // If err != nil, walk can't walk into this directory.

View File

@ -327,6 +327,10 @@ func _getTemplate(t0 *template.Template, root string, fs http.FileSystem, subMod
} }
data, err = ioutil.ReadAll(f) data, err = ioutil.ReadAll(f)
f.Close() f.Close()
if err != nil {
logs.Trace("template parse file err:", err)
continue
}
reg := regexp.MustCompile(BConfig.WebConfig.TemplateLeft + "[ ]*define[ ]+\"([^\"]+)\"") reg := regexp.MustCompile(BConfig.WebConfig.TemplateLeft + "[ ]*define[ ]+\"([^\"]+)\"")
allSub := reg.FindAllStringSubmatch(string(data), -1) allSub := reg.FindAllStringSubmatch(string(data), -1)
for _, sub := range allSub { for _, sub := range allSub {
@ -337,6 +341,9 @@ func _getTemplate(t0 *template.Template, root string, fs http.FileSystem, subMod
logs.Trace("template parse file err:", err) logs.Trace("template parse file err:", err)
} else if len(subMods1) > 0 { } else if len(subMods1) > 0 {
t, err = _getTemplate(t, root, fs, subMods1, others...) t, err = _getTemplate(t, root, fs, subMods1, others...)
if err != nil {
logs.Trace("template parse file err:", err)
}
} }
break break
} }