update interface-go-ipfs-core and handle breaking changes
* No more Hidden, StdinName, and Wrap options. * LsLink -> DirEntry with file types that don't expose internals. This commit was moved from ipfs/go-ipfs-http-client@5a7161eeab7127da4348dda6a6dc16f07b051f36
Steven Allen committed
Mar 26, 2019 at 18:15 UTC
0e800c3d8431fdcdc22ee2a2ac3337cb009553c3
2 files changed
+35
-36
client/httpapi/apifile.go
+5
-8
@@ -8,8 +8,9 @@ import (
8
"io/ioutil"
9
10
"github.com/ipfs/go-cid"
11
- "github.com/ipfs/go-ipfs-files"
12
- "github.com/ipfs/interface-go-ipfs-core"
11
+ files "github.com/ipfs/go-ipfs-files"
12
+ unixfs "github.com/ipfs/go-unixfs"
13
+ iface "github.com/ipfs/interface-go-ipfs-core"
14
)
15
16
const forwardSeekLimit = 1 << 14 //16k
@@ -174,17 +175,13 @@ func (it *apiIter) Next() bool {
175
}
176
177
switch it.cur.Type {
177
- case iface.THAMTShard:
178
- fallthrough
179
- case iface.TMetadata:
180
- fallthrough
181
- case iface.TDirectory:
178
+ case unixfs.THAMTShard, unixfs.TMetadata, unixfs.TDirectory:
179
it.curFile, err = it.core.getDir(it.ctx, iface.IpfsPath(c), int64(it.cur.Size))
180
if err != nil {
181
it.err = err
182
return false
183
}
187
- case iface.TFile:
184
+ case unixfs.TFile:
185
it.curFile, err = it.core.getFile(it.ctx, iface.IpfsPath(c), int64(it.cur.Size))
186
if err != nil {
187
it.err = err
client/httpapi/unixfs.go
+30
-28
@@ -8,9 +8,10 @@ import (
8
"io"
9
10
"github.com/ipfs/go-cid"
11
- "github.com/ipfs/go-ipfs-files"
12
- "github.com/ipfs/go-ipld-format"
13
- "github.com/ipfs/interface-go-ipfs-core"
11
+ files "github.com/ipfs/go-ipfs-files"
12
+ unixfs "github.com/ipfs/go-unixfs"
13
+ unixfs_pb "github.com/ipfs/go-unixfs/pb"
14
+ iface "github.com/ipfs/interface-go-ipfs-core"
15
caopts "github.com/ipfs/interface-go-ipfs-core/options"
16
mh "github.com/multiformats/go-multihash"
17
)
@@ -40,15 +41,12 @@ func (api *UnixfsAPI) Add(ctx context.Context, f files.Node, opts ...caopts.Unix
41
Option("chunker", options.Chunker).
42
Option("cid-version", options.CidVersion).
43
Option("fscache", options.FsCache).
43
- Option("hidden", options.Hidden).
44
Option("inline", options.Inline).
45
Option("inline-limit", options.InlineLimit).
46
Option("nocopy", options.NoCopy).
47
Option("only-hash", options.OnlyHash).
48
Option("pin", options.Pin).
49
Option("silent", options.Silent).
50
- Option("stdin-name", options.StdinName).
51
- Option("wrap-with-directory", options.Wrap).
50
Option("progress", options.Progress)
51
52
if options.RawLeavesSet {
@@ -62,13 +60,8 @@ func (api *UnixfsAPI) Add(ctx context.Context, f files.Node, opts ...caopts.Unix
60
req.Option("trickle", true)
61
}
62
65
- switch c := f.(type) {
66
- case files.Directory:
67
- req.Body(files.NewMultiFileReader(c, false))
68
- case files.File:
69
- d := files.NewMapDirectory(map[string]files.Node{"": c}) // unwrapped on the other side
70
- req.Body(files.NewMultiFileReader(d, false))
71
- }
63
+ d := files.NewMapDirectory(map[string]files.Node{"": f}) // unwrapped on the other side
64
+ req.Body(files.NewMultiFileReader(d, false))
65
66
var out addEvent
67
resp, err := req.Send(ctx)
@@ -127,7 +120,8 @@ loop:
120
type lsLink struct {
121
Name, Hash string
122
Size uint64
130
- Type iface.FileType
123
+ Type unixfs_pb.Data_DataType
124
+ Target string
125
}
126
127
type lsObject struct {
@@ -139,7 +133,7 @@ type lsOutput struct {
133
Objects []lsObject
134
}
135
142
-func (api *UnixfsAPI) Ls(ctx context.Context, p iface.Path, opts ...caopts.UnixfsLsOption) (<-chan iface.LsLink, error) {
136
+func (api *UnixfsAPI) Ls(ctx context.Context, p iface.Path, opts ...caopts.UnixfsLsOption) (<-chan iface.DirEntry, error) {
137
options, err := caopts.UnixfsLsOptions(opts...)
138
if err != nil {
139
return nil, err
@@ -158,7 +152,7 @@ func (api *UnixfsAPI) Ls(ctx context.Context, p iface.Path, opts ...caopts.Unixf
152
}
153
154
dec := json.NewDecoder(resp.Output)
161
- out := make(chan iface.LsLink)
155
+ out := make(chan iface.DirEntry)
156
157
go func() {
158
defer resp.Close()
@@ -171,7 +165,7 @@ func (api *UnixfsAPI) Ls(ctx context.Context, p iface.Path, opts ...caopts.Unixf
165
return
166
}
167
select {
174
- case out <- iface.LsLink{Err: err}:
168
+ case out <- iface.DirEntry{Err: err}:
169
case <-ctx.Done():
170
}
171
return
@@ -179,7 +173,7 @@ func (api *UnixfsAPI) Ls(ctx context.Context, p iface.Path, opts ...caopts.Unixf
173
174
if len(link.Objects) != 1 {
175
select {
182
- case out <- iface.LsLink{Err: errors.New("unexpected Objects len")}:
176
+ case out <- iface.DirEntry{Err: errors.New("unexpected Objects len")}:
177
case <-ctx.Done():
178
}
179
return
@@ -187,7 +181,7 @@ func (api *UnixfsAPI) Ls(ctx context.Context, p iface.Path, opts ...caopts.Unixf
181
182
if len(link.Objects[0].Links) != 1 {
183
select {
190
- case out <- iface.LsLink{Err: errors.New("unexpected Links len")}:
184
+ case out <- iface.DirEntry{Err: errors.New("unexpected Links len")}:
185
case <-ctx.Done():
186
}
187
return
@@ -198,21 +192,29 @@ func (api *UnixfsAPI) Ls(ctx context.Context, p iface.Path, opts ...caopts.Unixf
192
c, err := cid.Decode(l0.Hash)
193
if err != nil {
194
select {
201
- case out <- iface.LsLink{Err: err}:
195
+ case out <- iface.DirEntry{Err: err}:
196
case <-ctx.Done():
197
}
198
return
199
}
200
201
+ var ftype iface.FileType
202
+ switch l0.Type {
203
+ case unixfs.TRaw, unixfs.TFile:
204
+ ftype = iface.TFile
205
+ case unixfs.THAMTShard, unixfs.TDirectory, unixfs.TMetadata:
206
+ ftype = iface.TDirectory
207
+ case unixfs.TSymlink:
208
+ ftype = iface.TSymlink
209
+ }
210
+
211
select {
208
- case out <- iface.LsLink{
209
- Link: &format.Link{
210
- Cid: c,
211
- Name: l0.Name,
212
- Size: l0.Size,
213
- },
214
- Size: l0.Size,
215
- Type: l0.Type,
212
+ case out <- iface.DirEntry{
213
+ Name: l0.Name,
214
+ Cid: c,
215
+ Size: l0.Size,
216
+ Type: ftype,
217
+ Target: l0.Target,
218
}:
219
case <-ctx.Done():
220
}