🎨 搜索资源文件支持跟随 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()
|
||||
defer assetsLock.Unlock()
|
||||
|
||||
assets := filepath.Join(util.DataDir, "assets")
|
||||
assets := util.GetDataAssetsAbsPath()
|
||||
filepath.Walk(assets, func(path string, info fs.FileInfo, err error) error {
|
||||
if nil == info {
|
||||
return err
|
||||
|
@ -59,7 +59,7 @@ func LoadAssets() {
|
|||
}
|
||||
|
||||
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{
|
||||
HName: hName,
|
||||
Path: path,
|
||||
|
|
|
@ -632,11 +632,7 @@ func UnusedAssets() (ret []string) {
|
|||
delete(assetsPathMap, toRemove)
|
||||
}
|
||||
|
||||
dataAssetsAbsPath, err := getDataAssetsAbsPath()
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
|
||||
dataAssetsAbsPath := util.GetDataAssetsAbsPath()
|
||||
for _, assetAbsPath := range assetsPathMap {
|
||||
if _, ok := linkDestMap[assetAbsPath]; ok {
|
||||
continue
|
||||
|
@ -794,10 +790,7 @@ func allAssetAbsPaths() (assetsAbsPathMap map[string]string, err error) {
|
|||
}
|
||||
|
||||
// 全局 assets
|
||||
dataAssetsAbsPath, err := getDataAssetsAbsPath()
|
||||
if nil != err {
|
||||
return
|
||||
}
|
||||
dataAssetsAbsPath := util.GetDataAssetsAbsPath()
|
||||
filepath.Walk(dataAssetsAbsPath, func(assetPath string, info fs.FileInfo, err error) error {
|
||||
if dataAssetsAbsPath == assetPath {
|
||||
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
|
||||
}
|
||||
|
||||
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
Reference in a new issue