Bazaar resource directories support symlink (#8263)

* 🎨 bazaar resource directories support symlink

* 🎨 bazaar resource directories support symlink
This commit is contained in:
颖逸 2023-05-16 10:34:38 +08:00 committed by GitHub
parent 85496345ef
commit fdbfe6b848
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 38 additions and 19 deletions

View file

@ -101,6 +101,11 @@ func Icons() (icons []*Icon) {
func InstalledIcons() (ret []*Icon) { func InstalledIcons() (ret []*Icon) {
ret = []*Icon{} ret = []*Icon{}
if !util.IsPathRegularDirOrSymlinkDir(util.IconsPath) {
return
}
iconDirs, err := os.ReadDir(util.IconsPath) iconDirs, err := os.ReadDir(util.IconsPath)
if nil != err { if nil != err {
logging.LogWarnf("read icons folder failed: %s", err) logging.LogWarnf("read icons folder failed: %s", err)
@ -110,7 +115,7 @@ func InstalledIcons() (ret []*Icon) {
bazaarIcons := Icons() bazaarIcons := Icons()
for _, iconDir := range iconDirs { for _, iconDir := range iconDirs {
if !iconDir.IsDir() { if !util.IsDirRegularOrSymlink(iconDir) {
continue continue
} }
dirName := iconDir.Name() dirName := iconDir.Name()

View file

@ -24,7 +24,6 @@ import (
"strings" "strings"
"sync" "sync"
"github.com/88250/gulu"
"github.com/dustin/go-humanize" "github.com/dustin/go-humanize"
ants "github.com/panjf2000/ants/v2" ants "github.com/panjf2000/ants/v2"
"github.com/siyuan-note/httpclient" "github.com/siyuan-note/httpclient"
@ -106,7 +105,7 @@ func InstalledPlugins() (ret []*Plugin) {
ret = []*Plugin{} ret = []*Plugin{}
pluginsPath := filepath.Join(util.DataDir, "plugins") pluginsPath := filepath.Join(util.DataDir, "plugins")
if !gulu.File.IsDir(pluginsPath) { if !util.IsPathRegularDirOrSymlinkDir(pluginsPath) {
return return
} }
@ -119,7 +118,7 @@ func InstalledPlugins() (ret []*Plugin) {
bazaarPlugins := Plugins() bazaarPlugins := Plugins()
for _, pluginDir := range pluginDirs { for _, pluginDir := range pluginDirs {
if !pluginDir.IsDir() { if !util.IsDirRegularOrSymlink(pluginDir) {
continue continue
} }
dirName := pluginDir.Name() dirName := pluginDir.Name()

View file

@ -25,7 +25,6 @@ import (
"sync" "sync"
"time" "time"
"github.com/88250/gulu"
"github.com/dustin/go-humanize" "github.com/dustin/go-humanize"
"github.com/panjf2000/ants/v2" "github.com/panjf2000/ants/v2"
"github.com/siyuan-note/httpclient" "github.com/siyuan-note/httpclient"
@ -107,7 +106,7 @@ func InstalledTemplates() (ret []*Template) {
ret = []*Template{} ret = []*Template{}
templatesPath := filepath.Join(util.DataDir, "templates") templatesPath := filepath.Join(util.DataDir, "templates")
if !gulu.File.IsDir(templatesPath) { if !util.IsPathRegularDirOrSymlinkDir(templatesPath) {
return return
} }
@ -120,7 +119,7 @@ func InstalledTemplates() (ret []*Template) {
bazaarTemplates := Templates() bazaarTemplates := Templates()
for _, templateDir := range templateDirs { for _, templateDir := range templateDirs {
if !templateDir.IsDir() { if !util.IsDirRegularOrSymlink(templateDir) {
continue continue
} }
dirName := templateDir.Name() dirName := templateDir.Name()

View file

@ -24,7 +24,6 @@ import (
"strings" "strings"
"sync" "sync"
"github.com/88250/gulu"
"github.com/dustin/go-humanize" "github.com/dustin/go-humanize"
ants "github.com/panjf2000/ants/v2" ants "github.com/panjf2000/ants/v2"
"github.com/siyuan-note/httpclient" "github.com/siyuan-note/httpclient"
@ -105,7 +104,7 @@ func Themes() (ret []*Theme) {
func InstalledThemes() (ret []*Theme) { func InstalledThemes() (ret []*Theme) {
ret = []*Theme{} ret = []*Theme{}
if !gulu.File.IsDir(util.ThemesPath) { if !util.IsPathRegularDirOrSymlinkDir(util.ThemesPath) {
return return
} }
@ -118,7 +117,7 @@ func InstalledThemes() (ret []*Theme) {
bazaarThemes := Themes() bazaarThemes := Themes()
for _, themeDir := range themeDirs { for _, themeDir := range themeDirs {
if !themeDir.IsDir() { if !util.IsDirRegularOrSymlink(themeDir) {
continue continue
} }
dirName := themeDir.Name() dirName := themeDir.Name()

View file

@ -24,7 +24,6 @@ import (
"strings" "strings"
"sync" "sync"
"github.com/88250/gulu"
"github.com/dustin/go-humanize" "github.com/dustin/go-humanize"
ants "github.com/panjf2000/ants/v2" ants "github.com/panjf2000/ants/v2"
"github.com/siyuan-note/httpclient" "github.com/siyuan-note/httpclient"
@ -105,7 +104,7 @@ func InstalledWidgets() (ret []*Widget) {
ret = []*Widget{} ret = []*Widget{}
widgetsPath := filepath.Join(util.DataDir, "widgets") widgetsPath := filepath.Join(util.DataDir, "widgets")
if !gulu.File.IsDir(widgetsPath) { if !util.IsPathRegularDirOrSymlinkDir(widgetsPath) {
return return
} }
@ -118,7 +117,7 @@ func InstalledWidgets() (ret []*Widget) {
bazaarWidgets := Widgets() bazaarWidgets := Widgets()
for _, widgetDir := range widgetDirs { for _, widgetDir := range widgetDirs {
if !widgetDir.IsDir() { if !util.IsDirRegularOrSymlink(widgetDir) {
continue continue
} }
dirName := widgetDir.Name() dirName := widgetDir.Name()

View file

@ -78,7 +78,7 @@ func closeThemeWatchers() {
} }
func unloadThemes() { func unloadThemes() {
if !gulu.File.IsDir(util.ThemesPath) { if !util.IsPathRegularDirOrSymlinkDir(util.ThemesPath) {
return return
} }
@ -89,7 +89,7 @@ func unloadThemes() {
} }
for _, themeDir := range themeDirs { for _, themeDir := range themeDirs {
if !themeDir.IsDir() { if !util.IsDirRegularOrSymlink(themeDir) {
continue continue
} }
unwatchTheme(filepath.Join(util.ThemesPath, themeDir.Name())) unwatchTheme(filepath.Join(util.ThemesPath, themeDir.Name()))
@ -107,7 +107,7 @@ func loadThemes() {
Conf.Appearance.DarkThemes = nil Conf.Appearance.DarkThemes = nil
Conf.Appearance.LightThemes = nil Conf.Appearance.LightThemes = nil
for _, themeDir := range themeDirs { for _, themeDir := range themeDirs {
if !themeDir.IsDir() { if !util.IsDirRegularOrSymlink(themeDir) {
continue continue
} }
name := themeDir.Name() name := themeDir.Name()
@ -151,7 +151,7 @@ func loadIcons() {
Conf.Appearance.Icons = nil Conf.Appearance.Icons = nil
for _, iconDir := range iconDirs { for _, iconDir := range iconDirs {
if !iconDir.IsDir() { if !util.IsDirRegularOrSymlink(iconDir) {
continue continue
} }
name := iconDir.Name() name := iconDir.Name()

View file

@ -35,7 +35,7 @@ func GetPackageREADME(repoURL, repoHash, packageType string) (ret string) {
func BazaarPlugins() (plugins []*bazaar.Plugin) { func BazaarPlugins() (plugins []*bazaar.Plugin) {
plugins = bazaar.Plugins() plugins = bazaar.Plugins()
for _, plugin := range 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 plugin.Installed { if plugin.Installed {
if pluginConf, err := bazaar.PluginJSON(plugin.Name); nil == err && nil != plugin { 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) { func BazaarWidgets() (widgets []*bazaar.Widget) {
widgets = bazaar.Widgets() widgets = bazaar.Widgets()
for _, widget := range 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 widget.Installed { if widget.Installed {
if widgetConf, err := bazaar.WidgetJSON(widget.Name); nil == err && nil != widget { if widgetConf, err := bazaar.WidgetJSON(widget.Name); nil == err && nil != widget {

View file

@ -19,6 +19,7 @@ package util
import ( import (
"bytes" "bytes"
"io" "io"
"io/fs"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
@ -42,6 +43,23 @@ func IsEmptyDir(p string) bool {
return 1 > len(files) 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 { func RemoveID(name string) string {
ext := path.Ext(name) ext := path.Ext(name)
name = strings.TrimSuffix(name, ext) name = strings.TrimSuffix(name, ext)