From 2e8f6511e8d845207eb3be2ced11fe7b80ca95e3 Mon Sep 17 00:00:00 2001 From: Jeffrey Chen <78434827+TCOTC@users.noreply.github.com> Date: Sun, 8 Mar 2026 18:29:15 +0800 Subject: [PATCH] :recycle: Plugin existence by plugin.json and cleanup persisted info (#17162) --- kernel/bazaar/installed.go | 2 +- kernel/model/plugin.go | 24 +++++------------------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/kernel/bazaar/installed.go b/kernel/bazaar/installed.go index 4314b1312..5b87c7a13 100644 --- a/kernel/bazaar/installed.go +++ b/kernel/bazaar/installed.go @@ -190,7 +190,7 @@ func loadBazaarInfo() (ret *BazaarInfo) { return } -// saveBazaarInfo 保存集市持久化信息(调用者需持有写锁) +// saveBazaarInfo 保存集市持久化信息(调用者需持有 bazaarInfoCacheLock 写锁) func saveBazaarInfo() { infoPath := filepath.Join(util.DataDir, "storage", "bazaar.json") diff --git a/kernel/model/plugin.go b/kernel/model/plugin.go index 7e7c208d5..e51496426 100644 --- a/kernel/model/plugin.go +++ b/kernel/model/plugin.go @@ -267,9 +267,12 @@ func getPetals() (ret []*Petal) { var tmp []*Petal pluginsDir := filepath.Join(util.DataDir, "plugins") for _, petal := range ret { - pluginPath := filepath.Join(pluginsDir, petal.Name) - if hasPluginFiles(pluginPath) { + pluginJSONPath := filepath.Join(pluginsDir, petal.Name, "plugin.json") + if filelock.IsExist(pluginJSONPath) { tmp = append(tmp, petal) + } else { + // 插件不存在时,删除对应的持久化信息 + bazaar.RemovePackageInfo("plugins", petal.Name) } } if len(tmp) != len(ret) { @@ -281,20 +284,3 @@ func getPetals() (ret []*Petal) { } return } - -// hasPluginFiles 检查插件安装目录是否存在且包含文件 -func hasPluginFiles(pluginPath string) bool { - if !filelock.IsExist(pluginPath) { - return false - } - entries, err := os.ReadDir(pluginPath) - if err != nil { - return false - } - for _, entry := range entries { - if !entry.IsDir() { - return true - } - } - return false -}