diff --git a/g/os/gfile/gfile.go b/g/os/gfile/gfile.go index e55e156f4..e658a869b 100644 --- a/g/os/gfile/gfile.go +++ b/g/os/gfile/gfile.go @@ -425,8 +425,7 @@ func MainPkgPath() string { continue } // separator of '/' will be converted to Separator. - path = Dir(file) - for path[len(path) - 1] != os.PathSeparator { + for path = Dir(file); len(path) > 1 && Exists(path) && path[len(path) - 1] != os.PathSeparator; { files, _ := ScanDir(path, "*.go") for _, v := range files { if gregex.IsMatchString(`package\s+main`, GetContents(v)) {