mirror of
https://gitee.com/johng/gf.git
synced 2024-11-30 03:07:45 +08:00
add absolute file path support for package gcfg/gview
This commit is contained in:
parent
fe93d7b332
commit
6468d55a81
@ -174,6 +174,11 @@ func (c *AdapterFile) GetFilePath(fileName ...string) (path string, err error) {
|
|||||||
c.autoCheckAndAddMainPkgPathToSearchPaths()
|
c.autoCheckAndAddMainPkgPathToSearchPaths()
|
||||||
|
|
||||||
// Searching local file system.
|
// Searching local file system.
|
||||||
|
if path == "" {
|
||||||
|
// Absolute path.
|
||||||
|
if path = gfile.RealPath(usedFileName); path != "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
c.searchPaths.RLockFunc(func(array []string) {
|
c.searchPaths.RLockFunc(func(array []string) {
|
||||||
for _, searchPath := range array {
|
for _, searchPath := range array {
|
||||||
searchPath = gstr.TrimRight(searchPath, `\/`)
|
searchPath = gstr.TrimRight(searchPath, `\/`)
|
||||||
@ -188,11 +193,11 @@ func (c *AdapterFile) GetFilePath(fileName ...string) (path string, err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// If it cannot find the path of `file`, it formats and returns a detailed error.
|
// If it cannot find the path of `file`, it formats and returns a detailed error.
|
||||||
if path == "" {
|
if path == "" {
|
||||||
var (
|
var buffer = bytes.NewBuffer(nil)
|
||||||
buffer = bytes.NewBuffer(nil)
|
|
||||||
)
|
|
||||||
if c.searchPaths.Len() > 0 {
|
if c.searchPaths.Len() > 0 {
|
||||||
buffer.WriteString(fmt.Sprintf(
|
buffer.WriteString(fmt.Sprintf(
|
||||||
`config file "%s" not found in resource manager or the following system searching paths:`,
|
`config file "%s" not found in resource manager or the following system searching paths:`,
|
||||||
|
@ -319,9 +319,7 @@ func (view *View) formatTemplateObjectCreatingError(filePath, tplName string, er
|
|||||||
// Note that, the returned `folder` is the template folder path, but not the folder of
|
// Note that, the returned `folder` is the template folder path, but not the folder of
|
||||||
// the returned template file `path`.
|
// the returned template file `path`.
|
||||||
func (view *View) searchFile(ctx context.Context, file string) (path string, folder string, resource *gres.File, err error) {
|
func (view *View) searchFile(ctx context.Context, file string) (path string, folder string, resource *gres.File, err error) {
|
||||||
var (
|
var tempPath string
|
||||||
tempPath string
|
|
||||||
)
|
|
||||||
// Firstly checking the resource manager.
|
// Firstly checking the resource manager.
|
||||||
if !gres.IsEmpty() {
|
if !gres.IsEmpty() {
|
||||||
// Try folders.
|
// Try folders.
|
||||||
@ -350,6 +348,13 @@ func (view *View) searchFile(ctx context.Context, file string) (path string, fol
|
|||||||
|
|
||||||
// Secondly checking the file system.
|
// Secondly checking the file system.
|
||||||
if path == "" {
|
if path == "" {
|
||||||
|
// Absolute path.
|
||||||
|
path = gfile.RealPath(file)
|
||||||
|
if path != "" {
|
||||||
|
folder = gfile.Dir(path)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// In search paths.
|
||||||
view.searchPaths.RLockFunc(func(array []string) {
|
view.searchPaths.RLockFunc(func(array []string) {
|
||||||
for _, searchPath := range array {
|
for _, searchPath := range array {
|
||||||
searchPath = gstr.TrimRight(searchPath, `\/`)
|
searchPath = gstr.TrimRight(searchPath, `\/`)
|
||||||
|
Loading…
Reference in New Issue
Block a user