refactor(plugins): keep the superseded-copy cleanup beside the copy helpers

plugin_package.go was over the 800-line ceiling.
This commit is contained in:
yhh committed 2026-10-12 10:06:46 -07:00
1 parent 101e82b5bb
commit 6db92a8904
2 files changed
+29 -28

No files matched your search

+29
View File
@@ -5,6 +5,7 @@ import (
"path/filepath"
"runtime"
"slices"
"strings"
"reasonix/internal/ext/pluginpkg"
)
@@ -101,3 +102,31 @@ func syncPluginCopy(root string) error {
}
return nil
}
// A replacement published beside the old tree leaves that tree, and any earlier
// replacement, on disk so a watched directory cannot block it. Removing the
// plugin is when those are reclaimed; one that cannot be removed now is left
// for the next removal and does not fail an uninstall the registry already
// recorded.
func removeSupersededPluginCopies(reasonixHome, pluginsDir, name string) {
_ = os.RemoveAll(filepath.Join(pluginsDir, name))
entries, err := os.ReadDir(pluginsDir)
if err != nil {
return
}
// Another plugin's name may share the prefix, so a directory the registry
// still points at is never touched.
inUse := map[string]bool{}
if st, err := pluginpkg.LoadState(reasonixHome); err == nil {
for _, p := range st.Plugins {
inUse[filepath.Clean(pluginpkg.ResolveRoot(reasonixHome, p.Root))] = true
}
}
prefix := "." + name + ".staging-"
for _, entry := range entries {
path := filepath.Join(pluginsDir, entry.Name())
if entry.IsDir() && strings.HasPrefix(entry.Name(), prefix) && !inUse[filepath.Clean(path)] {
_ = os.RemoveAll(path)
}
}
}
@@ -759,34 +759,6 @@ func (t *Tool) applyRemovePluginPackage(_ request, act *action) error {
return nil
}
// A replacement published beside the old tree leaves that tree, and any earlier
// replacement, on disk so a watched directory cannot block it. Removing the
// plugin is when those are reclaimed; one that cannot be removed now is left
// for the next removal and does not fail an uninstall the registry already
// recorded.
func removeSupersededPluginCopies(reasonixHome, pluginsDir, name string) {
_ = os.RemoveAll(filepath.Join(pluginsDir, name))
entries, err := os.ReadDir(pluginsDir)
if err != nil {
return
}
// Another plugin's name may share the prefix, so a directory the registry
// still points at is never touched.
inUse := map[string]bool{}
if st, err := pluginpkg.LoadState(reasonixHome); err == nil {
for _, p := range st.Plugins {
inUse[filepath.Clean(pluginpkg.ResolveRoot(reasonixHome, p.Root))] = true
}
}
prefix := "." + name + ".staging-"
for _, entry := range entries {
path := filepath.Join(pluginsDir, entry.Name())
if entry.IsDir() && strings.HasPrefix(entry.Name(), prefix) && !inUse[filepath.Clean(path)] {
_ = os.RemoveAll(path)
}
}
}
func removePluginSymlink(target, source string) error {
info, err := os.Lstat(target)
if os.IsNotExist(err) {