6
6
"path/filepath"
7
7
8
8
repo "github.com/ipfs/go-ipfs/repo"
9
- config "github.com/ipfs/go-ipfs/repo/config"
10
9
11
10
ds "gx/ipfs/QmRWDav6mzWseLWeYfVd5fvUKiVe9xNH29YfMF438fG364/go-datastore"
12
11
mount "gx/ipfs/QmRWDav6mzWseLWeYfVd5fvUKiVe9xNH29YfMF438fG364/go-datastore/syncmount"
@@ -16,70 +15,40 @@ import (
16
15
"gx/ipfs/Qmbx2KUs8mUbDUiiESzC1ms7mdmh4pRu8X1V1tffC46M4n/go-ds-flatfs"
17
16
)
18
17
19
- func (r * FSRepo ) constructDatastore (kind string , params [] byte ) (repo.Datastore , error ) {
20
- switch kind {
18
+ func (r * FSRepo ) constructDatastore (params map [ string ] interface {} ) (repo.Datastore , error ) {
19
+ switch params [ "type" ] {
21
20
case "mount" :
22
- var mounts [] * mountConfig
23
- if err := json . Unmarshal ( params , & mounts ); err != nil {
24
- return nil , fmt .Errorf ("datastore mount: %v" , err )
21
+ mounts , ok := params [ "mounts" ].([] interface {})
22
+ if ! ok {
23
+ return nil , fmt .Errorf ("mounts field wasnt an array" )
25
24
}
26
25
27
26
return r .openMountDatastore (mounts )
28
27
case "flatfs" :
29
- var flatfsparams config.FlatDS
30
- if err := json .Unmarshal (params , & flatfsparams ); err != nil {
31
- return nil , fmt .Errorf ("datastore flatfs: %v" , err )
32
- }
33
-
34
- return r .openFlatfsDatastore (& flatfsparams )
28
+ return r .openFlatfsDatastore (params )
35
29
case "mem" :
36
30
return ds .NewMapDatastore (), nil
37
31
case "log" :
38
- var cfg struct {
39
- Name string
40
- ChildType string
41
- Child * json.RawMessage
42
- }
43
-
44
- if err := json .Unmarshal (params , & cfg ); err != nil {
45
- return nil , fmt .Errorf ("datastore measure: %v" , err )
46
- }
47
-
48
- child , err := r .constructDatastore (cfg .ChildType , []byte (* cfg .Child ))
32
+ child , err := r .constructDatastore (params ["child" ].(map [string ]interface {}))
49
33
if err != nil {
50
34
return nil , err
51
35
}
52
36
53
- return ds .NewLogDatastore (child , cfg .Name ), nil
54
-
37
+ return ds .NewLogDatastore (child , params ["name" ].(string )), nil
55
38
case "measure" :
56
- var measureOpts struct {
57
- Prefix string
58
- ChildType string
59
- Child * json.RawMessage
60
- }
61
-
62
- if err := json .Unmarshal (params , & measureOpts ); err != nil {
63
- return nil , fmt .Errorf ("datastore measure: %v" , err )
64
- }
65
-
66
- child , err := r .constructDatastore (measureOpts .ChildType , []byte (* measureOpts .Child ))
39
+ child , err := r .constructDatastore (params ["child" ].(map [string ]interface {}))
67
40
if err != nil {
68
41
return nil , err
69
42
}
70
43
71
- return r .openMeasureDB (measureOpts .Prefix , child )
72
-
73
- case "levelds" :
74
- var c config.LevelDB
75
- if err := json .Unmarshal (params , & c ); err != nil {
76
- return nil , fmt .Errorf ("datastore levelds: %v" , err )
77
- }
44
+ prefix := params ["prefix" ].(string )
78
45
79
- return r .openLeveldbDatastore ( & c )
46
+ return r .openMeasureDB ( prefix , child )
80
47
48
+ case "levelds" :
49
+ return r .openLeveldbDatastore (params )
81
50
default :
82
- return nil , fmt .Errorf ("unknown datastore type: %s" , kind )
51
+ return nil , fmt .Errorf ("unknown datastore type: %s" , params [ "type" ] )
83
52
}
84
53
}
85
54
@@ -89,40 +58,48 @@ type mountConfig struct {
89
58
Child * json.RawMessage
90
59
}
91
60
92
- func (r * FSRepo ) openMountDatastore (mountcfg []* mountConfig ) (repo.Datastore , error ) {
61
+ func (r * FSRepo ) openMountDatastore (mountcfg []interface {} ) (repo.Datastore , error ) {
93
62
var mounts []mount.Mount
94
- for _ , cfg := range mountcfg {
63
+ for _ , iface := range mountcfg {
64
+ cfg := iface .(map [string ]interface {})
95
65
96
- child , err := r .constructDatastore (cfg . ChildType , [] byte ( * cfg . Child ) )
66
+ child , err := r .constructDatastore (cfg )
97
67
if err != nil {
98
68
return nil , err
99
69
}
100
70
71
+ prefix , found := cfg ["mountpoint" ]
72
+ if ! found {
73
+ return nil , fmt .Errorf ("no 'mountpoint' on mount" )
74
+ }
75
+
101
76
mounts = append (mounts , mount.Mount {
102
77
Datastore : child ,
103
- Prefix : ds .NewKey (cfg . Path ),
78
+ Prefix : ds .NewKey (prefix .( string ) ),
104
79
})
105
80
}
106
81
107
82
return mount .New (mounts ), nil
108
83
}
109
84
110
- func (r * FSRepo ) openFlatfsDatastore (params * config. FlatDS ) (repo.Datastore , error ) {
111
- p := params . Path
85
+ func (r * FSRepo ) openFlatfsDatastore (params map [ string ] interface {} ) (repo.Datastore , error ) {
86
+ p := params [ "path" ].( string )
112
87
if ! filepath .IsAbs (p ) {
113
88
p = filepath .Join (r .path , p )
114
89
}
115
- return flatfs .New (p , params .PrefixLen , params .Sync )
90
+
91
+ plen := int (params ["prefixLen" ].(float64 ))
92
+ return flatfs .New (p , plen , params ["nosync" ].(bool ))
116
93
}
117
94
118
- func (r * FSRepo ) openLeveldbDatastore (params * config. LevelDB ) (repo.Datastore , error ) {
119
- p := params . Path
95
+ func (r * FSRepo ) openLeveldbDatastore (params map [ string ] interface {} ) (repo.Datastore , error ) {
96
+ p := params [ "path" ].( string )
120
97
if ! filepath .IsAbs (p ) {
121
98
p = filepath .Join (r .path , p )
122
99
}
123
100
124
101
var c ldbopts.Compression
125
- switch params . Compression {
102
+ switch params [ "compression" ].( string ) {
126
103
case "none" :
127
104
c = ldbopts .NoCompression
128
105
case "snappy" :
0 commit comments