(filePath string, requiredExtension string)
| 386 | } |
| 387 | |
| 388 | func pluginFileFromPath(filePath string, requiredExtension string) (pluginFileInfo, bool) { |
| 389 | base := filepath.Base(filePath) |
| 390 | lowerBase := strings.ToLower(base) |
| 391 | extension := strings.TrimSpace(requiredExtension) |
| 392 | if extension != "" { |
| 393 | if !strings.HasSuffix(lowerBase, strings.ToLower(extension)) { |
| 394 | return pluginFileInfo{}, false |
| 395 | } |
| 396 | } else { |
| 397 | for _, candidateExtension := range []string{".so", ".dylib", ".dll"} { |
| 398 | if strings.HasSuffix(lowerBase, candidateExtension) { |
| 399 | extension = candidateExtension |
| 400 | break |
| 401 | } |
| 402 | } |
| 403 | if extension == "" { |
| 404 | return pluginFileInfo{}, false |
| 405 | } |
| 406 | } |
| 407 | name := base[:len(base)-len(extension)] |
| 408 | id := name |
| 409 | version := "" |
| 410 | if versionIndex := strings.LastIndex(name, "-v"); versionIndex > 0 { |
| 411 | candidateID := name[:versionIndex] |
| 412 | candidateVersion := name[versionIndex+2:] |
| 413 | if validPluginFileID(candidateID) && validPluginFileVersion(candidateVersion) { |
| 414 | id = candidateID |
| 415 | version = candidateVersion |
| 416 | } |
| 417 | } |
| 418 | if !validPluginFileID(id) { |
| 419 | return pluginFileInfo{}, false |
| 420 | } |
| 421 | return pluginFileInfo{ID: id, Path: filePath, Version: version}, true |
| 422 | } |
| 423 | |
| 424 | func pluginFilePreferred(candidate pluginFileInfo, current pluginFileInfo) bool { |
| 425 | if strings.TrimSpace(current.Path) == "" { |
no test coverage detected