mirror of
https://github.com/esengine/DeepSeek-Reasonix.git
synced 2026-11-07 10:45:59 -10:00
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:
1 parent
101e82b5bb
commit
6db92a8904
2 files changed
+29
-28
No files matched your search
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user