MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / cleanupUnselectedPluginFiles

Function cleanupUnselectedPluginFiles

internal/pluginhost/platform.go:252–289  ·  view source on GitHub ↗
(root string, loaded []pluginFile)

Source from the content-addressed store, hash-verified

250}
251
252func cleanupUnselectedPluginFiles(root string, loaded []pluginFile) error {
253 if len(loaded) == 0 {
254 return nil
255 }
256 _, candidates, errSelect := selectPluginFilesWithCandidates(root)
257 if errSelect != nil {
258 return errSelect
259 }
260 loadedByID := make(map[string]map[string]struct{}, len(loaded))
261 for _, file := range loaded {
262 if strings.TrimSpace(file.ID) == "" || strings.TrimSpace(file.Path) == "" {
263 continue
264 }
265 paths := loadedByID[file.ID]
266 if paths == nil {
267 paths = make(map[string]struct{})
268 loadedByID[file.ID] = paths
269 }
270 paths[filepath.Clean(file.Path)] = struct{}{}
271 }
272 var errs []error
273 for _, candidate := range candidates {
274 paths := loadedByID[candidate.ID]
275 if len(paths) == 0 {
276 continue
277 }
278 if _, selected := paths[filepath.Clean(candidate.Path)]; selected {
279 continue
280 }
281 if errRemove := os.Remove(candidate.Path); errRemove != nil && !errors.Is(errRemove, os.ErrNotExist) {
282 errs = append(errs, errRemove)
283 log.WithError(errRemove).Warnf("pluginhost: failed to remove old plugin file %s", candidate.Path)
284 continue
285 }
286 log.WithFields(pluginLogFields(candidate.ID, "", candidate.Version, candidate.Path)).Info("pluginhost: old plugin file removed")
287 }
288 return errors.Join(errs...)
289}
290
291// DiscoverPluginFiles returns plugin binaries selected by the current host discovery rules.
292func DiscoverPluginFiles(root string, desiredVersions ...map[string]string) ([]PluginFileInfo, error) {

Callers 1

ApplyConfigMethod · 0.85

Calls 3

pluginLogFieldsFunction · 0.85
RemoveMethod · 0.80

Tested by

no test coverage detected