This repository was archived by the owner on Feb 7, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +45
-3
lines changed Expand file tree Collapse file tree 2 files changed +45
-3
lines changed Original file line number Diff line number Diff line change @@ -217,10 +217,12 @@ func (s *Shell) Unpin(path string) error {
217
217
Exec (context .Background (), nil )
218
218
}
219
219
220
+ type PinType string
221
+
220
222
const (
221
- DirectPin = "direct"
222
- RecursivePin = "recursive"
223
- IndirectPin = "indirect"
223
+ DirectPin PinType = "direct"
224
+ RecursivePin PinType = "recursive"
225
+ IndirectPin PinType = "indirect"
224
226
)
225
227
226
228
type PinInfo struct {
@@ -237,6 +239,12 @@ func (s *Shell) Pins() (map[string]PinInfo, error) {
237
239
return raw .Keys , s .Request ("pin/ls" ).Exec (context .Background (), & raw )
238
240
}
239
241
242
+ // Pins returns a map of the pins of specified type (DirectPin, RecursivePin, or IndirectPin)
243
+ func (s * Shell ) PinsOfType (ctx context.Context , pinType PinType ) (map [string ]PinInfo , error ) {
244
+ var raw struct { Keys map [string ]PinInfo }
245
+ return raw .Keys , s .Request ("pin/ls" ).Option ("type" , pinType ).Exec (ctx , & raw )
246
+ }
247
+
240
248
// PinStreamInfo is the output type for PinsStream
241
249
type PinStreamInfo struct {
242
250
Cid string
Original file line number Diff line number Diff line change @@ -239,6 +239,40 @@ func TestPins(t *testing.T) {
239
239
is .Equal (info .Type , RecursivePin )
240
240
}
241
241
242
+ func TestPinsOfType (t * testing.T ) {
243
+ is := is .New (t )
244
+ s := NewShell (shellUrl )
245
+
246
+ // Add a thing, which pins it by default
247
+ h , err := s .Add (bytes .NewBufferString ("go-ipfs-api pins test 9F3D1F30-D12A-4024-9477-8F0C8E4B3A63" ))
248
+ is .Nil (err )
249
+
250
+ pins , err := s .PinsOfType (context .Background (), RecursivePin )
251
+ is .Nil (err )
252
+
253
+ _ , ok := pins [h ]
254
+ is .True (ok )
255
+
256
+ err = s .Unpin (h )
257
+ is .Nil (err )
258
+
259
+ pins , err = s .Pins ()
260
+ is .Nil (err )
261
+
262
+ _ , ok = pins [h ]
263
+ is .False (ok )
264
+
265
+ err = s .Pin (h )
266
+ is .Nil (err )
267
+
268
+ pins , err = s .Pins ()
269
+ is .Nil (err )
270
+
271
+ info , ok := pins [h ]
272
+ is .True (ok )
273
+ is .Equal (info .Type , RecursivePin )
274
+ }
275
+
242
276
func TestPinsStream (t * testing.T ) {
243
277
is := is .New (t )
244
278
s := NewShell (shellUrl )
You can’t perform that action at this time.
0 commit comments