@cryptotaxi247 / kubo / commits / 5bfb8867f

Load static plugins in init

License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>

Łukasz Magiera committed Nov 4, 2018 at 22:48 UTC 5bfb8867f7316e07b4b77b40500f2ddaa0b488cb
3 files changed +31 -23
cmd/ipfs/main.go
+5 -4
@@ -174,10 +174,11 @@ func makeExecutor(req *cmds.Request, env interface{}) (cmds.Executor, error) {
174 if err != nil {
175 return nil, err
176 }
177 - if ok {
178 - if _, err := loader.LoadPlugins(pluginpath); err != nil {
179 - log.Error("error loading plugins: ", err)
180 - }
177 + if !ok {
178 + pluginpath = ""
179 + }
180 + if _, err := loader.LoadPlugins(pluginpath); err != nil {
181 + log.Error("error loading plugins: ", err)
182 }
183
184 exctr = cmds.NewExecutor(req.Root)
plugin/loader/load.go
+15 -13
@@ -22,20 +22,22 @@ func LoadPlugins(pluginDir string) ([]plugin.Plugin, error) {
22 plMap[v.Name()] = v
23 }
24
25 - newPls, err := loadDynamicPlugins(pluginDir)
26 - if err != nil {
27 - return nil, err
28 - }
25 + if pluginDir != "" {
26 + newPls, err := loadDynamicPlugins(pluginDir)
27 + if err != nil {
28 + return nil, err
29 + }
30
30 - for _, pl := range newPls {
31 - if ppl, ok := plMap[pl.Name()]; ok {
32 - // plugin is already preloaded
33 - return nil, fmt.Errorf(
34 - "plugin: %s, is duplicated in version: %s, "+
35 - "while trying to load dynamically: %s",
36 - ppl.Name(), ppl.Version(), pl.Version())
31 + for _, pl := range newPls {
32 + if ppl, ok := plMap[pl.Name()]; ok {
33 + // plugin is already preloaded
34 + return nil, fmt.Errorf(
35 + "plugin: %s, is duplicated in version: %s, "+
36 + "while trying to load dynamically: %s",
37 + ppl.Name(), ppl.Version(), pl.Version())
38 + }
39 + plMap[pl.Name()] = pl
40 }
38 - plMap[pl.Name()] = pl
41 }
42
43 pls := make([]plugin.Plugin, 0, len(plMap))
@@ -43,7 +45,7 @@ func LoadPlugins(pluginDir string) ([]plugin.Plugin, error) {
45 pls = append(pls, v)
46 }
47
46 - err = initialize(pls)
48 + err := initialize(pls)
49 if err != nil {
50 return nil, err
51 }
repo/fsrepo/config_test.go
+11 -6
@@ -1,4 +1,4 @@
1 -package fsrepo
1 +package fsrepo_test
2
3 import (
4 "encoding/json"
@@ -7,7 +7,10 @@ import (
7 "reflect"
8 "testing"
9
10 - config "gx/ipfs/QmbK4EmM2Xx5fmbqK38TGP3PpY66r3tkXLZTcc7dF9mFwM/go-ipfs-config"
10 + "github.com/ipfs/go-ipfs/plugin/loader"
11 + "github.com/ipfs/go-ipfs/repo/fsrepo"
12 +
13 + "gx/ipfs/QmPEpj17FDRpc7K1aArKZp3RsHtzRMKykeK9GVgn4WQGPR/go-ipfs-config"
14 )
15
16 // note: to test sorting of the mountpoints in the disk spec they are
@@ -72,6 +75,8 @@ var measureConfig = []byte(`{
75 }`)
76
77 func TestDefaultDatastoreConfig(t *testing.T) {
78 + loader.LoadPlugins("")
79 +
80 dir, err := ioutil.TempDir("", "ipfs-datastore-config-test")
81 if err != nil {
82 t.Fatal(err)
@@ -84,7 +89,7 @@ func TestDefaultDatastoreConfig(t *testing.T) {
89 t.Fatal(err)
90 }
91
87 - dsc, err := AnyDatastoreConfig(config.Spec)
92 + dsc, err := fsrepo.AnyDatastoreConfig(config.Spec)
93 if err != nil {
94 t.Fatal(err)
95 }
@@ -122,7 +127,7 @@ func TestLevelDbConfig(t *testing.T) {
127 t.Fatal(err)
128 }
129
125 - dsc, err := AnyDatastoreConfig(spec)
130 + dsc, err := fsrepo.AnyDatastoreConfig(spec)
131 if err != nil {
132 t.Fatal(err)
133 }
@@ -160,7 +165,7 @@ func TestFlatfsConfig(t *testing.T) {
165 t.Fatal(err)
166 }
167
163 - dsc, err := AnyDatastoreConfig(spec)
168 + dsc, err := fsrepo.AnyDatastoreConfig(spec)
169 if err != nil {
170 t.Fatal(err)
171 }
@@ -198,7 +203,7 @@ func TestMeasureConfig(t *testing.T) {
203 t.Fatal(err)
204 }
205
201 - dsc, err := AnyDatastoreConfig(spec)
206 + dsc, err := fsrepo.AnyDatastoreConfig(spec)
207 if err != nil {
208 t.Fatal(err)
209 }