mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 07:00:12 +01:00
🎨 搜索资源文件支持跟随 assets 文件夹符号链接 Fix https://github.com/siyuan-note/siyuan/issues/6217
This commit is contained in:
parent
a00e25cd1e
commit
56128b9cb7
3 changed files with 22 additions and 28 deletions
4
kernel/cache/asset.go
vendored
4
kernel/cache/asset.go
vendored
|
|
@ -43,7 +43,7 @@ func LoadAssets() {
|
||||||
assetsLock.Lock()
|
assetsLock.Lock()
|
||||||
defer assetsLock.Unlock()
|
defer assetsLock.Unlock()
|
||||||
|
|
||||||
assets := filepath.Join(util.DataDir, "assets")
|
assets := util.GetDataAssetsAbsPath()
|
||||||
filepath.Walk(assets, func(path string, info fs.FileInfo, err error) error {
|
filepath.Walk(assets, func(path string, info fs.FileInfo, err error) error {
|
||||||
if nil == info {
|
if nil == info {
|
||||||
return err
|
return err
|
||||||
|
|
@ -59,7 +59,7 @@ func LoadAssets() {
|
||||||
}
|
}
|
||||||
|
|
||||||
hName := util.RemoveID(info.Name())
|
hName := util.RemoveID(info.Name())
|
||||||
path = filepath.ToSlash(strings.TrimPrefix(path, util.DataDir))[1:]
|
path = "assets" + filepath.ToSlash(strings.TrimPrefix(path, assets))
|
||||||
Assets[path] = &Asset{
|
Assets[path] = &Asset{
|
||||||
HName: hName,
|
HName: hName,
|
||||||
Path: path,
|
Path: path,
|
||||||
|
|
|
||||||
|
|
@ -632,11 +632,7 @@ func UnusedAssets() (ret []string) {
|
||||||
delete(assetsPathMap, toRemove)
|
delete(assetsPathMap, toRemove)
|
||||||
}
|
}
|
||||||
|
|
||||||
dataAssetsAbsPath, err := getDataAssetsAbsPath()
|
dataAssetsAbsPath := util.GetDataAssetsAbsPath()
|
||||||
if nil != err {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, assetAbsPath := range assetsPathMap {
|
for _, assetAbsPath := range assetsPathMap {
|
||||||
if _, ok := linkDestMap[assetAbsPath]; ok {
|
if _, ok := linkDestMap[assetAbsPath]; ok {
|
||||||
continue
|
continue
|
||||||
|
|
@ -794,10 +790,7 @@ func allAssetAbsPaths() (assetsAbsPathMap map[string]string, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 全局 assets
|
// 全局 assets
|
||||||
dataAssetsAbsPath, err := getDataAssetsAbsPath()
|
dataAssetsAbsPath := util.GetDataAssetsAbsPath()
|
||||||
if nil != err {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
filepath.Walk(dataAssetsAbsPath, func(assetPath string, info fs.FileInfo, err error) error {
|
filepath.Walk(dataAssetsAbsPath, func(assetPath string, info fs.FileInfo, err error) error {
|
||||||
if dataAssetsAbsPath == assetPath {
|
if dataAssetsAbsPath == assetPath {
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -863,20 +856,3 @@ func copyAssetsToDataAssets(rootPath string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDataAssetsAbsPath() (ret string, err error) {
|
|
||||||
ret = filepath.Join(util.DataDir, "assets")
|
|
||||||
stat, statErr := os.Lstat(ret)
|
|
||||||
if nil != statErr {
|
|
||||||
err = statErr
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if 0 != stat.Mode()&os.ModeSymlink {
|
|
||||||
// 跟随符号链接 https://github.com/siyuan-note/siyuan/issues/5480
|
|
||||||
ret, err = os.Readlink(ret)
|
|
||||||
if nil != err {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -534,3 +534,21 @@ func IsValidPandocBin(binPath string) bool {
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetDataAssetsAbsPath() (ret string) {
|
||||||
|
ret = filepath.Join(DataDir, "assets")
|
||||||
|
var err error
|
||||||
|
stat, err := os.Lstat(ret)
|
||||||
|
if nil != err {
|
||||||
|
logging.LogErrorf("stat assets failed: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if 0 != stat.Mode()&os.ModeSymlink {
|
||||||
|
// 跟随符号链接 https://github.com/siyuan-note/siyuan/issues/5480
|
||||||
|
ret, err = os.Readlink(ret)
|
||||||
|
if nil != err {
|
||||||
|
logging.LogErrorf("read assets link failed: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue