@@ -65,6 +65,7 @@ var addPinCmd = &cmds.Command{
65
65
Options : []cmds.Option {
66
66
cmds .BoolOption (pinRecursiveOptionName , "r" , "Recursively pin the object linked to by the specified object(s)." ).WithDefault (true ),
67
67
cmds .BoolOption (pinProgressOptionName , "Show progress" ),
68
+ cmds .StringOption (pinNameOptionName , "n" , "An optional name for the pin(s)." ),
68
69
},
69
70
Type : AddPinOutput {},
70
71
Run : func (req * cmds.Request , res cmds.ResponseEmitter , env cmds.Environment ) error {
@@ -75,6 +76,7 @@ var addPinCmd = &cmds.Command{
75
76
76
77
// set recursive flag
77
78
recursive , _ := req .Options [pinRecursiveOptionName ].(bool )
79
+ name , _ := req .Options [pinNameOptionName ].(string )
78
80
showProgress , _ := req .Options [pinProgressOptionName ].(bool )
79
81
80
82
if err := req .ParseBodyArgs (); err != nil {
@@ -87,7 +89,7 @@ var addPinCmd = &cmds.Command{
87
89
}
88
90
89
91
if ! showProgress {
90
- added , err := pinAddMany (req .Context , api , enc , req .Arguments , recursive )
92
+ added , err := pinAddMany (req .Context , api , enc , req .Arguments , recursive , name )
91
93
if err != nil {
92
94
return err
93
95
}
@@ -105,7 +107,7 @@ var addPinCmd = &cmds.Command{
105
107
106
108
ch := make (chan pinResult , 1 )
107
109
go func () {
108
- added , err := pinAddMany (ctx , api , enc , req .Arguments , recursive )
110
+ added , err := pinAddMany (ctx , api , enc , req .Arguments , recursive , name )
109
111
ch <- pinResult {pins : added , err : err }
110
112
}()
111
113
@@ -181,7 +183,7 @@ var addPinCmd = &cmds.Command{
181
183
},
182
184
}
183
185
184
- func pinAddMany (ctx context.Context , api coreiface.CoreAPI , enc cidenc.Encoder , paths []string , recursive bool ) ([]string , error ) {
186
+ func pinAddMany (ctx context.Context , api coreiface.CoreAPI , enc cidenc.Encoder , paths []string , recursive bool , name string ) ([]string , error ) {
185
187
added := make ([]string , len (paths ))
186
188
for i , b := range paths {
187
189
p , err := cmdutils .PathOrCidPath (b )
@@ -194,7 +196,7 @@ func pinAddMany(ctx context.Context, api coreiface.CoreAPI, enc cidenc.Encoder,
194
196
return nil , err
195
197
}
196
198
197
- if err := api .Pin ().Add (ctx , rp , options .Pin .Recursive (recursive )); err != nil {
199
+ if err := api .Pin ().Add (ctx , rp , options .Pin .Recursive (recursive ), options . Pin . Name ( name ) ); err != nil {
198
200
return nil , err
199
201
}
200
202
added [i ] = enc .Encode (rp .RootCid ())
@@ -278,9 +280,10 @@ ipfs pin ls -t indirect <cid>
278
280
}
279
281
280
282
const (
281
- pinTypeOptionName = "type"
282
- pinQuietOptionName = "quiet"
283
- pinStreamOptionName = "stream"
283
+ pinTypeOptionName = "type"
284
+ pinQuietOptionName = "quiet"
285
+ pinStreamOptionName = "stream"
286
+ pinDetailedOptionName = "detailed"
284
287
)
285
288
286
289
var listPinCmd = & cmds.Command {
@@ -334,6 +337,7 @@ Example:
334
337
cmds .StringOption (pinTypeOptionName , "t" , "The type of pinned keys to list. Can be \" direct\" , \" indirect\" , \" recursive\" , or \" all\" ." ).WithDefault ("all" ),
335
338
cmds .BoolOption (pinQuietOptionName , "q" , "Write just hashes of objects." ),
336
339
cmds .BoolOption (pinStreamOptionName , "s" , "Enable streaming of pins as they are discovered." ),
340
+ cmds .BoolOption (pinDetailedOptionName , "d" , "Enable displaying additional information, such as pin names (slower)." ),
337
341
},
338
342
Run : func (req * cmds.Request , res cmds.ResponseEmitter , env cmds.Environment ) error {
339
343
api , err := cmdenv .GetApi (env , req )
@@ -343,6 +347,7 @@ Example:
343
347
344
348
typeStr , _ := req .Options [pinTypeOptionName ].(string )
345
349
stream , _ := req .Options [pinStreamOptionName ].(bool )
350
+ detailed , _ := req .Options [pinDetailedOptionName ].(bool )
346
351
347
352
switch typeStr {
348
353
case "all" , "direct" , "indirect" , "recursive" :
@@ -356,7 +361,7 @@ Example:
356
361
lgcList := map [string ]PinLsType {}
357
362
if ! stream {
358
363
emit = func (v PinLsOutputWrapper ) error {
359
- lgcList [v .PinLsObject .Cid ] = PinLsType {Type : v .PinLsObject .Type }
364
+ lgcList [v .PinLsObject .Cid ] = PinLsType {Type : v .PinLsObject .Type , Label : v . PinLsObject . Name }
360
365
return nil
361
366
}
362
367
} else {
@@ -368,7 +373,7 @@ Example:
368
373
if len (req .Arguments ) > 0 {
369
374
err = pinLsKeys (req , typeStr , api , emit )
370
375
} else {
371
- err = pinLsAll (req , typeStr , api , emit )
376
+ err = pinLsAll (req , typeStr , detailed , api , emit )
372
377
}
373
378
if err != nil {
374
379
return err
@@ -402,17 +407,21 @@ Example:
402
407
if stream {
403
408
if quiet {
404
409
fmt .Fprintf (w , "%s\n " , out .PinLsObject .Cid )
405
- } else {
410
+ } else if out . PinLsObject . Name == "" {
406
411
fmt .Fprintf (w , "%s %s\n " , out .PinLsObject .Cid , out .PinLsObject .Type )
412
+ } else {
413
+ fmt .Fprintf (w , "%s %s %s\n " , out .PinLsObject .Cid , out .PinLsObject .Type , out .PinLsObject .Name )
407
414
}
408
415
return nil
409
416
}
410
417
411
418
for k , v := range out .PinLsList .Keys {
412
419
if quiet {
413
420
fmt .Fprintf (w , "%s\n " , k )
414
- } else {
421
+ } else if v . Label == "" {
415
422
fmt .Fprintf (w , "%s %s\n " , k , v .Type )
423
+ } else {
424
+ fmt .Fprintf (w , "%s %s %s\n " , k , v .Type , v .Label )
416
425
}
417
426
}
418
427
@@ -436,12 +445,14 @@ type PinLsList struct {
436
445
437
446
// PinLsType contains the type of a pin
438
447
type PinLsType struct {
439
- Type string
448
+ Type string
449
+ Label string
440
450
}
441
451
442
452
// PinLsObject contains the description of a pin
443
453
type PinLsObject struct {
444
454
Cid string `json:",omitempty"`
455
+ Name string `json:",omitempty"`
445
456
Type string `json:",omitempty"`
446
457
}
447
458
@@ -502,7 +513,7 @@ func pinLsKeys(req *cmds.Request, typeStr string, api coreiface.CoreAPI, emit fu
502
513
return nil
503
514
}
504
515
505
- func pinLsAll (req * cmds.Request , typeStr string , api coreiface.CoreAPI , emit func (value PinLsOutputWrapper ) error ) error {
516
+ func pinLsAll (req * cmds.Request , typeStr string , detailed bool , api coreiface.CoreAPI , emit func (value PinLsOutputWrapper ) error ) error {
506
517
enc , err := cmdenv .GetCidEncoder (req )
507
518
if err != nil {
508
519
return err
@@ -520,7 +531,7 @@ func pinLsAll(req *cmds.Request, typeStr string, api coreiface.CoreAPI, emit fun
520
531
panic ("unhandled pin type" )
521
532
}
522
533
523
- pins , err := api .Pin ().Ls (req .Context , opt )
534
+ pins , err := api .Pin ().Ls (req .Context , opt , options . Pin . Ls . Detailed ( detailed ) )
524
535
if err != nil {
525
536
return err
526
537
}
@@ -532,6 +543,7 @@ func pinLsAll(req *cmds.Request, typeStr string, api coreiface.CoreAPI, emit fun
532
543
err = emit (PinLsOutputWrapper {
533
544
PinLsObject : PinLsObject {
534
545
Type : p .Type (),
546
+ Name : p .Name (),
535
547
Cid : enc .Encode (p .Path ().RootCid ()),
536
548
},
537
549
})
@@ -748,15 +760,15 @@ func pinVerify(ctx context.Context, n *core.IpfsNode, opts pinVerifyOpts, enc ci
748
760
out := make (chan any )
749
761
go func () {
750
762
defer close (out )
751
- for p := range n .Pinning .RecursiveKeys (ctx ) {
763
+ for p := range n .Pinning .RecursiveKeys (ctx , false ) {
752
764
if p .Err != nil {
753
765
out <- PinVerifyRes {Err : p .Err .Error ()}
754
766
return
755
767
}
756
- pinStatus := checkPin (p .C )
768
+ pinStatus := checkPin (p .Pin . Key )
757
769
if ! pinStatus .Ok || opts .includeOk {
758
770
select {
759
- case out <- PinVerifyRes {Cid : enc .Encode (p .C ), PinStatus : pinStatus }:
771
+ case out <- PinVerifyRes {Cid : enc .Encode (p .Pin . Key ), PinStatus : pinStatus }:
760
772
case <- ctx .Done ():
761
773
return
762
774
}
0 commit comments