From 07facaf49fb19a968ec5e9710bfbc142bb6b6c59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Sun, 4 Nov 2018 22:48:37 +0100 Subject: [PATCH] Load static plugins in init MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit License: MIT Signed-off-by: Ɓukasz Magiera --- cmd/ipfs/main.go | 9 +++++---- plugin/loader/load.go | 28 +++++++++++++++------------- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/cmd/ipfs/main.go b/cmd/ipfs/main.go index 0809c449a9ce..7ab43d864fb7 100644 --- a/cmd/ipfs/main.go +++ b/cmd/ipfs/main.go @@ -174,10 +174,11 @@ func makeExecutor(req *cmds.Request, env interface{}) (cmds.Executor, error) { if err != nil { return nil, err } - if ok { - if _, err := loader.LoadPlugins(pluginpath); err != nil { - log.Error("error loading plugins: ", err) - } + if !ok { + pluginpath = "" + } + if _, err := loader.LoadPlugins(pluginpath); err != nil { + log.Error("error loading plugins: ", err) } exctr = cmds.NewExecutor(req.Root) diff --git a/plugin/loader/load.go b/plugin/loader/load.go index b679fbe2343a..3ae93c731cc7 100644 --- a/plugin/loader/load.go +++ b/plugin/loader/load.go @@ -22,20 +22,22 @@ func LoadPlugins(pluginDir string) ([]plugin.Plugin, error) { plMap[v.Name()] = v } - newPls, err := loadDynamicPlugins(pluginDir) - if err != nil { - return nil, err - } + if pluginDir != "" { + newPls, err := loadDynamicPlugins(pluginDir) + if err != nil { + return nil, err + } - for _, pl := range newPls { - if ppl, ok := plMap[pl.Name()]; ok { - // plugin is already preloaded - return nil, fmt.Errorf( - "plugin: %s, is duplicated in version: %s, "+ - "while trying to load dynamically: %s", - ppl.Name(), ppl.Version(), pl.Version()) + for _, pl := range newPls { + if ppl, ok := plMap[pl.Name()]; ok { + // plugin is already preloaded + return nil, fmt.Errorf( + "plugin: %s, is duplicated in version: %s, "+ + "while trying to load dynamically: %s", + ppl.Name(), ppl.Version(), pl.Version()) + } + plMap[pl.Name()] = pl } - plMap[pl.Name()] = pl } pls := make([]plugin.Plugin, 0, len(plMap)) @@ -43,7 +45,7 @@ func LoadPlugins(pluginDir string) ([]plugin.Plugin, error) { pls = append(pls, v) } - err = initialize(pls) + err := initialize(pls) if err != nil { return nil, err }