Error if duplicate plugin id is loaded (#4571)

* Error if duplicate plugin id is loaded
* Use case insensitive comparison
This commit is contained in:
WithoutPants 2024-02-19 13:55:52 +11:00 committed by GitHub
parent 93b851eae6
commit afd7f02644
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -14,6 +14,7 @@ import (
"os"
"path/filepath"
"strconv"
"strings"
"github.com/stashapp/stash/pkg/fsutil"
"github.com/stashapp/stash/pkg/logger"
@ -128,16 +129,25 @@ func (c *Cache) RegisterSessionStore(sessionStore *session.Store) {
// If a plugin cannot be loaded, an error is logged and the plugin is skipped.
func (c *Cache) ReloadPlugins() {
path := c.config.GetPluginsPath()
// # 4484 - ensure plugin ids are unique
plugins := make([]Config, 0)
pluginIDs := make(map[string]bool)
logger.Debugf("Reading plugin configs from %s", path)
err := fsutil.SymWalk(path, func(fp string, f os.FileInfo, err error) error {
if filepath.Ext(fp) == ".yml" {
plugin, err := loadPluginFromYAMLFile(fp)
// use case insensitive plugin IDs
pluginID := strings.ToLower(plugin.id)
if err != nil {
logger.Errorf("Error loading plugin %s: %v", fp, err)
} else {
if _, exists := pluginIDs[pluginID]; exists {
logger.Errorf("Error loading plugin %s: plugin ID %s already exists", fp, plugin.id)
return nil
}
pluginIDs[pluginID] = true
plugins = append(plugins, *plugin)
}
}