@@ -275,17 +275,17 @@ The output of blocks happens in strict DAG-traversal, first-seen, order.
275
275
},
276
276
Run : func (req * cmds.Request , res cmds.ResponseEmitter , env cmds.Environment ) error {
277
277
278
- c , err := cid .Decode (req .Arguments [0 ])
279
- if err != nil {
278
+ c , cidErr := cid .Decode (req .Arguments [0 ])
279
+ if cidErr != nil {
280
280
return fmt .Errorf (
281
281
"unable to parse root specification (currently only bare CIDs are supported): %s" ,
282
- err ,
282
+ cidErr ,
283
283
)
284
284
}
285
285
286
- node , err := cmdenv .GetNode (env )
287
- if err != nil {
288
- return err
286
+ node , nodeErr := cmdenv .GetNode (env )
287
+ if nodeErr != nil {
288
+ return nodeErr
289
289
}
290
290
291
291
// Code disabled until descent-issue in go-ipld-prime is fixed
@@ -307,6 +307,24 @@ The output of blocks happens in strict DAG-traversal, first-seen, order.
307
307
// if err := car.Write(pipeW); err != nil {}
308
308
309
309
pipeR , pipeW := io .Pipe ()
310
+ // this is so convoluted because we:
311
+ // - want to close the readpipe on error so that the goroutine dies
312
+ // - can not do so on success, because during a no-deamon process
313
+ // scenario the PostRun will not be able to grab the EOF from the
314
+ // now-closed pipe
315
+ //
316
+ // Skipping this check results in:
317
+ //
318
+ // cmd/ipfs/ipfs dag export QmdmQXB2mzChmMeKY47C43LxUdg1NDJ5MWcKMKxDu7RgQm >/dev/null
319
+ // 0s 0 B / ? [------------------------------------------------------------------------=]Error: io: read/write on closed pipe
320
+ // 1s 107.08 MiB / ? [-----------------------------------------=----------] 106.59 MiB/s
321
+ //
322
+ var emittingError error
323
+ defer func () {
324
+ if emittingError != nil {
325
+ pipeR .Close ()
326
+ }
327
+ }()
310
328
311
329
errCh := make (chan error , 2 ) // we only report the 1st error
312
330
go func () {
@@ -330,21 +348,20 @@ The output of blocks happens in strict DAG-traversal, first-seen, order.
330
348
}
331
349
}()
332
350
333
- if err := res .Emit (pipeR ); err != nil {
334
- pipeR .Close () // ignore the error if any
335
- return err
351
+ if emittingError = res .Emit (pipeR ); emittingError != nil {
352
+ return emittingError
336
353
}
337
354
338
- err = <- errCh
355
+ emittingError = <- errCh
339
356
340
357
// minimal user friendliness
341
- if err != nil &&
358
+ if emittingError != nil &&
342
359
! node .IsOnline &&
343
- err == ipld .ErrNotFound {
344
- err = fmt .Errorf ("%s (currently offline, perhaps retry after attaching to the network)" , err )
360
+ emittingError == ipld .ErrNotFound {
361
+ emittingError = fmt .Errorf ("%s (currently offline, perhaps retry after attaching to the network)" , emittingError )
345
362
}
346
363
347
- return err
364
+ return emittingError
348
365
},
349
366
PostRun : cmds.PostRunMap {
350
367
cmds .CLI : func (res cmds.Response , re cmds.ResponseEmitter ) error {
0 commit comments