@cryptotaxi247 / kubo / commits / de4527788

doc(core, main)

Brian Tiger Chow committed Jan 17, 2015 at 02:41 UTC de45277883e96d03e2a9bb2ce6ace1ad63d71696
2 files changed +15 -3
cmd/ipfs/main.go
+1 -1
@@ -182,7 +182,7 @@ func (i *cmdInvocation) constructNodeFunc(ctx context.Context) func() (*core.Ipf
182 }
183
184 r := fsrepo.At(i.req.Context().ConfigRoot)
185 - if err := r.Open(); err != nil {
185 + if err := r.Open(); err != nil { // repo is owned by the node
186 return nil, err
187 }
188
core/core.go
+14 -2
@@ -150,6 +150,18 @@ func Online(r repo.Repo) ConfigOption {
150 // DEPRECATED: use Online, Offline functions
151 func Standard(r repo.Repo, online bool) ConfigOption {
152 return func(ctx context.Context) (n *IpfsNode, err error) {
153 + // FIXME perform node construction in the main constructor so it isn't
154 + // necessary to perform this teardown in this scope.
155 + success := false
156 + defer func() {
157 + if !success && n != nil {
158 + n.teardown()
159 + }
160 + }()
161 +
162 + // TODO move as much of node initialization as possible into
163 + // NewIPFSNode. The larger these config options are, the harder it is
164 + // to test all node construction code paths.
165
166 if r == nil {
167 return nil, debugerror.Errorf("repo required")
@@ -177,15 +189,15 @@ func Standard(r repo.Repo, online bool) ConfigOption {
189 return nil, debugerror.Wrap(err)
190 }
191
180 - // setup online services
192 if online {
193 if err := n.StartOnlineServices(ctx); err != nil {
183 - return nil, err // debugerror.Wraps.
194 + return nil, err
195 }
196 } else {
197 n.Exchange = offline.Exchange(n.Blockstore)
198 }
199
200 + success = true
201 return n, nil
202 }
203 }