Merge remote-tracking branch 'origin/dev' into dev

This commit is contained in:
Vanessa 2023-05-17 15:36:37 +08:00
commit de2a414968
2 changed files with 9 additions and 4 deletions

View file

@ -70,6 +70,10 @@ func SearchTemplate(keyword string) (ret []*Block) {
ret = []*Block{}
templates := filepath.Join(util.DataDir, "templates")
if !util.IsPathRegularDirOrSymlinkDir(templates) {
return
}
groups, err := os.ReadDir(templates)
if nil != err {
logging.LogErrorf("read templates failed: %s", err)
@ -89,10 +93,11 @@ func SearchTemplate(keyword string) (ret []*Block) {
if group.IsDir() {
var templateBlocks []*Block
templateDir := filepath.Join(templates, group.Name())
filepath.Walk(templateDir, func(path string, info fs.FileInfo, err error) error {
name := strings.ToLower(info.Name())
// filepath.Walk 与 filepath.WalkDir 均不支持跟踪符号链接
filepath.WalkDir(templateDir, func(path string, entry fs.DirEntry, err error) error {
name := strings.ToLower(entry.Name())
if strings.HasPrefix(name, ".") {
if info.IsDir() {
if entry.IsDir() {
return filepath.SkipDir
}
return nil

View file

@ -37,7 +37,7 @@ func SearchWidget(keyword string) (ret []*Block) {
k := strings.ToLower(keyword)
for _, entry := range entries {
if !entry.IsDir() {
if !util.IsDirRegularOrSymlink(entry) {
continue
}