Skip to content

Commit 8e05c63

Browse files
committed
feat: add --detailed option to ipfs pin ls
1 parent fec88d8 commit 8e05c63

File tree

10 files changed

+40
-27
lines changed

10 files changed

+40
-27
lines changed

core/commands/pin/pin.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,10 @@ ipfs pin ls -t indirect <cid>
280280
}
281281

282282
const (
283-
pinTypeOptionName = "type"
284-
pinQuietOptionName = "quiet"
285-
pinStreamOptionName = "stream"
283+
pinTypeOptionName = "type"
284+
pinQuietOptionName = "quiet"
285+
pinStreamOptionName = "stream"
286+
pinDetailedOptionName = "detailed"
286287
)
287288

288289
var listPinCmd = &cmds.Command{
@@ -336,6 +337,7 @@ Example:
336337
cmds.StringOption(pinTypeOptionName, "t", "The type of pinned keys to list. Can be \"direct\", \"indirect\", \"recursive\", or \"all\".").WithDefault("all"),
337338
cmds.BoolOption(pinQuietOptionName, "q", "Write just hashes of objects."),
338339
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)."),
339341
},
340342
Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error {
341343
api, err := cmdenv.GetApi(env, req)
@@ -345,6 +347,7 @@ Example:
345347

346348
typeStr, _ := req.Options[pinTypeOptionName].(string)
347349
stream, _ := req.Options[pinStreamOptionName].(bool)
350+
detailed, _ := req.Options[pinDetailedOptionName].(bool)
348351

349352
switch typeStr {
350353
case "all", "direct", "indirect", "recursive":
@@ -370,7 +373,7 @@ Example:
370373
if len(req.Arguments) > 0 {
371374
err = pinLsKeys(req, typeStr, api, emit)
372375
} else {
373-
err = pinLsAll(req, typeStr, api, emit)
376+
err = pinLsAll(req, typeStr, detailed, api, emit)
374377
}
375378
if err != nil {
376379
return err
@@ -510,7 +513,7 @@ func pinLsKeys(req *cmds.Request, typeStr string, api coreiface.CoreAPI, emit fu
510513
return nil
511514
}
512515

513-
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 {
514517
enc, err := cmdenv.GetCidEncoder(req)
515518
if err != nil {
516519
return err
@@ -528,7 +531,7 @@ func pinLsAll(req *cmds.Request, typeStr string, api coreiface.CoreAPI, emit fun
528531
panic("unhandled pin type")
529532
}
530533

531-
pins, err := api.Pin().Ls(req.Context, opt)
534+
pins, err := api.Pin().Ls(req.Context, opt, options.Pin.Ls.Detailed(detailed))
532535
if err != nil {
533536
return err
534537
}
@@ -757,7 +760,7 @@ func pinVerify(ctx context.Context, n *core.IpfsNode, opts pinVerifyOpts, enc ci
757760
out := make(chan any)
758761
go func() {
759762
defer close(out)
760-
for p := range n.Pinning.RecursiveKeys(ctx) {
763+
for p := range n.Pinning.RecursiveKeys(ctx, false) {
761764
if p.Err != nil {
762765
out <- PinVerifyRes{Err: p.Err.Error()}
763766
return

core/coreapi/pin.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (api *PinAPI) Ls(ctx context.Context, opts ...caopts.PinLsOption) (<-chan c
6767
return nil, fmt.Errorf("invalid type '%s', must be one of {direct, indirect, recursive, all}", settings.Type)
6868
}
6969

70-
return api.pinLsAll(ctx, settings.Type), nil
70+
return api.pinLsAll(ctx, settings.Type, settings.Detailed), nil
7171
}
7272

7373
func (api *PinAPI) IsPinned(ctx context.Context, p path.Path, opts ...caopts.PinIsPinnedOption) (string, bool, error) {
@@ -231,7 +231,7 @@ func (api *PinAPI) Verify(ctx context.Context) (<-chan coreiface.PinStatus, erro
231231
out := make(chan coreiface.PinStatus)
232232
go func() {
233233
defer close(out)
234-
for p := range api.pinning.RecursiveKeys(ctx) {
234+
for p := range api.pinning.RecursiveKeys(ctx, false) {
235235
var res *pinStatus
236236
if p.Err != nil {
237237
res = &pinStatus{err: p.Err}
@@ -276,7 +276,7 @@ func (p *pinInfo) Err() error {
276276
//
277277
// The caller must keep reading results until the channel is closed to prevent
278278
// leaking the goroutine that is fetching pins.
279-
func (api *PinAPI) pinLsAll(ctx context.Context, typeStr string) <-chan coreiface.Pin {
279+
func (api *PinAPI) pinLsAll(ctx context.Context, typeStr string, detailed bool) <-chan coreiface.Pin {
280280
out := make(chan coreiface.Pin, 1)
281281

282282
emittedSet := cid.NewSet()
@@ -302,7 +302,7 @@ func (api *PinAPI) pinLsAll(ctx context.Context, typeStr string) <-chan coreifac
302302
var rkeys []cid.Cid
303303
var err error
304304
if typeStr == "recursive" || typeStr == "all" {
305-
for streamedCid := range api.pinning.RecursiveKeys(ctx) {
305+
for streamedCid := range api.pinning.RecursiveKeys(ctx, detailed) {
306306
if streamedCid.Err != nil {
307307
out <- &pinInfo{err: streamedCid.Err}
308308
return
@@ -315,7 +315,7 @@ func (api *PinAPI) pinLsAll(ctx context.Context, typeStr string) <-chan coreifac
315315
}
316316
}
317317
if typeStr == "direct" || typeStr == "all" {
318-
for streamedCid := range api.pinning.DirectKeys(ctx) {
318+
for streamedCid := range api.pinning.DirectKeys(ctx, detailed) {
319319
if streamedCid.Err != nil {
320320
out <- &pinInfo{err: streamedCid.Err}
321321
return
@@ -330,15 +330,15 @@ func (api *PinAPI) pinLsAll(ctx context.Context, typeStr string) <-chan coreifac
330330
// We need to first visit the direct pins that have priority
331331
// without emitting them
332332

333-
for streamedCid := range api.pinning.DirectKeys(ctx) {
333+
for streamedCid := range api.pinning.DirectKeys(ctx, detailed) {
334334
if streamedCid.Err != nil {
335335
out <- &pinInfo{err: streamedCid.Err}
336336
return
337337
}
338338
emittedSet.Add(streamedCid.Pin.Key)
339339
}
340340

341-
for streamedCid := range api.pinning.RecursiveKeys(ctx) {
341+
for streamedCid := range api.pinning.RecursiveKeys(ctx, detailed) {
342342
if streamedCid.Err != nil {
343343
out <- &pinInfo{err: streamedCid.Err}
344344
return

core/coreiface/options/pin.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ type PinAddSettings struct {
1010

1111
// PinLsSettings represent the settings for PinAPI.Ls
1212
type PinLsSettings struct {
13-
Type string
13+
Type string
14+
Detailed bool
1415
}
1516

1617
// PinIsPinnedSettings represent the settings for PinAPI.IsPinned
@@ -195,6 +196,15 @@ func (pinLsOpts) pinType(t string) PinLsOption {
195196
}
196197
}
197198

199+
// Detailed is an option for [Pin.Ls] which sets whether or not to return
200+
// detailed information, such as pin names and modes.
201+
func (pinLsOpts) Detailed(detailed bool) PinLsOption {
202+
return func(settings *PinLsSettings) error {
203+
settings.Detailed = detailed
204+
return nil
205+
}
206+
}
207+
198208
type pinIsPinnedOpts struct{}
199209

200210
// All is an option for Pin.IsPinned which will make it search in all type of pins.

docs/examples/kubo-as-a-library/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ go 1.20
77
replace github.com/ipfs/kubo => ./../../..
88

99
require (
10-
github.com/ipfs/boxo v0.16.1-0.20240102112808-a73b1877dbf8
10+
github.com/ipfs/boxo v0.16.1-0.20240102133734-dc2f8b06ce71
1111
github.com/ipfs/kubo v0.0.0-00010101000000-000000000000
1212
github.com/libp2p/go-libp2p v0.32.2
1313
github.com/multiformats/go-multiaddr v0.12.0

docs/examples/kubo-as-a-library/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ github.com/ipfs-shipyard/nopfs/ipfs v0.13.2-0.20231027223058-cde3b5ba964c h1:7Uy
303303
github.com/ipfs-shipyard/nopfs/ipfs v0.13.2-0.20231027223058-cde3b5ba964c/go.mod h1:6EekK/jo+TynwSE/ZOiOJd4eEvRXoavEC3vquKtv4yI=
304304
github.com/ipfs/bbloom v0.0.4 h1:Gi+8EGJ2y5qiD5FbsbpX/TMNcJw8gSqr7eyjHa4Fhvs=
305305
github.com/ipfs/bbloom v0.0.4/go.mod h1:cS9YprKXpoZ9lT0n/Mw/a6/aFV6DTjTLYHeA+gyqMG0=
306-
github.com/ipfs/boxo v0.16.1-0.20240102112808-a73b1877dbf8 h1:J7v8ilV3rJDSFuEIIfQfEwqYBrdoksTenVRdpUzrpiU=
307-
github.com/ipfs/boxo v0.16.1-0.20240102112808-a73b1877dbf8/go.mod h1:jAgpNQn7T7BnibUeReXcKU9Ha1xmYNyOlwVEl193ow0=
306+
github.com/ipfs/boxo v0.16.1-0.20240102133734-dc2f8b06ce71 h1:4WeZGWkOD4Wr2aGm7xXWdwGgPZbCYHjaz+gVaxx1sJ8=
307+
github.com/ipfs/boxo v0.16.1-0.20240102133734-dc2f8b06ce71/go.mod h1:jAgpNQn7T7BnibUeReXcKU9Ha1xmYNyOlwVEl193ow0=
308308
github.com/ipfs/go-bitfield v1.1.0 h1:fh7FIo8bSwaJEh6DdTWbCeZ1eqOaOkKFI74SCnsWbGA=
309309
github.com/ipfs/go-bitfield v1.1.0/go.mod h1:paqf1wjq/D2BBmzfTVFlJQ9IlFOZpg422HL0HqsGWHU=
310310
github.com/ipfs/go-block-format v0.0.2/go.mod h1:AWR46JfpcObNfg3ok2JHDUfdiHRgWhJgCQF+KIgOPJY=

gc/gc.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ func ColoredSet(ctx context.Context, pn pin.Pinner, ng ipld.NodeGetter, bestEffo
226226
}
227227
return links, nil
228228
}
229-
rkeys := pn.RecursiveKeys(ctx)
229+
rkeys := pn.RecursiveKeys(ctx, false)
230230
err := Descendants(ctx, getLinks, gcs, rkeys)
231231
if err != nil {
232232
errors = true
@@ -270,15 +270,15 @@ func ColoredSet(ctx context.Context, pn pin.Pinner, ng ipld.NodeGetter, bestEffo
270270
}
271271
}
272272

273-
dkeys := pn.DirectKeys(ctx)
273+
dkeys := pn.DirectKeys(ctx, false)
274274
for k := range dkeys {
275275
if k.Err != nil {
276276
return nil, k.Err
277277
}
278278
gcs.Add(toCidV1(k.Pin.Key))
279279
}
280280

281-
ikeys := pn.InternalPins(ctx)
281+
ikeys := pn.InternalPins(ctx, false)
282282
err = Descendants(ctx, getLinks, gcs, ikeys)
283283
if err != nil {
284284
errors = true

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ require (
1717
github.com/hashicorp/go-multierror v1.1.1
1818
github.com/ipfs-shipyard/nopfs v0.0.12-0.20231027223058-cde3b5ba964c
1919
github.com/ipfs-shipyard/nopfs/ipfs v0.13.2-0.20231027223058-cde3b5ba964c
20-
github.com/ipfs/boxo v0.16.1-0.20240102112808-a73b1877dbf8
20+
github.com/ipfs/boxo v0.16.1-0.20240102133734-dc2f8b06ce71
2121
github.com/ipfs/go-block-format v0.2.0
2222
github.com/ipfs/go-cid v0.4.1
2323
github.com/ipfs/go-cidutil v0.1.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,8 @@ github.com/ipfs-shipyard/nopfs/ipfs v0.13.2-0.20231027223058-cde3b5ba964c h1:7Uy
337337
github.com/ipfs-shipyard/nopfs/ipfs v0.13.2-0.20231027223058-cde3b5ba964c/go.mod h1:6EekK/jo+TynwSE/ZOiOJd4eEvRXoavEC3vquKtv4yI=
338338
github.com/ipfs/bbloom v0.0.4 h1:Gi+8EGJ2y5qiD5FbsbpX/TMNcJw8gSqr7eyjHa4Fhvs=
339339
github.com/ipfs/bbloom v0.0.4/go.mod h1:cS9YprKXpoZ9lT0n/Mw/a6/aFV6DTjTLYHeA+gyqMG0=
340-
github.com/ipfs/boxo v0.16.1-0.20240102112808-a73b1877dbf8 h1:J7v8ilV3rJDSFuEIIfQfEwqYBrdoksTenVRdpUzrpiU=
341-
github.com/ipfs/boxo v0.16.1-0.20240102112808-a73b1877dbf8/go.mod h1:jAgpNQn7T7BnibUeReXcKU9Ha1xmYNyOlwVEl193ow0=
340+
github.com/ipfs/boxo v0.16.1-0.20240102133734-dc2f8b06ce71 h1:4WeZGWkOD4Wr2aGm7xXWdwGgPZbCYHjaz+gVaxx1sJ8=
341+
github.com/ipfs/boxo v0.16.1-0.20240102133734-dc2f8b06ce71/go.mod h1:jAgpNQn7T7BnibUeReXcKU9Ha1xmYNyOlwVEl193ow0=
342342
github.com/ipfs/go-bitfield v1.1.0 h1:fh7FIo8bSwaJEh6DdTWbCeZ1eqOaOkKFI74SCnsWbGA=
343343
github.com/ipfs/go-bitfield v1.1.0/go.mod h1:paqf1wjq/D2BBmzfTVFlJQ9IlFOZpg422HL0HqsGWHU=
344344
github.com/ipfs/go-bitswap v0.11.0 h1:j1WVvhDX1yhG32NTC9xfxnqycqYIlhzEzLXG/cU1HyQ=

test/dependencies/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ require (
103103
github.com/hexops/gotextdiff v1.0.3 // indirect
104104
github.com/inconshreveable/mousetrap v1.1.0 // indirect
105105
github.com/ipfs/bbloom v0.0.4 // indirect
106-
github.com/ipfs/boxo v0.16.1-0.20240102112808-a73b1877dbf8 // indirect
106+
github.com/ipfs/boxo v0.16.1-0.20240102133734-dc2f8b06ce71 // indirect
107107
github.com/ipfs/go-block-format v0.2.0 // indirect
108108
github.com/ipfs/go-cid v0.4.1 // indirect
109109
github.com/ipfs/go-datastore v0.6.0 // indirect

test/dependencies/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,8 @@ github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2
342342
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
343343
github.com/ipfs/bbloom v0.0.4 h1:Gi+8EGJ2y5qiD5FbsbpX/TMNcJw8gSqr7eyjHa4Fhvs=
344344
github.com/ipfs/bbloom v0.0.4/go.mod h1:cS9YprKXpoZ9lT0n/Mw/a6/aFV6DTjTLYHeA+gyqMG0=
345-
github.com/ipfs/boxo v0.16.1-0.20240102112808-a73b1877dbf8 h1:J7v8ilV3rJDSFuEIIfQfEwqYBrdoksTenVRdpUzrpiU=
346-
github.com/ipfs/boxo v0.16.1-0.20240102112808-a73b1877dbf8/go.mod h1:jAgpNQn7T7BnibUeReXcKU9Ha1xmYNyOlwVEl193ow0=
345+
github.com/ipfs/boxo v0.16.1-0.20240102133734-dc2f8b06ce71 h1:4WeZGWkOD4Wr2aGm7xXWdwGgPZbCYHjaz+gVaxx1sJ8=
346+
github.com/ipfs/boxo v0.16.1-0.20240102133734-dc2f8b06ce71/go.mod h1:jAgpNQn7T7BnibUeReXcKU9Ha1xmYNyOlwVEl193ow0=
347347
github.com/ipfs/go-block-format v0.2.0 h1:ZqrkxBA2ICbDRbK8KJs/u0O3dlp6gmAuuXUJNiW1Ycs=
348348
github.com/ipfs/go-block-format v0.2.0/go.mod h1:+jpL11nFx5A/SPpsoBn6Bzkra/zaArfSmsknbPMYgzM=
349349
github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s=

0 commit comments

Comments
 (0)