Skip to content

Commit

Permalink
Load static plugins in init
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
  • Loading branch information
magik6k committed Nov 4, 2018
1 parent e1be2f7 commit 07facaf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 17 deletions.
9 changes: 5 additions & 4 deletions cmd/ipfs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 15 additions & 13 deletions plugin/loader/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,30 @@ 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))
for _, v := range plMap {
pls = append(pls, v)
}

err = initialize(pls)
err := initialize(pls)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 07facaf

Please sign in to comment.