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

Commit 6062f4d

Browse files
authored
Merge pull request #16 from ipfs/feat/update-paths
Update interface - path changes
2 parents 0b1bf38 + e53361d commit 6062f4d

17 files changed

+83
-184
lines changed

.gx/lastpubver

Lines changed: 0 additions & 1 deletion
This file was deleted.

.travis.yml

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

66
go:
7-
- 1.11.x
7+
- 1.12.x
88

99
env:
1010
global:
@@ -15,7 +15,6 @@ env:
1515

1616
# disable travis install
1717
install:
18-
- make deps
1918
- go get -d github.com/ipfs/go-ipfs
2019
- (cd $GOPATH/src/github.com/ipfs/go-ipfs; make install)
2120

@@ -25,7 +24,6 @@ script:
2524

2625
cache:
2726
directories:
28-
- $GOPATH/src/gx
2927
- $GOPATH/pkg/mod
3028
- $HOME/.cache/go-build
3129

Makefile

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,4 @@
1-
all: deps
2-
gx:
3-
go get github.com/whyrusleeping/gx
4-
go get github.com/whyrusleeping/gx-go
5-
deps: gx
6-
gx --verbose install --global
7-
gx-go rewrite
8-
test: deps
9-
gx test -v -race -coverprofile=coverage.txt -covermode=atomic .
10-
rw:
11-
gx-go rewrite
12-
rwundo:
13-
gx-go rewrite --undo
14-
publish: rwundo
15-
gx publish
16-
.PHONY: all gx deps test rw rwundo publish
1+
test:
2+
go test -v -race -coverprofile=coverage.txt -covermode=atomic .
3+
4+
.PHONY: test

api_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"testing"
1111

1212
"github.com/ipfs/interface-go-ipfs-core"
13+
"github.com/ipfs/interface-go-ipfs-core/path"
1314
"github.com/ipfs/interface-go-ipfs-core/tests"
1415
local "github.com/ipfs/iptb-plugins/local"
1516
"github.com/ipfs/iptb/testbed"
@@ -171,11 +172,7 @@ func (NodeProvider) makeAPISwarm(ctx context.Context, fullIdentity bool, n int)
171172
}
172173

173174
// empty node is pinned even with --empty-repo, we don't want that
174-
emptyNode, err := iface.ParsePath("/ipfs/QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn")
175-
if err != nil {
176-
errs <- err
177-
return
178-
}
175+
emptyNode := path.New("/ipfs/QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn")
179176
if err := apis[i].Pin().Rm(ctx, emptyNode); err != nil {
180177
errs <- err
181178
return

apifile.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import (
1010
"github.com/ipfs/go-cid"
1111
files "github.com/ipfs/go-ipfs-files"
1212
unixfs "github.com/ipfs/go-unixfs"
13-
iface "github.com/ipfs/interface-go-ipfs-core"
13+
"github.com/ipfs/interface-go-ipfs-core/path"
1414
)
1515

1616
const forwardSeekLimit = 1 << 14 //16k
1717

18-
func (api *UnixfsAPI) Get(ctx context.Context, p iface.Path) (files.Node, error) {
18+
func (api *UnixfsAPI) Get(ctx context.Context, p path.Path) (files.Node, error) {
1919
if p.Mutable() { // use resolved path in case we are dealing with IPNS / MFS
2020
var err error
2121
p, err = api.core().ResolvePath(ctx, p)
@@ -48,7 +48,7 @@ type apiFile struct {
4848
ctx context.Context
4949
core *HttpApi
5050
size int64
51-
path iface.Path
51+
path path.Path
5252

5353
r *Response
5454
at int64
@@ -114,7 +114,7 @@ func (f *apiFile) Size() (int64, error) {
114114
return f.size, nil
115115
}
116116

117-
func (api *UnixfsAPI) getFile(ctx context.Context, p iface.Path, size int64) (files.Node, error) {
117+
func (api *UnixfsAPI) getFile(ctx context.Context, p path.Path, size int64) (files.Node, error) {
118118
f := &apiFile{
119119
ctx: ctx,
120120
core: api.core(),
@@ -177,13 +177,13 @@ func (it *apiIter) Next() bool {
177177

178178
switch it.cur.Type {
179179
case unixfs.THAMTShard, unixfs.TMetadata, unixfs.TDirectory:
180-
it.curFile, err = it.core.getDir(it.ctx, iface.IpfsPath(c), int64(it.cur.Size))
180+
it.curFile, err = it.core.getDir(it.ctx, path.IpfsPath(c), int64(it.cur.Size))
181181
if err != nil {
182182
it.err = err
183183
return false
184184
}
185185
case unixfs.TFile:
186-
it.curFile, err = it.core.getFile(it.ctx, iface.IpfsPath(c), int64(it.cur.Size))
186+
it.curFile, err = it.core.getFile(it.ctx, path.IpfsPath(c), int64(it.cur.Size))
187187
if err != nil {
188188
it.err = err
189189
return false
@@ -203,7 +203,7 @@ type apiDir struct {
203203
ctx context.Context
204204
core *UnixfsAPI
205205
size int64
206-
path iface.Path
206+
path path.Path
207207

208208
dec *json.Decoder
209209
}
@@ -224,7 +224,7 @@ func (d *apiDir) Entries() files.DirIterator {
224224
}
225225
}
226226

227-
func (api *UnixfsAPI) getDir(ctx context.Context, p iface.Path, size int64) (files.Node, error) {
227+
func (api *UnixfsAPI) getDir(ctx context.Context, p path.Path, size int64) (files.Node, error) {
228228
resp, err := api.core().Request("ls", p.String()).
229229
Option("resolve-size", true).
230230
Option("stream", true).Send(ctx)

block.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/ipfs/go-cid"
1111
"github.com/ipfs/interface-go-ipfs-core"
1212
caopts "github.com/ipfs/interface-go-ipfs-core/options"
13+
"github.com/ipfs/interface-go-ipfs-core/path"
1314
mh "github.com/multiformats/go-multihash"
1415
)
1516

@@ -26,8 +27,8 @@ func (s *blockStat) Size() int {
2627
return s.BSize
2728
}
2829

29-
func (s *blockStat) Path() iface.ResolvedPath {
30-
return iface.IpldPath(s.cid)
30+
func (s *blockStat) Path() path.Resolved {
31+
return path.IpldPath(s.cid)
3132
}
3233

3334
func (api *BlockAPI) Put(ctx context.Context, r io.Reader, opts ...caopts.BlockPutOption) (iface.BlockStat, error) {
@@ -60,7 +61,7 @@ func (api *BlockAPI) Put(ctx context.Context, r io.Reader, opts ...caopts.BlockP
6061
return &out, nil
6162
}
6263

63-
func (api *BlockAPI) Get(ctx context.Context, p iface.Path) (io.Reader, error) {
64+
func (api *BlockAPI) Get(ctx context.Context, p path.Path) (io.Reader, error) {
6465
resp, err := api.core().Request("block/get", p.String()).Send(ctx)
6566
if err != nil {
6667
return nil, err
@@ -79,7 +80,7 @@ func (api *BlockAPI) Get(ctx context.Context, p iface.Path) (io.Reader, error) {
7980
return b, nil
8081
}
8182

82-
func (api *BlockAPI) Rm(ctx context.Context, p iface.Path, opts ...caopts.BlockRmOption) error {
83+
func (api *BlockAPI) Rm(ctx context.Context, p path.Path, opts ...caopts.BlockRmOption) error {
8384
options, err := caopts.BlockRmOptions(opts...)
8485
if err != nil {
8586
return err
@@ -105,7 +106,7 @@ func (api *BlockAPI) Rm(ctx context.Context, p iface.Path, opts ...caopts.BlockR
105106
return nil
106107
}
107108

108-
func (api *BlockAPI) Stat(ctx context.Context, p iface.Path) (iface.BlockStat, error) {
109+
func (api *BlockAPI) Stat(ctx context.Context, p path.Path) (iface.BlockStat, error) {
109110
var out blockStat
110111
err := api.core().Request("block/stat", p.String()).Exec(ctx, &out)
111112
if err != nil {

dag.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@ import (
99
"github.com/ipfs/go-block-format"
1010
"github.com/ipfs/go-cid"
1111
"github.com/ipfs/go-ipld-format"
12-
"github.com/ipfs/interface-go-ipfs-core"
1312
"github.com/ipfs/interface-go-ipfs-core/options"
13+
"github.com/ipfs/interface-go-ipfs-core/path"
1414
)
1515

1616
type httpNodeAdder HttpApi
1717
type HttpDagServ httpNodeAdder
1818
type pinningHttpNodeAdder httpNodeAdder
1919

2020
func (api *HttpDagServ) Get(ctx context.Context, c cid.Cid) (format.Node, error) {
21-
r, err := api.core().Block().Get(ctx, iface.IpldPath(c))
21+
r, err := api.core().Block().Get(ctx, path.IpldPath(c))
2222
if err != nil {
2323
return nil, err
2424
}
@@ -105,7 +105,7 @@ func (api *HttpDagServ) Pinning() format.NodeAdder {
105105
}
106106

107107
func (api *HttpDagServ) Remove(ctx context.Context, c cid.Cid) error {
108-
return api.core().Block().Rm(ctx, iface.IpldPath(c)) //TODO: should we force rm?
108+
return api.core().Block().Rm(ctx, path.IpldPath(c)) //TODO: should we force rm?
109109
}
110110

111111
func (api *HttpDagServ) RemoveMany(ctx context.Context, cids []cid.Cid) error {

dht.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"context"
55
"encoding/json"
66

7-
"github.com/ipfs/interface-go-ipfs-core"
87
caopts "github.com/ipfs/interface-go-ipfs-core/options"
8+
"github.com/ipfs/interface-go-ipfs-core/path"
99
"github.com/libp2p/go-libp2p-peer"
1010
"github.com/libp2p/go-libp2p-peerstore"
1111
notif "github.com/libp2p/go-libp2p-routing/notifications"
@@ -37,7 +37,7 @@ func (api *DhtAPI) FindPeer(ctx context.Context, p peer.ID) (peerstore.PeerInfo,
3737
}
3838
}
3939

40-
func (api *DhtAPI) FindProviders(ctx context.Context, p iface.Path, opts ...caopts.DhtFindProvidersOption) (<-chan peerstore.PeerInfo, error) {
40+
func (api *DhtAPI) FindProviders(ctx context.Context, p path.Path, opts ...caopts.DhtFindProvidersOption) (<-chan peerstore.PeerInfo, error) {
4141
options, err := caopts.DhtFindProvidersOptions(opts...)
4242
if err != nil {
4343
return nil, err
@@ -93,7 +93,7 @@ func (api *DhtAPI) FindProviders(ctx context.Context, p iface.Path, opts ...caop
9393
return res, nil
9494
}
9595

96-
func (api *DhtAPI) Provide(ctx context.Context, p iface.Path, opts ...caopts.DhtProvideOption) error {
96+
func (api *DhtAPI) Provide(ctx context.Context, p path.Path, opts ...caopts.DhtProvideOption) error {
9797
options, err := caopts.DhtProvideOptions(opts...)
9898
if err != nil {
9999
return err

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/ipfs/go-merkledag v0.0.3
99
github.com/ipfs/go-path v0.0.3
1010
github.com/ipfs/go-unixfs v0.0.4
11-
github.com/ipfs/interface-go-ipfs-core v0.0.6
11+
github.com/ipfs/interface-go-ipfs-core v0.0.7
1212
github.com/ipfs/iptb v1.4.0
1313
github.com/ipfs/iptb-plugins v0.0.1
1414
github.com/libp2p/go-libp2p-net v0.0.1

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ github.com/ipfs/go-verifcid v0.0.1 h1:m2HI7zIuR5TFyQ1b79Da5N9dnnCP1vcu2QqawmWlK2
125125
github.com/ipfs/go-verifcid v0.0.1/go.mod h1:5Hrva5KBeIog4A+UpqlaIU+DEstipcJYQQZc0g37pY0=
126126
github.com/ipfs/interface-go-ipfs-core v0.0.6 h1:yf9D2cMLVgBMXHL+gs/HepDc/M7ZXQXYdoN0eXl7z9c=
127127
github.com/ipfs/interface-go-ipfs-core v0.0.6/go.mod h1:VceUOYu+kPEy8Ev/gAhzXFTIfc/7xILKnL4fgZg8tZM=
128+
github.com/ipfs/interface-go-ipfs-core v0.0.7 h1:KfPVykJTT2viS/NdIC7xUEmnS9jDufl3FXivatAxtZM=
129+
github.com/ipfs/interface-go-ipfs-core v0.0.7/go.mod h1:VceUOYu+kPEy8Ev/gAhzXFTIfc/7xILKnL4fgZg8tZM=
128130
github.com/ipfs/iptb v1.4.0 h1:YFYTrCkLMRwk/35IMyC6+yjoQSHTEcNcefBStLJzgvo=
129131
github.com/ipfs/iptb v1.4.0/go.mod h1:1rzHpCYtNp87/+hTxG5TfCVn/yMY3dKnLn8tBiMfdmg=
130132
github.com/ipfs/iptb-plugins v0.0.1 h1:aUHbQ4y8/lKIBX/FN0KXe3c4NldPLsq7VyW2CcFXbhE=

key.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66

77
"github.com/ipfs/interface-go-ipfs-core"
88
caopts "github.com/ipfs/interface-go-ipfs-core/options"
9+
"github.com/ipfs/interface-go-ipfs-core/path"
910
"github.com/libp2p/go-libp2p-peer"
1011
)
1112

@@ -22,9 +23,8 @@ func (k *keyOutput) Name() string {
2223
return k.JName
2324
}
2425

25-
func (k *keyOutput) Path() iface.Path {
26-
p, _ := iface.ParsePath("/ipns/" + k.Id)
27-
return p
26+
func (k *keyOutput) Path() path.Path {
27+
return path.New("/ipns/" + k.Id)
2828
}
2929

3030
func (k *keyOutput) ID() peer.ID {

name.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/ipfs/interface-go-ipfs-core"
1010
caopts "github.com/ipfs/interface-go-ipfs-core/options"
1111
"github.com/ipfs/interface-go-ipfs-core/options/namesys"
12+
"github.com/ipfs/interface-go-ipfs-core/path"
1213
)
1314

1415
type NameAPI HttpApi
@@ -17,18 +18,18 @@ type ipnsEntry struct {
1718
JName string `json:"Name"`
1819
JValue string `json:"Value"`
1920

20-
path iface.Path
21+
path path.Path
2122
}
2223

2324
func (e *ipnsEntry) Name() string {
2425
return e.JName
2526
}
2627

27-
func (e *ipnsEntry) Value() iface.Path {
28+
func (e *ipnsEntry) Value() path.Path {
2829
return e.path
2930
}
3031

31-
func (api *NameAPI) Publish(ctx context.Context, p iface.Path, opts ...caopts.NamePublishOption) (iface.IpnsEntry, error) {
32+
func (api *NameAPI) Publish(ctx context.Context, p path.Path, opts ...caopts.NamePublishOption) (iface.IpnsEntry, error) {
3233
options, err := caopts.NamePublishOptions(opts...)
3334
if err != nil {
3435
return nil, err
@@ -48,8 +49,8 @@ func (api *NameAPI) Publish(ctx context.Context, p iface.Path, opts ...caopts.Na
4849
if err := req.Exec(ctx, &out); err != nil {
4950
return nil, err
5051
}
51-
out.path, err = iface.ParsePath(out.JValue)
52-
return &out, err
52+
out.path = path.New(out.JValue)
53+
return &out, out.path.IsValid()
5354
}
5455

5556
func (api *NameAPI) Search(ctx context.Context, name string, opts ...caopts.NameResolveOption) (<-chan iface.IpnsResult, error) {
@@ -93,7 +94,7 @@ func (api *NameAPI) Search(ctx context.Context, name string, opts ...caopts.Name
9394
}
9495
var ires iface.IpnsResult
9596
if err == nil {
96-
ires.Path, err = iface.ParsePath(out.Path)
97+
ires.Path = path.New(out.Path)
9798
}
9899

99100
select {
@@ -109,7 +110,7 @@ func (api *NameAPI) Search(ctx context.Context, name string, opts ...caopts.Name
109110
return res, nil
110111
}
111112

112-
func (api *NameAPI) Resolve(ctx context.Context, name string, opts ...caopts.NameResolveOption) (iface.Path, error) {
113+
func (api *NameAPI) Resolve(ctx context.Context, name string, opts ...caopts.NameResolveOption) (path.Path, error) {
113114
options, err := caopts.NameResolveOptions(opts...)
114115
if err != nil {
115116
return nil, err
@@ -131,7 +132,7 @@ func (api *NameAPI) Resolve(ctx context.Context, name string, opts ...caopts.Nam
131132
return nil, err
132133
}
133134

134-
return iface.ParsePath(out.Path)
135+
return path.New(out.Path), nil
135136
}
136137

137138
func (api *NameAPI) core() *HttpApi {

0 commit comments

Comments
 (0)