Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Widgets search supports symlink subdirectory #8276

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 8 additions & 3 deletions kernel/model/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 {
88250 marked this conversation as resolved.
Show resolved Hide resolved
name := strings.ToLower(entry.Name())
if strings.HasPrefix(name, ".") {
if info.IsDir() {
if entry.IsDir() {
return filepath.SkipDir
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion kernel/model/widget.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down