@@ -17,6 +17,7 @@ import (
17
17
18
18
cid "gx/ipfs/QmR8BauakNcBa3RbE4nbQu76PDiJgoQgz8AJdhJuiU4TAw/go-cid"
19
19
bserv "gx/ipfs/QmVDTbzzTwnuBwNbJdhW3u7LoBQp46bezm9yp4z1RoEepM/go-blockservice"
20
+ apicid "gx/ipfs/QmWf8NwKFLbTBvAvZst3bYF7WEEetzxWyMhvQ885cj9MM8/go-cidutil/apicid"
20
21
"gx/ipfs/QmYMQuypUbgsdNHmuCBSUJV6wdQVsBHRivNAp3efHJwZJD/go-verifcid"
21
22
offline "gx/ipfs/QmYZwey1thDTynSrvd6qQkX24UpTka6TFhQ2v569UpoqxD/go-ipfs-exchange-offline"
22
23
cmds "gx/ipfs/Qma6uuSyjkecGhMFFLfzyJDPyoDtNJSHJNweDccZhaWkgU/go-ipfs-cmds"
@@ -39,11 +40,11 @@ var PinCmd = &cmds.Command{
39
40
}
40
41
41
42
type PinOutput struct {
42
- Pins []string
43
+ Pins []apicid. Hash
43
44
}
44
45
45
46
type AddPinOutput struct {
46
- Pins []string
47
+ Pins []apicid. Hash
47
48
Progress int `json:",omitempty"`
48
49
}
49
50
@@ -92,7 +93,7 @@ var addPinCmd = &cmds.Command{
92
93
if err != nil {
93
94
return err
94
95
}
95
- return cmds .EmitOnce (res , & AddPinOutput {Pins : cidsToStrings (added )})
96
+ return cmds .EmitOnce (res , & AddPinOutput {Pins : toAPICids (added )})
96
97
}
97
98
98
99
v := new (dag.ProgressTracker )
@@ -124,7 +125,7 @@ var addPinCmd = &cmds.Command{
124
125
return err
125
126
}
126
127
}
127
- return res .Emit (& AddPinOutput {Pins : cidsToStrings (val .pins )})
128
+ return res .Emit (& AddPinOutput {Pins : toAPICids (val .pins )})
128
129
case <- ticker .C :
129
130
if err := res .Emit (& AddPinOutput {Progress : v .Value ()}); err != nil {
130
131
return err
@@ -220,7 +221,7 @@ collected if needed. (By default, recursively. Use -r=false for direct pins.)
220
221
return err
221
222
}
222
223
223
- return cmds .EmitOnce (res , & PinOutput {cidsToStrings (removed )})
224
+ return cmds .EmitOnce (res , & PinOutput {toAPICids (removed )})
224
225
},
225
226
Encoders : cmds.EncoderMap {
226
227
cmds .Text : cmds .MakeTypedEncoder (func (req * cmds.Request , w io.Writer , out * PinOutput ) error {
@@ -311,7 +312,7 @@ Example:
311
312
return err
312
313
}
313
314
314
- var keys map [string ]RefKeyObject
315
+ var keys map [apicid. Hash ]RefKeyObject
315
316
316
317
if len (req .Arguments ) > 0 {
317
318
keys , err = pinLsKeys (req .Context , req .Arguments , typeStr , n , api )
@@ -347,6 +348,10 @@ const (
347
348
pinUnpinOptionName = "unpin"
348
349
)
349
350
351
+ type UpdatePinOutput struct {
352
+ Pins []string // really paths
353
+ }
354
+
350
355
var updatePinCmd = & cmds.Command {
351
356
Helptext : cmdkit.HelpText {
352
357
Tagline : "Update a recursive pin" ,
@@ -364,7 +369,7 @@ new pin and removing the old one.
364
369
Options : []cmdkit.Option {
365
370
cmdkit .BoolOption (pinUnpinOptionName , "Remove the old pin." ).WithDefault (true ),
366
371
},
367
- Type : PinOutput {},
372
+ Type : UpdatePinOutput {},
368
373
Run : func (req * cmds.Request , res cmds.ResponseEmitter , env cmds.Environment ) error {
369
374
api , err := cmdenv .GetApi (env )
370
375
if err != nil {
@@ -388,10 +393,10 @@ new pin and removing the old one.
388
393
return err
389
394
}
390
395
391
- return cmds .EmitOnce (res , & PinOutput {Pins : []string {from .String (), to .String ()}})
396
+ return cmds .EmitOnce (res , & UpdatePinOutput {Pins : []string {from .String (), to .String ()}})
392
397
},
393
398
Encoders : cmds.EncoderMap {
394
- cmds .Text : cmds .MakeTypedEncoder (func (req * cmds.Request , w io.Writer , out * PinOutput ) error {
399
+ cmds .Text : cmds .MakeTypedEncoder (func (req * cmds.Request , w io.Writer , out * UpdatePinOutput ) error {
395
400
fmt .Fprintf (w , "updated %s to %s\n " , out .Pins [0 ], out .Pins [1 ])
396
401
return nil
397
402
}),
@@ -452,17 +457,17 @@ type RefKeyObject struct {
452
457
}
453
458
454
459
type RefKeyList struct {
455
- Keys map [string ]RefKeyObject
460
+ Keys map [apicid. Hash ]RefKeyObject
456
461
}
457
462
458
- func pinLsKeys (ctx context.Context , args []string , typeStr string , n * core.IpfsNode , api iface.CoreAPI ) (map [string ]RefKeyObject , error ) {
463
+ func pinLsKeys (ctx context.Context , args []string , typeStr string , n * core.IpfsNode , api iface.CoreAPI ) (map [apicid. Hash ]RefKeyObject , error ) {
459
464
460
465
mode , ok := pin .StringToMode (typeStr )
461
466
if ! ok {
462
467
return nil , fmt .Errorf ("invalid pin mode '%s'" , typeStr )
463
468
}
464
469
465
- keys := make (map [string ]RefKeyObject )
470
+ keys := make (map [apicid. Hash ]RefKeyObject )
466
471
467
472
for _ , p := range args {
468
473
pth , err := iface .ParsePath (p )
@@ -489,21 +494,21 @@ func pinLsKeys(ctx context.Context, args []string, typeStr string, n *core.IpfsN
489
494
default :
490
495
pinType = "indirect through " + pinType
491
496
}
492
- keys [c .Cid (). String ( )] = RefKeyObject {
497
+ keys [apicid . FromCid ( c .Cid ())] = RefKeyObject {
493
498
Type : pinType ,
494
499
}
495
500
}
496
501
497
502
return keys , nil
498
503
}
499
504
500
- func pinLsAll (ctx context.Context , typeStr string , n * core.IpfsNode ) (map [string ]RefKeyObject , error ) {
505
+ func pinLsAll (ctx context.Context , typeStr string , n * core.IpfsNode ) (map [apicid. Hash ]RefKeyObject , error ) {
501
506
502
- keys := make (map [string ]RefKeyObject )
507
+ keys := make (map [apicid. Hash ]RefKeyObject )
503
508
504
509
AddToResultKeys := func (keyList []cid.Cid , typeStr string ) {
505
510
for _ , c := range keyList {
506
- keys [c . String ( )] = RefKeyObject {
511
+ keys [apicid . FromCid ( c )] = RefKeyObject {
507
512
Type : typeStr ,
508
513
}
509
514
}
@@ -531,7 +536,7 @@ func pinLsAll(ctx context.Context, typeStr string, n *core.IpfsNode) (map[string
531
536
532
537
// PinVerifyRes is the result returned for each pin checked in "pin verify"
533
538
type PinVerifyRes struct {
534
- Cid string
539
+ Cid apicid. Hash
535
540
PinStatus
536
541
}
537
542
@@ -543,7 +548,7 @@ type PinStatus struct {
543
548
544
549
// BadNode is used in PinVerifyRes
545
550
type BadNode struct {
546
- Cid string
551
+ Cid apicid. Hash
547
552
Err string
548
553
}
549
554
@@ -553,7 +558,7 @@ type pinVerifyOpts struct {
553
558
}
554
559
555
560
func pinVerify (ctx context.Context , n * core.IpfsNode , opts pinVerifyOpts ) <- chan interface {} {
556
- visited := make (map [string ]PinStatus )
561
+ visited := make (map [cid. Cid ]PinStatus )
557
562
558
563
bs := n .Blocks .Blockstore ()
559
564
DAG := dag .NewDAGService (bserv .New (bs , offline .Exchange (bs )))
@@ -562,15 +567,15 @@ func pinVerify(ctx context.Context, n *core.IpfsNode, opts pinVerifyOpts) <-chan
562
567
563
568
var checkPin func (root cid.Cid ) PinStatus
564
569
checkPin = func (root cid.Cid ) PinStatus {
565
- key := root . String ()
570
+ key := root
566
571
if status , ok := visited [key ]; ok {
567
572
return status
568
573
}
569
574
570
575
if err := verifcid .ValidateCid (root ); err != nil {
571
576
status := PinStatus {Ok : false }
572
577
if opts .explain {
573
- status .BadNodes = []BadNode {BadNode {Cid : key , Err : err .Error ()}}
578
+ status .BadNodes = []BadNode {BadNode {Cid : apicid . FromCid ( key ) , Err : err .Error ()}}
574
579
}
575
580
visited [key ] = status
576
581
return status
@@ -580,7 +585,7 @@ func pinVerify(ctx context.Context, n *core.IpfsNode, opts pinVerifyOpts) <-chan
580
585
if err != nil {
581
586
status := PinStatus {Ok : false }
582
587
if opts .explain {
583
- status .BadNodes = []BadNode {BadNode {Cid : key , Err : err .Error ()}}
588
+ status .BadNodes = []BadNode {BadNode {Cid : apicid . FromCid ( key ) , Err : err .Error ()}}
584
589
}
585
590
visited [key ] = status
586
591
return status
@@ -606,7 +611,7 @@ func pinVerify(ctx context.Context, n *core.IpfsNode, opts pinVerifyOpts) <-chan
606
611
pinStatus := checkPin (cid )
607
612
if ! pinStatus .Ok || opts .includeOk {
608
613
select {
609
- case out <- & PinVerifyRes {cid . String ( ), pinStatus }:
614
+ case out <- & PinVerifyRes {apicid . FromCid ( cid ), pinStatus }:
610
615
case <- ctx .Done ():
611
616
return
612
617
}
@@ -629,10 +634,10 @@ func (r PinVerifyRes) Format(out io.Writer) {
629
634
}
630
635
}
631
636
632
- func cidsToStrings (cs []cid.Cid ) []string {
633
- out := make ([]string , 0 , len (cs ))
637
+ func toAPICids (cs []cid.Cid ) []apicid. Hash {
638
+ out := make ([]apicid. Hash , 0 , len (cs ))
634
639
for _ , c := range cs {
635
- out = append (out , c . String ( ))
640
+ out = append (out , apicid . FromCid ( c ))
636
641
}
637
642
return out
638
643
}
0 commit comments