From 56128b9cb7cf488a39443e887c328e30993fc4a5 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Sun, 16 Oct 2022 14:15:42 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E6=90=9C=E7=B4=A2=E8=B5=84=E6=BA=90?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E6=94=AF=E6=8C=81=E8=B7=9F=E9=9A=8F=20assets?= =?UTF-8?q?=20=E6=96=87=E4=BB=B6=E5=A4=B9=E7=AC=A6=E5=8F=B7=E9=93=BE?= =?UTF-8?q?=E6=8E=A5=20Fix=20https://github.com/siyuan-note/siyuan/issues/?= =?UTF-8?q?6217?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/cache/asset.go | 4 ++-- kernel/model/assets.go | 28 ++-------------------------- kernel/util/working.go | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+), 28 deletions(-) diff --git a/kernel/cache/asset.go b/kernel/cache/asset.go index 0ed480d8b..bf9d2368b 100644 --- a/kernel/cache/asset.go +++ b/kernel/cache/asset.go @@ -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, diff --git a/kernel/model/assets.go b/kernel/model/assets.go index cf0f5dc28..1f6fdb148 100644 --- a/kernel/model/assets.go +++ b/kernel/model/assets.go @@ -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 -} diff --git a/kernel/util/working.go b/kernel/util/working.go index 63d6e7b24..7ba3d7f68 100644 --- a/kernel/util/working.go +++ b/kernel/util/working.go @@ -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 +}