Skip to content
This repository was archived by the owner on Oct 5, 2023. It is now read-only.

Commit 4e8a6c8

Browse files
petargodcongaschmahmann
authored
Bump interface-go-ipfs-core version (#117)
* fix issues #26 Implement an IsPinned function * fix issues #113 Implement interface v0.3.0 * ci: update to use go-ipfs v0.6.0 * ci: bump go version Co-authored-by: godcong <[email protected]> Co-authored-by: Adin Schmahmann <[email protected]>
1 parent 7002cce commit 4e8a6c8

File tree

4 files changed

+51
-14
lines changed

4 files changed

+51
-14
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ os:
44
language: go
55

66
go:
7-
- 1.13.x
7+
- 1.14.x
88

99
env:
1010
global:
@@ -16,7 +16,7 @@ env:
1616

1717
# disable travis install
1818
install:
19-
- (cd /tmp && go get github.com/ipfs/go-ipfs/cmd/ipfs@v0.5.0-rc2)
19+
- (cd /tmp && go get github.com/ipfs/go-ipfs/cmd/ipfs@v0.6.0)
2020

2121
script:
2222
- bash <(curl -s https://raw.githubusercontent.com/ipfs/ci-helpers/master/travis-ci/run-standard-tests.sh)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/ipfs/go-merkledag v0.3.1
1010
github.com/ipfs/go-path v0.0.7
1111
github.com/ipfs/go-unixfs v0.2.4
12-
github.com/ipfs/interface-go-ipfs-core v0.2.6
12+
github.com/ipfs/interface-go-ipfs-core v0.3.0
1313
github.com/ipfs/iptb v1.4.0
1414
github.com/ipfs/iptb-plugins v0.2.2
1515
github.com/libp2p/go-libp2p-core v0.5.1

go.sum

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
4444
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
4545
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4646
github.com/dgraph-io/badger v1.5.5-0.20190226225317-8115aed38f8f/go.mod h1:VZxzAIRPHRVNRKRo6AXrX9BJegn6il06VMTZVJYCIjQ=
47+
github.com/dgraph-io/badger v1.6.0-rc1 h1:JphPpoBZJ3WHha133BGYlQqltSGIhV+VsEID0++nN9A=
4748
github.com/dgraph-io/badger v1.6.0-rc1/go.mod h1:zwt7syl517jmP8s94KqSxTlM6IMsdhYy6psNgSztDR4=
4849
github.com/dgryski/go-farm v0.0.0-20190104051053-3adb47b1fb0f/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
4950
github.com/dgryski/go-farm v0.0.0-20190423205320-6a90982ecee2/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
@@ -201,8 +202,8 @@ github.com/ipfs/go-unixfs v0.2.4 h1:6NwppOXefWIyysZ4LR/qUBPvXd5//8J3jiMdvpbw6Lo=
201202
github.com/ipfs/go-unixfs v0.2.4/go.mod h1:SUdisfUjNoSDzzhGVxvCL9QO/nKdwXdr+gbMUdqcbYw=
202203
github.com/ipfs/go-verifcid v0.0.1 h1:m2HI7zIuR5TFyQ1b79Da5N9dnnCP1vcu2QqawmWlK2E=
203204
github.com/ipfs/go-verifcid v0.0.1/go.mod h1:5Hrva5KBeIog4A+UpqlaIU+DEstipcJYQQZc0g37pY0=
204-
github.com/ipfs/interface-go-ipfs-core v0.2.6 h1:4eeGPJUDWblEurSzpAtL2znDG1xqAoX2aNNIoOFwyuc=
205-
github.com/ipfs/interface-go-ipfs-core v0.2.6/go.mod h1:Tihp8zxGpUeE3Tokr94L6zWZZdkRQvG5TL6i9MuNE+s=
205+
github.com/ipfs/interface-go-ipfs-core v0.3.0 h1:oZdLLfh256gPGcYPURjivj/lv296GIcr8mUqZUnXOEI=
206+
github.com/ipfs/interface-go-ipfs-core v0.3.0/go.mod h1:Tihp8zxGpUeE3Tokr94L6zWZZdkRQvG5TL6i9MuNE+s=
206207
github.com/ipfs/iptb v1.4.0 h1:YFYTrCkLMRwk/35IMyC6+yjoQSHTEcNcefBStLJzgvo=
207208
github.com/ipfs/iptb v1.4.0/go.mod h1:1rzHpCYtNp87/+hTxG5TfCVn/yMY3dKnLn8tBiMfdmg=
208209
github.com/ipfs/iptb-plugins v0.2.2 h1:HleRKMeex/jmQrmNG36v51M3eZO5j9BhFplBPGs0qGQ=

pin.go

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ package httpapi
33
import (
44
"context"
55
"encoding/json"
6+
"strings"
67

78
"github.com/ipfs/go-cid"
8-
"github.com/ipfs/interface-go-ipfs-core"
9+
iface "github.com/ipfs/interface-go-ipfs-core"
910
caopts "github.com/ipfs/interface-go-ipfs-core/options"
1011
"github.com/ipfs/interface-go-ipfs-core/path"
1112
"github.com/pkg/errors"
@@ -24,6 +25,11 @@ type pinRefKeyList struct {
2425
type pin struct {
2526
path path.Resolved
2627
typ string
28+
err error
29+
}
30+
31+
func (p *pin) Err() error {
32+
return p.err
2733
}
2834

2935
func (p *pin) Path() path.Resolved {
@@ -44,7 +50,7 @@ func (api *PinAPI) Add(ctx context.Context, p path.Path, opts ...caopts.PinAddOp
4450
Option("recursive", options.Recursive).Exec(ctx, nil)
4551
}
4652

47-
func (api *PinAPI) Ls(ctx context.Context, opts ...caopts.PinLsOption) ([]iface.Pin, error) {
53+
func (api *PinAPI) Ls(ctx context.Context, opts ...caopts.PinLsOption) (<-chan iface.Pin, error) {
4854
options, err := caopts.PinLsOptions(opts...)
4955
if err != nil {
5056
return nil, err
@@ -57,16 +63,46 @@ func (api *PinAPI) Ls(ctx context.Context, opts ...caopts.PinLsOption) ([]iface.
5763
return nil, err
5864
}
5965

60-
pins := make([]iface.Pin, 0, len(out.Keys))
61-
for hash, p := range out.Keys {
62-
c, err := cid.Parse(hash)
63-
if err != nil {
64-
return nil, err
66+
pins := make(chan iface.Pin)
67+
go func(ch chan<- iface.Pin) {
68+
defer close(ch)
69+
for hash, p := range out.Keys {
70+
c, e := cid.Parse(hash)
71+
if e != nil {
72+
ch <- &pin{typ: p.Type, err: e}
73+
return
74+
}
75+
ch <- &pin{typ: p.Type, path: path.IpldPath(c), err: e}
6576
}
66-
pins = append(pins, &pin{typ: p.Type, path: path.IpldPath(c)})
77+
}(pins)
78+
return pins, nil
79+
}
80+
81+
// IsPinned returns whether or not the given cid is pinned
82+
// and an explanation of why its pinned
83+
func (api *PinAPI) IsPinned(ctx context.Context, p path.Path, opts ...caopts.PinIsPinnedOption) (string, bool, error) {
84+
options, err := caopts.PinIsPinnedOptions(opts...)
85+
if err != nil {
86+
return "", false, err
87+
}
88+
var out pinRefKeyList
89+
err = api.core().Request("pin/ls").
90+
Option("type", options.WithType).
91+
Option("arg", p.String()).
92+
Exec(ctx, &out)
93+
if err != nil {
94+
// TODO: This error-type discrimination based on sub-string matching is brittle.
95+
// It is addressed by this open issue: https://github.com/ipfs/go-ipfs/issues/7563
96+
if strings.Index(err.Error(), "is not pinned") != -1 {
97+
return "", false, nil
98+
}
99+
return "", false, err
67100
}
68101

69-
return pins, nil
102+
for _, obj := range out.Keys {
103+
return obj.Type, true, nil
104+
}
105+
return "", false, errors.New("http api returned no error and no results")
70106
}
71107

72108
func (api *PinAPI) Rm(ctx context.Context, p path.Path, opts ...caopts.PinRmOption) error {

0 commit comments

Comments
 (0)