mirror of
https://github.com/stashapp/stash.git
synced 2025-12-16 20:07:05 +03:00
Error if duplicate plugin id is loaded (#4571)
* Error if duplicate plugin id is loaded * Use case insensitive comparison
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/stashapp/stash/pkg/fsutil"
|
"github.com/stashapp/stash/pkg/fsutil"
|
||||||
"github.com/stashapp/stash/pkg/logger"
|
"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.
|
// If a plugin cannot be loaded, an error is logged and the plugin is skipped.
|
||||||
func (c *Cache) ReloadPlugins() {
|
func (c *Cache) ReloadPlugins() {
|
||||||
path := c.config.GetPluginsPath()
|
path := c.config.GetPluginsPath()
|
||||||
|
// # 4484 - ensure plugin ids are unique
|
||||||
plugins := make([]Config, 0)
|
plugins := make([]Config, 0)
|
||||||
|
pluginIDs := make(map[string]bool)
|
||||||
|
|
||||||
logger.Debugf("Reading plugin configs from %s", path)
|
logger.Debugf("Reading plugin configs from %s", path)
|
||||||
|
|
||||||
err := fsutil.SymWalk(path, func(fp string, f os.FileInfo, err error) error {
|
err := fsutil.SymWalk(path, func(fp string, f os.FileInfo, err error) error {
|
||||||
if filepath.Ext(fp) == ".yml" {
|
if filepath.Ext(fp) == ".yml" {
|
||||||
plugin, err := loadPluginFromYAMLFile(fp)
|
plugin, err := loadPluginFromYAMLFile(fp)
|
||||||
|
// use case insensitive plugin IDs
|
||||||
|
pluginID := strings.ToLower(plugin.id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Errorf("Error loading plugin %s: %v", fp, err)
|
logger.Errorf("Error loading plugin %s: %v", fp, err)
|
||||||
} else {
|
} 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)
|
plugins = append(plugins, *plugin)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user