diff --git a/kernel/model/assets.go b/kernel/model/assets.go index 601d48b13..32b89f0e4 100644 --- a/kernel/model/assets.go +++ b/kernel/model/assets.go @@ -65,11 +65,19 @@ func GetAssetPathByHash(hash string) string { } func HandleAssetsRemoveEvent(assetAbsPath string) { + if !filelock.IsExist(assetAbsPath) { + return + } + removeIndexAssetContent(assetAbsPath) removeAssetThumbnail(assetAbsPath) } func HandleAssetsChangeEvent(assetAbsPath string) { + if !filelock.IsExist(assetAbsPath) { + return + } + indexAssetContent(assetAbsPath) removeAssetThumbnail(assetAbsPath) } @@ -694,7 +702,11 @@ func RemoveUnusedAssets() (ret []string) { util.PushErrMsg(fmt.Sprintf("%s", removeErr), 7000) return } + util.RemoveAssetText(unusedAsset) + if !isFileWatcherAvailable() { + HandleAssetsRemoveEvent(absPath) + } } ret = append(ret, absPath) } @@ -739,6 +751,9 @@ func RemoveUnusedAsset(p string) (ret string) { ret = absPath util.RemoveAssetText(p) + if !isFileWatcherAvailable() { + HandleAssetsRemoveEvent(absPath) + } IncSync() diff --git a/kernel/model/assets_watcher.go b/kernel/model/assets_watcher.go index 5a9953d2a..a7d1b7ed9 100644 --- a/kernel/model/assets_watcher.go +++ b/kernel/model/assets_watcher.go @@ -30,10 +30,14 @@ import ( "github.com/siyuan-note/siyuan/kernel/util" ) +func isFileWatcherAvailable() bool { + return util.ContainerAndroid != util.Container && util.ContainerIOS != util.Container && util.ContainerHarmony != util.Container +} + var assetsWatcher *fsnotify.Watcher func WatchAssets() { - if util.ContainerAndroid == util.Container || util.ContainerIOS == util.Container || util.ContainerHarmony == util.Container { + if !isFileWatcherAvailable() { return } diff --git a/kernel/model/repository.go b/kernel/model/repository.go index 830663c33..e7486ac18 100644 --- a/kernel/model/repository.go +++ b/kernel/model/repository.go @@ -1635,6 +1635,11 @@ func processSyncMergeResult(exit, byHand bool, mergeResult *dejavu.MergeResult, if strings.HasSuffix(file.Path, ".sy") { upsertTrees++ } + + if !isFileWatcherAvailable() && strings.HasPrefix(file.Path, "/assets/") { + absPath := filepath.Join(util.DataDir, file.Path) + HandleAssetsChangeEvent(absPath) + } } removeWidgetDirSet, unloadPluginSet, uninstallPluginSet := hashset.New(), hashset.New(), hashset.New() @@ -1676,6 +1681,11 @@ func processSyncMergeResult(exit, byHand bool, mergeResult *dejavu.MergeResult, removeWidgetDirSet.Add(parts[2]) } } + + if !isFileWatcherAvailable() && strings.HasPrefix(file.Path, "/assets/") { + absPath := filepath.Join(util.DataDir, file.Path) + HandleAssetsRemoveEvent(absPath) + } } for _, upsertPetal := range mergeResult.UpsertPetals {