From 685da50d936139e28e28319c5fafa06ff44f5a39 Mon Sep 17 00:00:00 2001 From: youngsterxyf Date: Mon, 11 Jan 2016 12:22:38 +0800 Subject: [PATCH] fix #1552 in beego, see: https://github.com/astaxie/beego/issues/1552 --- run.go | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/run.go b/run.go index 8d2f9a2..f1f97bb 100644 --- a/run.go +++ b/run.go @@ -134,7 +134,7 @@ func readAppDirectories(directory string, paths *[]string) { continue } - if isExcluded(fileInfo) { + if isExcluded(path.Join(directory, fileInfo.Name())) { continue } @@ -157,10 +157,20 @@ func readAppDirectories(directory string, paths *[]string) { } // If a file is excluded -func isExcluded(fileInfo os.FileInfo) bool { +func isExcluded(filePath string) bool { for _, p := range excludedPaths { - if strings.HasSuffix(fileInfo.Name(), p) { - ColorLog("[INFO] Excluding from watching [ %s ]\n", fileInfo.Name()) + absP, err := path.Abs(p) + if err != nil { + ColorLog("[ERROR] Can not get absolute path of [ %s ]\n", p) + continue + } + absFilePath, err := path.Abs(filePath) + if err != nil { + ColorLog("[ERROR] Can not get absolute path of [ %s ]\n", filePath) + break + } + if strings.HasPrefix(absFilePath, absP) { + ColorLog("[INFO] Excluding from watching [ %s ]\n", filePath) return true } }