♻️ Plugin existence by plugin.json and cleanup persisted info (#17162)

This commit is contained in:
Jeffrey Chen 2026-03-08 18:29:15 +08:00 committed by GitHub
parent 82e552aafc
commit 2e8f6511e8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 20 deletions

View file

@ -190,7 +190,7 @@ func loadBazaarInfo() (ret *BazaarInfo) {
return
}
// saveBazaarInfo 保存集市持久化信息(调用者需持有写锁)
// saveBazaarInfo 保存集市持久化信息(调用者需持有 bazaarInfoCacheLock 写锁)
func saveBazaarInfo() {
infoPath := filepath.Join(util.DataDir, "storage", "bazaar.json")

View file

@ -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
}