Fix shadowed variables in various places: Part 1 of 2 (#10175)
* Fix shadowed variables in cmd package * Fix shadowed variables in plugin package * Fix shadowed variables in store package * Fix shadowed variables in web package * Changes as requested Signed-off-by: Hanzei <hanzei@mailbox.org> * Fix build * Remove unnessary statements * Use require all the time * Fix build * Rename variables according to feedback * Fix NPE * Changes as requested
Этот коммит содержится в:
коммит произвёл
Jesse Hallam
родитель
2c9cf41dad
Коммит
d898787371
@@ -151,14 +151,14 @@ func (env *Environment) Activate(id string) (manifest *model.Manifest, activated
|
||||
return nil, false, fmt.Errorf("plugin not found: %v", id)
|
||||
}
|
||||
|
||||
activePlugin := activePlugin{BundleInfo: pluginInfo}
|
||||
ap := activePlugin{BundleInfo: pluginInfo}
|
||||
defer func() {
|
||||
if reterr == nil {
|
||||
activePlugin.State = model.PluginStateRunning
|
||||
ap.State = model.PluginStateRunning
|
||||
} else {
|
||||
activePlugin.State = model.PluginStateFailedToStart
|
||||
ap.State = model.PluginStateFailedToStart
|
||||
}
|
||||
env.activePlugins.Store(pluginInfo.Manifest.Id, activePlugin)
|
||||
env.activePlugins.Store(pluginInfo.Manifest.Id, ap)
|
||||
}()
|
||||
|
||||
if pluginInfo.Manifest.MinServerVersion != "" {
|
||||
@@ -211,11 +211,11 @@ func (env *Environment) Activate(id string) (manifest *model.Manifest, activated
|
||||
}
|
||||
|
||||
if pluginInfo.Manifest.HasServer() {
|
||||
supervisor, err := newSupervisor(pluginInfo, env.logger, env.newAPIImpl(pluginInfo.Manifest))
|
||||
sup, err := newSupervisor(pluginInfo, env.logger, env.newAPIImpl(pluginInfo.Manifest))
|
||||
if err != nil {
|
||||
return nil, false, errors.Wrapf(err, "unable to start plugin: %v", id)
|
||||
}
|
||||
activePlugin.supervisor = supervisor
|
||||
ap.supervisor = sup
|
||||
|
||||
componentActivated = true
|
||||
}
|
||||
@@ -236,12 +236,12 @@ func (env *Environment) Deactivate(id string) bool {
|
||||
|
||||
env.activePlugins.Delete(id)
|
||||
|
||||
activePlugin := p.(activePlugin)
|
||||
if activePlugin.supervisor != nil {
|
||||
if err := activePlugin.supervisor.Hooks().OnDeactivate(); err != nil {
|
||||
env.logger.Error("Plugin OnDeactivate() error", mlog.String("plugin_id", activePlugin.BundleInfo.Manifest.Id), mlog.Err(err))
|
||||
ap := p.(activePlugin)
|
||||
if ap.supervisor != nil {
|
||||
if err := ap.supervisor.Hooks().OnDeactivate(); err != nil {
|
||||
env.logger.Error("Plugin OnDeactivate() error", mlog.String("plugin_id", ap.BundleInfo.Manifest.Id), mlog.Err(err))
|
||||
}
|
||||
activePlugin.supervisor.Shutdown()
|
||||
ap.supervisor.Shutdown()
|
||||
}
|
||||
|
||||
return true
|
||||
@@ -250,13 +250,13 @@ func (env *Environment) Deactivate(id string) bool {
|
||||
// Shutdown deactivates all plugins and gracefully shuts down the environment.
|
||||
func (env *Environment) Shutdown() {
|
||||
env.activePlugins.Range(func(key, value interface{}) bool {
|
||||
activePlugin := value.(activePlugin)
|
||||
ap := value.(activePlugin)
|
||||
|
||||
if activePlugin.supervisor != nil {
|
||||
if err := activePlugin.supervisor.Hooks().OnDeactivate(); err != nil {
|
||||
env.logger.Error("Plugin OnDeactivate() error", mlog.String("plugin_id", activePlugin.BundleInfo.Manifest.Id), mlog.Err(err))
|
||||
if ap.supervisor != nil {
|
||||
if err := ap.supervisor.Hooks().OnDeactivate(); err != nil {
|
||||
env.logger.Error("Plugin OnDeactivate() error", mlog.String("plugin_id", ap.BundleInfo.Manifest.Id), mlog.Err(err))
|
||||
}
|
||||
activePlugin.supervisor.Shutdown()
|
||||
ap.supervisor.Shutdown()
|
||||
}
|
||||
|
||||
env.activePlugins.Delete(key)
|
||||
@@ -270,9 +270,9 @@ func (env *Environment) Shutdown() {
|
||||
// Consider using RunMultiPluginHook instead.
|
||||
func (env *Environment) HooksForPlugin(id string) (Hooks, error) {
|
||||
if p, ok := env.activePlugins.Load(id); ok {
|
||||
activePlugin := p.(activePlugin)
|
||||
if activePlugin.supervisor != nil {
|
||||
return activePlugin.supervisor.Hooks(), nil
|
||||
ap := p.(activePlugin)
|
||||
if ap.supervisor != nil {
|
||||
return ap.supervisor.Hooks(), nil
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,12 +285,12 @@ func (env *Environment) HooksForPlugin(id string) (Hooks, error) {
|
||||
// plugins is not specified.
|
||||
func (env *Environment) RunMultiPluginHook(hookRunnerFunc func(hooks Hooks) bool, hookId int) {
|
||||
env.activePlugins.Range(func(key, value interface{}) bool {
|
||||
activePlugin := value.(activePlugin)
|
||||
ap := value.(activePlugin)
|
||||
|
||||
if activePlugin.supervisor == nil || !activePlugin.supervisor.Implements(hookId) {
|
||||
if ap.supervisor == nil || !ap.supervisor.Implements(hookId) {
|
||||
return true
|
||||
}
|
||||
if !hookRunnerFunc(activePlugin.supervisor.Hooks()) {
|
||||
if !hookRunnerFunc(ap.supervisor.Hooks()) {
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/go-plugin"
|
||||
plugin "github.com/hashicorp/go-plugin"
|
||||
"github.com/mattermost/mattermost-server/mlog"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
)
|
||||
@@ -23,10 +23,10 @@ type supervisor struct {
|
||||
}
|
||||
|
||||
func newSupervisor(pluginInfo *model.BundleInfo, parentLogger *mlog.Logger, apiImpl API) (retSupervisor *supervisor, retErr error) {
|
||||
supervisor := supervisor{}
|
||||
sup := supervisor{}
|
||||
defer func() {
|
||||
if retErr != nil {
|
||||
supervisor.Shutdown()
|
||||
sup.Shutdown()
|
||||
}
|
||||
}()
|
||||
|
||||
@@ -53,7 +53,7 @@ func newSupervisor(pluginInfo *model.BundleInfo, parentLogger *mlog.Logger, apiI
|
||||
}
|
||||
executable = filepath.Join(pluginInfo.Path, executable)
|
||||
|
||||
supervisor.client = plugin.NewClient(&plugin.ClientConfig{
|
||||
sup.client = plugin.NewClient(&plugin.ClientConfig{
|
||||
HandshakeConfig: handshake,
|
||||
Plugins: pluginMap,
|
||||
Cmd: exec.Command(executable),
|
||||
@@ -63,7 +63,7 @@ func newSupervisor(pluginInfo *model.BundleInfo, parentLogger *mlog.Logger, apiI
|
||||
StartTimeout: time.Second * 3,
|
||||
})
|
||||
|
||||
rpcClient, err := supervisor.client.Client()
|
||||
rpcClient, err := sup.client.Client()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -73,24 +73,24 @@ func newSupervisor(pluginInfo *model.BundleInfo, parentLogger *mlog.Logger, apiI
|
||||
return nil, err
|
||||
}
|
||||
|
||||
supervisor.hooks = raw.(Hooks)
|
||||
sup.hooks = raw.(Hooks)
|
||||
|
||||
if impl, err := supervisor.hooks.Implemented(); err != nil {
|
||||
impl, err := sup.hooks.Implemented()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
for _, hookName := range impl {
|
||||
if hookId, ok := hookNameToId[hookName]; ok {
|
||||
supervisor.implemented[hookId] = true
|
||||
}
|
||||
}
|
||||
for _, hookName := range impl {
|
||||
if hookId, ok := hookNameToId[hookName]; ok {
|
||||
sup.implemented[hookId] = true
|
||||
}
|
||||
}
|
||||
|
||||
err = supervisor.Hooks().OnActivate()
|
||||
err = sup.Hooks().OnActivate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &supervisor, nil
|
||||
return &sup, nil
|
||||
}
|
||||
|
||||
func (sup *supervisor) Shutdown() {
|
||||
|
||||
Ссылка в новой задаче
Block a user