Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

Bazaar resource directories support symlink (#8263)

颖逸fdbfe6b8487c
diff --git a/kernel/bazaar/icon.go b/kernel/bazaar/icon.go
index 5ba18a1c43..88cf3d1981 100644
--- a/kernel/bazaar/icon.go
+++ b/kernel/bazaar/icon.go
@@ -101,6 +101,11 @@ func Icons() (icons []*Icon) {
func InstalledIcons() (ret []*Icon) {
ret = []*Icon{}
+
+ if !util.IsPathRegularDirOrSymlinkDir(util.IconsPath) {
+ return
+ }
+
iconDirs, err := os.ReadDir(util.IconsPath)
if nil != err {
logging.LogWarnf("read icons folder failed: %s", err)
@@ -110,7 +115,7 @@ func InstalledIcons() (ret []*Icon) {
bazaarIcons := Icons()
for _, iconDir := range iconDirs {
- if !iconDir.IsDir() {
+ if !util.IsDirRegularOrSymlink(iconDir) {
continue
}
dirName := iconDir.Name()
diff --git a/kernel/bazaar/plugin.go b/kernel/bazaar/plugin.go
index 791edc8e9a..b80ee6d268 100644
--- a/kernel/bazaar/plugin.go
+++ b/kernel/bazaar/plugin.go
@@ -24,7 +24,6 @@ import (
"strings"
"sync"
- "github.com/88250/gulu"
"github.com/dustin/go-humanize"
ants "github.com/panjf2000/ants/v2"
"github.com/siyuan-note/httpclient"
@@ -106,7 +105,7 @@ func InstalledPlugins() (ret []*Plugin) {
ret = []*Plugin{}
pluginsPath := filepath.Join(util.DataDir, "plugins")
- if !gulu.File.IsDir(pluginsPath) {
+ if !util.IsPathRegularDirOrSymlinkDir(pluginsPath) {
return
}
@@ -119,7 +118,7 @@ func InstalledPlugins() (ret []*Plugin) {
bazaarPlugins := Plugins()
for _, pluginDir := range pluginDirs {
- if !pluginDir.IsDir() {
+ if !util.IsDirRegularOrSymlink(pluginDir) {
continue
}
dirName := pluginDir.Name()
diff --git a/kernel/bazaar/template.go b/kernel/bazaar/template.go
index 3e5c4859d0..17eb4c02d8 100644
--- a/kernel/bazaar/template.go
+++ b/kernel/bazaar/template.go
@@ -25,7 +25,6 @@ import (
"sync"
"time"
- "github.com/88250/gulu"
"github.com/dustin/go-humanize"
"github.com/panjf2000/ants/v2"
"github.com/siyuan-note/httpclient"
@@ -107,7 +106,7 @@ func InstalledTemplates() (ret []*Template) {
ret = []*Template{}
templatesPath := filepath.Join(util.DataDir, "templates")
- if !gulu.File.IsDir(templatesPath) {
+ if !util.IsPathRegularDirOrSymlinkDir(templatesPath) {
return
}
@@ -120,7 +119,7 @@ func InstalledTemplates() (ret []*Template) {
bazaarTemplates := Templates()
for _, templateDir := range templateDirs {
- if !templateDir.IsDir() {
+ if !util.IsDirRegularOrSymlink(templateDir) {
continue
}
dirName := templateDir.Name()
diff --git a/kernel/bazaar/theme.go b/kernel/bazaar/theme.go
index ca37c26ead..93635b5ad1 100644
--- a/kernel/bazaar/theme.go
+++ b/kernel/bazaar/theme.go
@@ -24,7 +24,6 @@ import (
"strings"
"sync"
- "github.com/88250/gulu"
"github.com/dustin/go-humanize"
ants "github.com/panjf2000/ants/v2"
"github.com/siyuan-note/httpclient"
@@ -105,7 +104,7 @@ func Themes() (ret []*Theme) {
func InstalledThemes() (ret []*Theme) {
ret = []*Theme{}
- if !gulu.File.IsDir(util.ThemesPath) {
+ if !util.IsPathRegularDirOrSymlinkDir(util.ThemesPath) {
return
}
@@ -118,7 +117,7 @@ func InstalledThemes() (ret []*Theme) {
bazaarThemes := Themes()
for _, themeDir := range themeDirs {
- if !themeDir.IsDir() {
+ if !util.IsDirRegularOrSymlink(themeDir) {
continue
}
dirName := themeDir.Name()
diff --git a/kernel/bazaar/widget.go b/kernel/bazaar/widget.go
index 138eeb90cb..b78586ccdb 100644
--- a/kernel/bazaar/widget.go
+++ b/kernel/bazaar/widget.go
@@ -24,7 +24,6 @@ import (
"strings"
"sync"
- "github.com/88250/gulu"
"github.com/dustin/go-humanize"
ants "github.com/panjf2000/ants/v2"
"github.com/siyuan-note/httpclient"
@@ -105,7 +104,7 @@ func InstalledWidgets() (ret []*Widget) {
ret = []*Widget{}
widgetsPath := filepath.Join(util.DataDir, "widgets")
- if !gulu.File.IsDir(widgetsPath) {
+ if !util.IsPathRegularDirOrSymlinkDir(widgetsPath) {
return
}
@@ -118,7 +117,7 @@ func InstalledWidgets() (ret []*Widget) {
bazaarWidgets := Widgets()
for _, widgetDir := range widgetDirs {
- if !widgetDir.IsDir() {
+ if !util.IsDirRegularOrSymlink(widgetDir) {
continue
}
dirName := widgetDir.Name()
diff --git a/kernel/model/appearance.go b/kernel/model/appearance.go
index 896bfd6a8d..c3f6f7a3ef 100644
--- a/kernel/model/appearance.go
+++ b/kernel/model/appearance.go
@@ -78,7 +78,7 @@ func closeThemeWatchers() {
}
func unloadThemes() {
- if !gulu.File.IsDir(util.ThemesPath) {
+ if !util.IsPathRegularDirOrSymlinkDir(util.ThemesPath) {
return
}
@@ -89,7 +89,7 @@ func unloadThemes() {
}
for _, themeDir := range themeDirs {
- if !themeDir.IsDir() {
+ if !util.IsDirRegularOrSymlink(themeDir) {
continue
}
unwatchTheme(filepath.Join(util.ThemesPath, themeDir.Name()))
@@ -107,7 +107,7 @@ func loadThemes() {
Conf.Appearance.DarkThemes = nil
Conf.Appearance.LightThemes = nil
for _, themeDir := range themeDirs {
- if !themeDir.IsDir() {
+ if !util.IsDirRegularOrSymlink(themeDir) {
continue
}
name := themeDir.Name()
@@ -151,7 +151,7 @@ func loadIcons() {
Conf.Appearance.Icons = nil
for _, iconDir := range iconDirs {
- if !iconDir.IsDir() {
+ if !util.IsDirRegularOrSymlink(iconDir) {
continue
}
name := iconDir.Name()
diff --git a/kernel/model/bazzar.go b/kernel/model/bazzar.go
index f133c15960..d24eeb4283 100644
--- a/kernel/model/bazzar.go
+++ b/kernel/model/bazzar.go
@@ -35,7 +35,7 @@ func GetPackageREADME(repoURL, repoHash, packageType string) (ret string) {
func BazaarPlugins() (plugins []*bazaar.Plugin) {
plugins = bazaar.Plugins()
for _, plugin := range plugins {
- plugin.Installed = gulu.File.IsDir(filepath.Join(util.DataDir, "plugins", plugin.Name))
+ plugin.Installed = util.IsPathRegularDirOrSymlinkDir(filepath.Join(util.DataDir, "plugins", plugin.Name))
if plugin.Installed {
if plugin.Installed {
if pluginConf, err := bazaar.PluginJSON(plugin.Name); nil == err && nil != plugin {
@@ -96,7 +96,7 @@ func UninstallBazaarPlugin(pluginName string) error {
func BazaarWidgets() (widgets []*bazaar.Widget) {
widgets = bazaar.Widgets()
for _, widget := range widgets {
- widget.Installed = gulu.File.IsDir(filepath.Join(util.DataDir, "widgets", widget.Name))
+ widget.Installed = util.IsPathRegularDirOrSymlinkDir(filepath.Join(util.DataDir, "widgets", widget.Name))
if widget.Installed {
if widget.Installed {
if widgetConf, err := bazaar.WidgetJSON(widget.Name); nil == err && nil != widget {
diff --git a/kernel/util/file.go b/kernel/util/file.go
index f6ef9b3ac9..ca6984d6fd 100644
--- a/kernel/util/file.go
+++ b/kernel/util/file.go
@@ -19,6 +19,7 @@ package util
import (
"bytes"
"io"
+ "io/fs"
"os"
"path"
"path/filepath"
@@ -42,6 +43,23 @@ func IsEmptyDir(p string) bool {
return 1 > len(files)
}
+func IsDirRegularOrSymlink(dir fs.DirEntry) bool {
+ return dir.IsDir() || dir.Type() == fs.ModeSymlink
+}
+
+func IsPathRegularDirOrSymlinkDir(path string) bool {
+ fio, err := os.Stat(path)
+ if os.IsNotExist(err) {
+ return false
+ }
+
+ if nil != err {
+ return false
+ }
+
+ return fio.IsDir()
+}
+
func RemoveID(name string) string {
ext := path.Ext(name)
name = strings.TrimSuffix(name, ext)