fix issue 437

This commit is contained in:
John
2019-12-25 21:22:06 +08:00
parent a10f428715
commit 80c6ceaf26
8 changed files with 36 additions and 18 deletions

View File

@ -0,0 +1,16 @@
package main
import (
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/net/ghttp"
)
// https://github.com/gogf/gf/issues/437
func main() {
s := g.Server()
s.BindHandler("/", func(r *ghttp.Request) {
r.Response.WriteTpl("client/layout.html")
})
s.SetPort(8199)
s.Run()
}

View File

@ -131,8 +131,8 @@ func formatSubStack(st stack, buffer *bytes.Buffer) {
if strings.Contains(file, gFILTER_KEY) {
continue
}
// Avoid GF stacks if not in GF development.
if !intlog.IsInGFDevelop() {
// Avoid GF stacks if not in GF development.
if strings.Contains(file, "github.com/gogf/gf/") {
continue
}

View File

@ -24,13 +24,15 @@ func (s *Server) handleAccessLog(r *Request) {
if r.TLS != nil {
scheme = "https"
}
s.config.Logger.File(s.config.AccessLogPattern).Stdout(s.config.LogStdout).Printf(
`%d "%s %s %s %s %s" %.3f, %s, "%s", "%s"`,
r.Response.Status,
r.Method, scheme, r.Host, r.URL.String(), r.Proto,
float64(r.LeaveTime-r.EnterTime)/1000,
r.GetClientIp(), r.Referer(), r.UserAgent(),
)
s.config.Logger.File(s.config.AccessLogPattern).
Stdout(s.config.LogStdout).
Printf(
`%d "%s %s %s %s %s" %.3f, %s, "%s", "%s"`,
r.Response.Status,
r.Method, scheme, r.Host, r.URL.String(), r.Proto,
float64(r.LeaveTime-r.EnterTime)/1000,
r.GetClientIp(), r.Referer(), r.UserAgent(),
)
}
// 处理服务错误信息主要是panichttp请求的status由access log进行管理
@ -52,12 +54,15 @@ func (s *Server) handleErrorLog(err error, r *Request) {
)
if stack := gerror.Stack(err); stack != "" {
content += "\nStack:\n" + stack
s.config.Logger.File(s.config.AccessLogPattern).Stack(false).Stdout(s.config.LogStdout).Error(content)
s.config.Logger.File(s.config.AccessLogPattern).
Stack(false).
Stdout(s.config.LogStdout).
Error(content)
return
}
s.config.Logger.File(s.config.AccessLogPattern).
Stack(s.config.ErrorStack).
StackWithFilter(gPATH_FILTER_KEY).
Stdout(s.config.LogStdout).
Errorf(content)
Error(content)
}

View File

@ -101,7 +101,7 @@ func Join(paths ...string) string {
// Exists checks whether given <path> exist.
func Exists(path string) bool {
if _, err := os.Stat(path); !os.IsNotExist(err) {
if stat, err := os.Stat(path); stat != nil && !os.IsNotExist(err) {
return true
}
return false
@ -228,11 +228,7 @@ func CopyDir(src string, dst string) (err error) {
if !si.IsDir() {
return fmt.Errorf("source is not a directory")
}
_, err = os.Stat(dst)
if err != nil && !os.IsNotExist(err) {
return
}
if err == nil {
if Exists(dst) {
return fmt.Errorf("destination already exists")
}
err = os.MkdirAll(dst, si.Mode())

View File

@ -40,7 +40,7 @@ func fileRealPath(path string) string {
// fileExists checks whether given <path> exist.
func fileExists(path string) bool {
if _, err := os.Stat(path); !os.IsNotExist(err) {
if stat, err := os.Stat(path); stat != nil && !os.IsNotExist(err) {
return true
}
return false

View File

@ -165,7 +165,7 @@ func (sp *SPath) Search(name string, indexFiles ...string) (filePath string, isD
path := ""
for _, v := range array {
path = gfile.Join(v, name)
if stat, err := os.Stat(path); !os.IsNotExist(err) {
if stat, err := os.Stat(path); stat != nil && !os.IsNotExist(err) {
path = gfile.Abs(path)
// Security check: the result file path must be under the searching directory.
if len(path) >= len(v) && path[:len(v)] == v {