diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/plugin.go | 21 | ||||
-rw-r--r-- | app/plugin_install.go | 14 |
2 files changed, 31 insertions, 4 deletions
diff --git a/app/plugin.go b/app/plugin.go index 8fce76f39..8838e31a9 100644 --- a/app/plugin.go +++ b/app/plugin.go @@ -6,11 +6,13 @@ package app import ( "net/http" "os" + "path/filepath" "strings" "github.com/mattermost/mattermost-server/mlog" "github.com/mattermost/mattermost-server/model" "github.com/mattermost/mattermost-server/plugin" + "github.com/mattermost/mattermost-server/utils" ) func (a *App) SyncPluginsActiveState() { @@ -101,6 +103,25 @@ func (a *App) InitPlugins(pluginDir, webappPluginDir string) { a.Plugins = env } + prepackagedPluginsDir, found := utils.FindDir("prepackaged_plugins") + if found { + if err := filepath.Walk(prepackagedPluginsDir, func(walkPath string, info os.FileInfo, err error) error { + if !strings.HasSuffix(walkPath, ".tar.gz") { + return nil + } + + if fileReader, err := os.Open(walkPath); err != nil { + mlog.Error("Failed to open prepackaged plugin", mlog.Err(err), mlog.String("path", walkPath)) + } else if _, err := a.InstallPlugin(fileReader, true); err != nil { + mlog.Error("Failed to unpack prepackaged plugin", mlog.Err(err), mlog.String("path", walkPath)) + } + + return nil + }); err != nil { + mlog.Error("Failed to complete unpacking prepackaged plugins", mlog.Err(err)) + } + } + // Sync plugin active state when config changes. Also notify plugins. a.RemoveConfigListener(a.PluginConfigListenerId) a.PluginConfigListenerId = a.AddConfigListener(func(*model.Config, *model.Config) { diff --git a/app/plugin_install.go b/app/plugin_install.go index f96c75f06..b97fbc5d5 100644 --- a/app/plugin_install.go +++ b/app/plugin_install.go @@ -17,11 +17,11 @@ import ( ) // InstallPlugin unpacks and installs a plugin but does not enable or activate it. -func (a *App) InstallPlugin(pluginFile io.Reader) (*model.Manifest, *model.AppError) { - return a.installPlugin(pluginFile) +func (a *App) InstallPlugin(pluginFile io.Reader, replace bool) (*model.Manifest, *model.AppError) { + return a.installPlugin(pluginFile, replace) } -func (a *App) installPlugin(pluginFile io.Reader) (*model.Manifest, *model.AppError) { +func (a *App) installPlugin(pluginFile io.Reader, replace bool) (*model.Manifest, *model.AppError) { if a.Plugins == nil || !*a.Config().PluginSettings.Enable { return nil, model.NewAppError("installPlugin", "app.plugin.disabled.app_error", nil, "", http.StatusNotImplemented) } @@ -63,7 +63,13 @@ func (a *App) installPlugin(pluginFile io.Reader) (*model.Manifest, *model.AppEr // Check that there is no plugin with the same ID for _, bundle := range bundles { if bundle.Manifest != nil && bundle.Manifest.Id == manifest.Id { - return nil, model.NewAppError("installPlugin", "app.plugin.install_id.app_error", nil, "", http.StatusBadRequest) + if !replace { + return nil, model.NewAppError("installPlugin", "app.plugin.install_id.app_error", nil, "", http.StatusBadRequest) + } + + if err := a.RemovePlugin(manifest.Id); err != nil { + return nil, model.NewAppError("installPlugin", "app.plugin.install_id_failed_remove.app_error", nil, "", http.StatusBadRequest) + } } } |