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 +69
-0
lines changed
Expand file tree Collapse file tree 2 files changed +69
-0
lines changed Original file line number Diff line number Diff line change @@ -307,6 +307,41 @@ func (s *Shell) Unpin(path string) error {
307307 return nil
308308}
309309
310+ const (
311+ DirectPin = "direct"
312+ RecursivePin = "recursive"
313+ IndirectPin = "indirect"
314+ )
315+
316+ type PinInfo struct {
317+ Type string
318+ }
319+
320+ // Pins returns a map of the pin hashes to their info (currently just the
321+ // pin type, one of DirectPin, RecursivePin, or IndirectPin. A map is returned
322+ // instead of a slice because it is easier to do existence lookup by map key
323+ // than unordered array searching. The map is likely to be more useful to a
324+ // client than a flat list.
325+ func (s * Shell ) Pins () (map [string ]PinInfo , error ) {
326+ resp , err := s .newRequest ("pin/ls" ).Send (s .httpcli )
327+ if err != nil {
328+ return nil , err
329+ }
330+ defer resp .Close ()
331+
332+ if resp .Error != nil {
333+ return nil , resp .Error
334+ }
335+
336+ raw := struct { Keys map [string ]PinInfo }{}
337+ err = json .NewDecoder (resp .Output ).Decode (& raw )
338+ if err != nil {
339+ return nil , err
340+ }
341+
342+ return raw .Keys , nil
343+ }
344+
310345type PeerInfo struct {
311346 Addrs []string
312347 ID string
Original file line number Diff line number Diff line change @@ -92,6 +92,40 @@ func TestFileList(t *testing.T) {
9292 }
9393}
9494
95+ func TestPins (t * testing.T ) {
96+ is := is .New (t )
97+ s := NewShell (shellUrl )
98+
99+ // Add a thing, which pins it by default
100+ h , err := s .Add (bytes .NewBufferString ("go-ipfs-api pins test 9F3D1F30-D12A-4024-9477-8F0C8E4B3A63" ))
101+ is .Nil (err )
102+
103+ pins , err := s .Pins ()
104+ is .Nil (err )
105+
106+ _ , ok := pins [h ]
107+ is .True (ok )
108+
109+ err = s .Unpin (h )
110+ is .Nil (err )
111+
112+ pins , err = s .Pins ()
113+ is .Nil (err )
114+
115+ _ , ok = pins [h ]
116+ is .False (ok )
117+
118+ err = s .Pin (h )
119+ is .Nil (err )
120+
121+ pins , err = s .Pins ()
122+ is .Nil (err )
123+
124+ info , ok := pins [h ]
125+ is .True (ok )
126+ is .Equal (info .Type , RecursivePin )
127+ }
128+
95129func TestPatch_rmLink (t * testing.T ) {
96130 is := is .New (t )
97131 s := NewShell (shellUrl )
You can’t perform that action at this time.
0 commit comments