Skip to content

Commit

Permalink
Bazaar resource directories support symlink (#8263)
Browse files Browse the repository at this point in the history
* 🎨 bazaar resource directories support symlink

* 🎨 bazaar resource directories support symlink
  • Loading branch information
Zuoqiu-Yingyi committed May 16, 2023
1 parent 8549634 commit fdbfe6b
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 19 deletions.
7 changes: 6 additions & 1 deletion kernel/bazaar/icon.go
Expand Up @@ -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)
Expand All @@ -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()
Expand Down
5 changes: 2 additions & 3 deletions kernel/bazaar/plugin.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand All @@ -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()
Expand Down
5 changes: 2 additions & 3 deletions kernel/bazaar/template.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand All @@ -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()
Expand Down
5 changes: 2 additions & 3 deletions kernel/bazaar/theme.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand All @@ -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()
Expand Down
5 changes: 2 additions & 3 deletions kernel/bazaar/widget.go
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand All @@ -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()
Expand Down
8 changes: 4 additions & 4 deletions kernel/model/appearance.go
Expand Up @@ -78,7 +78,7 @@ func closeThemeWatchers() {
}

func unloadThemes() {
if !gulu.File.IsDir(util.ThemesPath) {
if !util.IsPathRegularDirOrSymlinkDir(util.ThemesPath) {
return
}

Expand All @@ -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()))
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions kernel/model/bazzar.go
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
18 changes: 18 additions & 0 deletions kernel/util/file.go
Expand Up @@ -19,6 +19,7 @@ package util
import (
"bytes"
"io"
"io/fs"
"os"
"path"
"path/filepath"
Expand All @@ -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)
Expand Down

0 comments on commit fdbfe6b

Please sign in to comment.