mirror of
https://gitee.com/johng/gf
synced 2026-06-06 16:21:40 +08:00
fix: disable specific staticcheck rules and update lint config - Disabled staticcheck rules SA1029, SA1019, S1000, and related checks in `.golangci.yml` to filter out unwanted linter errors. - Updated staticcheck checks list for more precise linting control. - Clarified configuration for easier maintenance and future updates. --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: hailaz <739476267@qq.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
59 lines
1.5 KiB
Go
59 lines
1.5 KiB
Go
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
|
//
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
// If a copy of the MIT was not distributed with this file,
|
|
// You can obtain one at https://github.com/gogf/gf.
|
|
|
|
package gfile
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
|
|
"github.com/gogf/gf/v2/container/garray"
|
|
"github.com/gogf/gf/v2/errors/gerror"
|
|
)
|
|
|
|
// Search searches file by name `name` in following paths with priority:
|
|
// prioritySearchPaths, Pwd()、SelfDir()、MainPkgPath().
|
|
// It returns the absolute file path of `name` if found, or en empty string if not found.
|
|
func Search(name string, prioritySearchPaths ...string) (realPath string, err error) {
|
|
// Check if it's an absolute path.
|
|
realPath = RealPath(name)
|
|
if realPath != "" {
|
|
return
|
|
}
|
|
// Search paths array.
|
|
array := garray.NewStrArray()
|
|
array.Append(prioritySearchPaths...)
|
|
array.Append(Pwd(), SelfDir())
|
|
if path := MainPkgPath(); path != "" {
|
|
array.Append(path)
|
|
}
|
|
// Remove repeated items.
|
|
array.Unique()
|
|
// Do the searching.
|
|
array.RLockFunc(func(array []string) {
|
|
path := ""
|
|
for _, v := range array {
|
|
path = RealPath(v + Separator + name)
|
|
if path != "" {
|
|
realPath = path
|
|
break
|
|
}
|
|
}
|
|
})
|
|
// If it fails searching, it returns formatted error.
|
|
if realPath == "" {
|
|
buffer := bytes.NewBuffer(nil)
|
|
fmt.Fprintf(buffer, `cannot find "%s" in following paths:`, name)
|
|
array.RLockFunc(func(array []string) {
|
|
for k, v := range array {
|
|
fmt.Fprintf(buffer, "\n%d. %s", k+1, v)
|
|
}
|
|
})
|
|
err = gerror.New(buffer.String())
|
|
}
|
|
return
|
|
}
|