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

Function pluginFileInfos

internal/homeplugins/sync.go:302–358  ·  view source on GitHub ↗
(root string, id string)

Source from the content-addressed store, hash-verified

300}
301
302func pluginFileInfos(root string, id string) ([]pluginFileInfo, error) {
303 root = strings.TrimSpace(root)
304 if root == "" {
305 root = "plugins"
306 }
307 id = strings.TrimSpace(id)
308 platform := CurrentPlatform()
309 extension := pluginExtension(platform.GOOS)
310 candidates := make([]pluginFileInfo, 0)
311 for _, dir := range pluginCandidateDirs(root, platform.GOOS, platform.GOARCH) {
312 entries, errReadDir := os.ReadDir(dir)
313 if errReadDir != nil {
314 if errors.Is(errReadDir, os.ErrNotExist) {
315 continue
316 }
317 return nil, errReadDir
318 }
319 files := make([]string, 0, len(entries))
320 for _, entry := range entries {
321 if entry == nil || !entry.Type().IsRegular() {
322 continue
323 }
324 if strings.HasSuffix(strings.ToLower(entry.Name()), extension) {
325 files = append(files, filepath.Join(dir, entry.Name()))
326 }
327 }
328 sort.Strings(files)
329 for _, filePath := range files {
330 file, okFile := pluginFileFromPath(filePath, extension)
331 if !okFile || file.ID != id {
332 continue
333 }
334 candidates = append(candidates, file)
335 }
336 }
337 if len(candidates) <= 1 {
338 return candidates, nil
339 }
340 bestIndex := 0
341 for index := 1; index < len(candidates); index++ {
342 if pluginFilePreferred(candidates[index], candidates[bestIndex]) {
343 bestIndex = index
344 }
345 }
346 if bestIndex == 0 {
347 return candidates, nil
348 }
349 out := make([]pluginFileInfo, 0, len(candidates))
350 out = append(out, candidates[bestIndex])
351 for index, candidate := range candidates {
352 if index == bestIndex {
353 continue
354 }
355 out = append(out, candidate)
356 }
357 return out, nil
358}
359

Callers 1

pluginFilePathsFunction · 0.85

Calls 6

CurrentPlatformFunction · 0.85
pluginExtensionFunction · 0.70
pluginCandidateDirsFunction · 0.70
pluginFileFromPathFunction · 0.70
pluginFilePreferredFunction · 0.70
NameMethod · 0.65

Tested by

no test coverage detected