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

Function pluginFileInfoFromPath

internal/pluginstore/install.go:472–506  ·  view source on GitHub ↗
(filePath string, requiredExtension string)

Source from the content-addressed store, hash-verified

470}
471
472func pluginFileInfoFromPath(filePath string, requiredExtension string) (pluginFileInfo, bool) {
473 base := filepath.Base(filePath)
474 lowerBase := strings.ToLower(base)
475 extension := strings.TrimSpace(requiredExtension)
476 if extension != "" {
477 if !strings.HasSuffix(lowerBase, strings.ToLower(extension)) {
478 return pluginFileInfo{}, false
479 }
480 } else {
481 for _, candidateExtension := range []string{".so", ".dylib", ".dll"} {
482 if strings.HasSuffix(lowerBase, candidateExtension) {
483 extension = candidateExtension
484 break
485 }
486 }
487 if extension == "" {
488 return pluginFileInfo{}, false
489 }
490 }
491 name := base[:len(base)-len(extension)]
492 id := name
493 version := ""
494 if versionIndex := strings.LastIndex(name, "-v"); versionIndex > 0 {
495 candidateID := name[:versionIndex]
496 candidateVersion := name[versionIndex+2:]
497 if validPluginID(candidateID) && validPluginVersion(candidateVersion) {
498 id = candidateID
499 version = candidateVersion
500 }
501 }
502 if !validPluginID(id) {
503 return pluginFileInfo{}, false
504 }
505 return pluginFileInfo{ID: id, Path: filePath, Version: version}, true
506}
507
508func pluginExtension(goos string) string {
509 switch strings.ToLower(strings.TrimSpace(goos)) {

Callers 2

pluginIDFromPathFunction · 0.85

Calls 2

validPluginIDFunction · 0.70
validPluginVersionFunction · 0.70

Tested by

no test coverage detected