mirror of
https://github.com/ipfs/kubo.git
synced 2026-02-22 10:57:42 +08:00
Merge pull request ipfs/go-ipfs-http-client#16 from ipfs/feat/update-paths
Update interface - path changes This commit was moved from ipfs/go-ipfs-http-client@6062f4dc5c
This commit is contained in:
commit
ea34bcbd0e
@ -10,6 +10,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/ipfs/interface-go-ipfs-core"
|
||||
"github.com/ipfs/interface-go-ipfs-core/path"
|
||||
"github.com/ipfs/interface-go-ipfs-core/tests"
|
||||
local "github.com/ipfs/iptb-plugins/local"
|
||||
"github.com/ipfs/iptb/testbed"
|
||||
@ -171,11 +172,7 @@ func (NodeProvider) makeAPISwarm(ctx context.Context, fullIdentity bool, n int)
|
||||
}
|
||||
|
||||
// empty node is pinned even with --empty-repo, we don't want that
|
||||
emptyNode, err := iface.ParsePath("/ipfs/QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn")
|
||||
if err != nil {
|
||||
errs <- err
|
||||
return
|
||||
}
|
||||
emptyNode := path.New("/ipfs/QmUNLLsPACCz1vLxQVkXqqLX5R1X345qqfHbsf67hvA3Nn")
|
||||
if err := apis[i].Pin().Rm(ctx, emptyNode); err != nil {
|
||||
errs <- err
|
||||
return
|
||||
|
||||
@ -10,12 +10,12 @@ import (
|
||||
"github.com/ipfs/go-cid"
|
||||
files "github.com/ipfs/go-ipfs-files"
|
||||
unixfs "github.com/ipfs/go-unixfs"
|
||||
iface "github.com/ipfs/interface-go-ipfs-core"
|
||||
"github.com/ipfs/interface-go-ipfs-core/path"
|
||||
)
|
||||
|
||||
const forwardSeekLimit = 1 << 14 //16k
|
||||
|
||||
func (api *UnixfsAPI) Get(ctx context.Context, p iface.Path) (files.Node, error) {
|
||||
func (api *UnixfsAPI) Get(ctx context.Context, p path.Path) (files.Node, error) {
|
||||
if p.Mutable() { // use resolved path in case we are dealing with IPNS / MFS
|
||||
var err error
|
||||
p, err = api.core().ResolvePath(ctx, p)
|
||||
@ -48,7 +48,7 @@ type apiFile struct {
|
||||
ctx context.Context
|
||||
core *HttpApi
|
||||
size int64
|
||||
path iface.Path
|
||||
path path.Path
|
||||
|
||||
r *Response
|
||||
at int64
|
||||
@ -114,7 +114,7 @@ func (f *apiFile) Size() (int64, error) {
|
||||
return f.size, nil
|
||||
}
|
||||
|
||||
func (api *UnixfsAPI) getFile(ctx context.Context, p iface.Path, size int64) (files.Node, error) {
|
||||
func (api *UnixfsAPI) getFile(ctx context.Context, p path.Path, size int64) (files.Node, error) {
|
||||
f := &apiFile{
|
||||
ctx: ctx,
|
||||
core: api.core(),
|
||||
@ -177,13 +177,13 @@ func (it *apiIter) Next() bool {
|
||||
|
||||
switch it.cur.Type {
|
||||
case unixfs.THAMTShard, unixfs.TMetadata, unixfs.TDirectory:
|
||||
it.curFile, err = it.core.getDir(it.ctx, iface.IpfsPath(c), int64(it.cur.Size))
|
||||
it.curFile, err = it.core.getDir(it.ctx, path.IpfsPath(c), int64(it.cur.Size))
|
||||
if err != nil {
|
||||
it.err = err
|
||||
return false
|
||||
}
|
||||
case unixfs.TFile:
|
||||
it.curFile, err = it.core.getFile(it.ctx, iface.IpfsPath(c), int64(it.cur.Size))
|
||||
it.curFile, err = it.core.getFile(it.ctx, path.IpfsPath(c), int64(it.cur.Size))
|
||||
if err != nil {
|
||||
it.err = err
|
||||
return false
|
||||
@ -203,7 +203,7 @@ type apiDir struct {
|
||||
ctx context.Context
|
||||
core *UnixfsAPI
|
||||
size int64
|
||||
path iface.Path
|
||||
path path.Path
|
||||
|
||||
dec *json.Decoder
|
||||
}
|
||||
@ -224,7 +224,7 @@ func (d *apiDir) Entries() files.DirIterator {
|
||||
}
|
||||
}
|
||||
|
||||
func (api *UnixfsAPI) getDir(ctx context.Context, p iface.Path, size int64) (files.Node, error) {
|
||||
func (api *UnixfsAPI) getDir(ctx context.Context, p path.Path, size int64) (files.Node, error) {
|
||||
resp, err := api.core().Request("ls", p.String()).
|
||||
Option("resolve-size", true).
|
||||
Option("stream", true).Send(ctx)
|
||||
|
||||
@ -10,6 +10,7 @@ import (
|
||||
"github.com/ipfs/go-cid"
|
||||
"github.com/ipfs/interface-go-ipfs-core"
|
||||
caopts "github.com/ipfs/interface-go-ipfs-core/options"
|
||||
"github.com/ipfs/interface-go-ipfs-core/path"
|
||||
mh "github.com/multiformats/go-multihash"
|
||||
)
|
||||
|
||||
@ -26,8 +27,8 @@ func (s *blockStat) Size() int {
|
||||
return s.BSize
|
||||
}
|
||||
|
||||
func (s *blockStat) Path() iface.ResolvedPath {
|
||||
return iface.IpldPath(s.cid)
|
||||
func (s *blockStat) Path() path.Resolved {
|
||||
return path.IpldPath(s.cid)
|
||||
}
|
||||
|
||||
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
|
||||
return &out, nil
|
||||
}
|
||||
|
||||
func (api *BlockAPI) Get(ctx context.Context, p iface.Path) (io.Reader, error) {
|
||||
func (api *BlockAPI) Get(ctx context.Context, p path.Path) (io.Reader, error) {
|
||||
resp, err := api.core().Request("block/get", p.String()).Send(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -79,7 +80,7 @@ func (api *BlockAPI) Get(ctx context.Context, p iface.Path) (io.Reader, error) {
|
||||
return b, nil
|
||||
}
|
||||
|
||||
func (api *BlockAPI) Rm(ctx context.Context, p iface.Path, opts ...caopts.BlockRmOption) error {
|
||||
func (api *BlockAPI) Rm(ctx context.Context, p path.Path, opts ...caopts.BlockRmOption) error {
|
||||
options, err := caopts.BlockRmOptions(opts...)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -105,7 +106,7 @@ func (api *BlockAPI) Rm(ctx context.Context, p iface.Path, opts ...caopts.BlockR
|
||||
return nil
|
||||
}
|
||||
|
||||
func (api *BlockAPI) Stat(ctx context.Context, p iface.Path) (iface.BlockStat, error) {
|
||||
func (api *BlockAPI) Stat(ctx context.Context, p path.Path) (iface.BlockStat, error) {
|
||||
var out blockStat
|
||||
err := api.core().Request("block/stat", p.String()).Exec(ctx, &out)
|
||||
if err != nil {
|
||||
|
||||
@ -9,8 +9,8 @@ import (
|
||||
"github.com/ipfs/go-block-format"
|
||||
"github.com/ipfs/go-cid"
|
||||
"github.com/ipfs/go-ipld-format"
|
||||
"github.com/ipfs/interface-go-ipfs-core"
|
||||
"github.com/ipfs/interface-go-ipfs-core/options"
|
||||
"github.com/ipfs/interface-go-ipfs-core/path"
|
||||
)
|
||||
|
||||
type httpNodeAdder HttpApi
|
||||
@ -18,7 +18,7 @@ type HttpDagServ httpNodeAdder
|
||||
type pinningHttpNodeAdder httpNodeAdder
|
||||
|
||||
func (api *HttpDagServ) Get(ctx context.Context, c cid.Cid) (format.Node, error) {
|
||||
r, err := api.core().Block().Get(ctx, iface.IpldPath(c))
|
||||
r, err := api.core().Block().Get(ctx, path.IpldPath(c))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -105,7 +105,7 @@ func (api *HttpDagServ) Pinning() format.NodeAdder {
|
||||
}
|
||||
|
||||
func (api *HttpDagServ) Remove(ctx context.Context, c cid.Cid) error {
|
||||
return api.core().Block().Rm(ctx, iface.IpldPath(c)) //TODO: should we force rm?
|
||||
return api.core().Block().Rm(ctx, path.IpldPath(c)) //TODO: should we force rm?
|
||||
}
|
||||
|
||||
func (api *HttpDagServ) RemoveMany(ctx context.Context, cids []cid.Cid) error {
|
||||
|
||||
@ -4,8 +4,8 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/ipfs/interface-go-ipfs-core"
|
||||
caopts "github.com/ipfs/interface-go-ipfs-core/options"
|
||||
"github.com/ipfs/interface-go-ipfs-core/path"
|
||||
"github.com/libp2p/go-libp2p-peer"
|
||||
"github.com/libp2p/go-libp2p-peerstore"
|
||||
notif "github.com/libp2p/go-libp2p-routing/notifications"
|
||||
@ -37,7 +37,7 @@ func (api *DhtAPI) FindPeer(ctx context.Context, p peer.ID) (peerstore.PeerInfo,
|
||||
}
|
||||
}
|
||||
|
||||
func (api *DhtAPI) FindProviders(ctx context.Context, p iface.Path, opts ...caopts.DhtFindProvidersOption) (<-chan peerstore.PeerInfo, error) {
|
||||
func (api *DhtAPI) FindProviders(ctx context.Context, p path.Path, opts ...caopts.DhtFindProvidersOption) (<-chan peerstore.PeerInfo, error) {
|
||||
options, err := caopts.DhtFindProvidersOptions(opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -93,7 +93,7 @@ func (api *DhtAPI) FindProviders(ctx context.Context, p iface.Path, opts ...caop
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (api *DhtAPI) Provide(ctx context.Context, p iface.Path, opts ...caopts.DhtProvideOption) error {
|
||||
func (api *DhtAPI) Provide(ctx context.Context, p path.Path, opts ...caopts.DhtProvideOption) error {
|
||||
options, err := caopts.DhtProvideOptions(opts...)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/ipfs/interface-go-ipfs-core"
|
||||
caopts "github.com/ipfs/interface-go-ipfs-core/options"
|
||||
"github.com/ipfs/interface-go-ipfs-core/path"
|
||||
"github.com/libp2p/go-libp2p-peer"
|
||||
)
|
||||
|
||||
@ -22,9 +23,8 @@ func (k *keyOutput) Name() string {
|
||||
return k.JName
|
||||
}
|
||||
|
||||
func (k *keyOutput) Path() iface.Path {
|
||||
p, _ := iface.ParsePath("/ipns/" + k.Id)
|
||||
return p
|
||||
func (k *keyOutput) Path() path.Path {
|
||||
return path.New("/ipns/" + k.Id)
|
||||
}
|
||||
|
||||
func (k *keyOutput) ID() peer.ID {
|
||||
|
||||
@ -9,6 +9,7 @@ import (
|
||||
"github.com/ipfs/interface-go-ipfs-core"
|
||||
caopts "github.com/ipfs/interface-go-ipfs-core/options"
|
||||
"github.com/ipfs/interface-go-ipfs-core/options/namesys"
|
||||
"github.com/ipfs/interface-go-ipfs-core/path"
|
||||
)
|
||||
|
||||
type NameAPI HttpApi
|
||||
@ -17,18 +18,18 @@ type ipnsEntry struct {
|
||||
JName string `json:"Name"`
|
||||
JValue string `json:"Value"`
|
||||
|
||||
path iface.Path
|
||||
path path.Path
|
||||
}
|
||||
|
||||
func (e *ipnsEntry) Name() string {
|
||||
return e.JName
|
||||
}
|
||||
|
||||
func (e *ipnsEntry) Value() iface.Path {
|
||||
func (e *ipnsEntry) Value() path.Path {
|
||||
return e.path
|
||||
}
|
||||
|
||||
func (api *NameAPI) Publish(ctx context.Context, p iface.Path, opts ...caopts.NamePublishOption) (iface.IpnsEntry, error) {
|
||||
func (api *NameAPI) Publish(ctx context.Context, p path.Path, opts ...caopts.NamePublishOption) (iface.IpnsEntry, error) {
|
||||
options, err := caopts.NamePublishOptions(opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -48,8 +49,8 @@ func (api *NameAPI) Publish(ctx context.Context, p iface.Path, opts ...caopts.Na
|
||||
if err := req.Exec(ctx, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out.path, err = iface.ParsePath(out.JValue)
|
||||
return &out, err
|
||||
out.path = path.New(out.JValue)
|
||||
return &out, out.path.IsValid()
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
var ires iface.IpnsResult
|
||||
if err == nil {
|
||||
ires.Path, err = iface.ParsePath(out.Path)
|
||||
ires.Path = path.New(out.Path)
|
||||
}
|
||||
|
||||
select {
|
||||
@ -109,7 +110,7 @@ func (api *NameAPI) Search(ctx context.Context, name string, opts ...caopts.Name
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (api *NameAPI) Resolve(ctx context.Context, name string, opts ...caopts.NameResolveOption) (iface.Path, error) {
|
||||
func (api *NameAPI) Resolve(ctx context.Context, name string, opts ...caopts.NameResolveOption) (path.Path, error) {
|
||||
options, err := caopts.NameResolveOptions(opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -131,7 +132,7 @@ func (api *NameAPI) Resolve(ctx context.Context, name string, opts ...caopts.Nam
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return iface.ParsePath(out.Path)
|
||||
return path.New(out.Path), nil
|
||||
}
|
||||
|
||||
func (api *NameAPI) core() *HttpApi {
|
||||
|
||||
@ -14,6 +14,7 @@ import (
|
||||
ft "github.com/ipfs/go-unixfs"
|
||||
"github.com/ipfs/interface-go-ipfs-core"
|
||||
caopts "github.com/ipfs/interface-go-ipfs-core/options"
|
||||
"github.com/ipfs/interface-go-ipfs-core/path"
|
||||
)
|
||||
|
||||
type ObjectAPI HttpApi
|
||||
@ -41,7 +42,7 @@ func (api *ObjectAPI) New(ctx context.Context, opts ...caopts.ObjectNewOption) (
|
||||
return n, nil
|
||||
}
|
||||
|
||||
func (api *ObjectAPI) Put(ctx context.Context, r io.Reader, opts ...caopts.ObjectPutOption) (iface.ResolvedPath, error) {
|
||||
func (api *ObjectAPI) Put(ctx context.Context, r io.Reader, opts ...caopts.ObjectPutOption) (path.Resolved, error) {
|
||||
options, err := caopts.ObjectPutOptions(opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -63,10 +64,10 @@ func (api *ObjectAPI) Put(ctx context.Context, r io.Reader, opts ...caopts.Objec
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return iface.IpfsPath(c), nil
|
||||
return path.IpfsPath(c), nil
|
||||
}
|
||||
|
||||
func (api *ObjectAPI) Get(ctx context.Context, p iface.Path) (ipld.Node, error) {
|
||||
func (api *ObjectAPI) Get(ctx context.Context, p path.Path) (ipld.Node, error) {
|
||||
r, err := api.core().Block().Get(ctx, p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -79,7 +80,7 @@ func (api *ObjectAPI) Get(ctx context.Context, p iface.Path) (ipld.Node, error)
|
||||
return merkledag.DecodeProtobuf(b)
|
||||
}
|
||||
|
||||
func (api *ObjectAPI) Data(ctx context.Context, p iface.Path) (io.Reader, error) {
|
||||
func (api *ObjectAPI) Data(ctx context.Context, p path.Path) (io.Reader, error) {
|
||||
resp, err := api.core().Request("object/data", p.String()).Send(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -98,7 +99,7 @@ func (api *ObjectAPI) Data(ctx context.Context, p iface.Path) (io.Reader, error)
|
||||
return b, nil
|
||||
}
|
||||
|
||||
func (api *ObjectAPI) Links(ctx context.Context, p iface.Path) ([]*ipld.Link, error) {
|
||||
func (api *ObjectAPI) Links(ctx context.Context, p path.Path) ([]*ipld.Link, error) {
|
||||
var out struct {
|
||||
Links []struct {
|
||||
Name string
|
||||
@ -126,7 +127,7 @@ func (api *ObjectAPI) Links(ctx context.Context, p iface.Path) ([]*ipld.Link, er
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (api *ObjectAPI) Stat(ctx context.Context, p iface.Path) (*iface.ObjectStat, error) {
|
||||
func (api *ObjectAPI) Stat(ctx context.Context, p path.Path) (*iface.ObjectStat, error) {
|
||||
var out struct {
|
||||
Hash string
|
||||
NumLinks int
|
||||
@ -154,7 +155,7 @@ func (api *ObjectAPI) Stat(ctx context.Context, p iface.Path) (*iface.ObjectStat
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (api *ObjectAPI) AddLink(ctx context.Context, base iface.Path, name string, child iface.Path, opts ...caopts.ObjectAddLinkOption) (iface.ResolvedPath, error) {
|
||||
func (api *ObjectAPI) AddLink(ctx context.Context, base path.Path, name string, child path.Path, opts ...caopts.ObjectAddLinkOption) (path.Resolved, error) {
|
||||
options, err := caopts.ObjectAddLinkOptions(opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -173,10 +174,10 @@ func (api *ObjectAPI) AddLink(ctx context.Context, base iface.Path, name string,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return iface.IpfsPath(c), nil
|
||||
return path.IpfsPath(c), nil
|
||||
}
|
||||
|
||||
func (api *ObjectAPI) RmLink(ctx context.Context, base iface.Path, link string) (iface.ResolvedPath, error) {
|
||||
func (api *ObjectAPI) RmLink(ctx context.Context, base path.Path, link string) (path.Resolved, error) {
|
||||
var out objectOut
|
||||
err := api.core().Request("object/patch/rm-link", base.String(), link).
|
||||
Exec(ctx, &out)
|
||||
@ -189,10 +190,10 @@ func (api *ObjectAPI) RmLink(ctx context.Context, base iface.Path, link string)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return iface.IpfsPath(c), nil
|
||||
return path.IpfsPath(c), nil
|
||||
}
|
||||
|
||||
func (api *ObjectAPI) AppendData(ctx context.Context, p iface.Path, r io.Reader) (iface.ResolvedPath, error) {
|
||||
func (api *ObjectAPI) AppendData(ctx context.Context, p path.Path, r io.Reader) (path.Resolved, error) {
|
||||
var out objectOut
|
||||
err := api.core().Request("object/patch/append-data", p.String()).
|
||||
FileBody(r).
|
||||
@ -206,10 +207,10 @@ func (api *ObjectAPI) AppendData(ctx context.Context, p iface.Path, r io.Reader)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return iface.IpfsPath(c), nil
|
||||
return path.IpfsPath(c), nil
|
||||
}
|
||||
|
||||
func (api *ObjectAPI) SetData(ctx context.Context, p iface.Path, r io.Reader) (iface.ResolvedPath, error) {
|
||||
func (api *ObjectAPI) SetData(ctx context.Context, p path.Path, r io.Reader) (path.Resolved, error) {
|
||||
var out objectOut
|
||||
err := api.core().Request("object/patch/set-data", p.String()).
|
||||
FileBody(r).
|
||||
@ -223,7 +224,7 @@ func (api *ObjectAPI) SetData(ctx context.Context, p iface.Path, r io.Reader) (i
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return iface.IpfsPath(c), nil
|
||||
return path.IpfsPath(c), nil
|
||||
}
|
||||
|
||||
type change struct {
|
||||
@ -233,7 +234,7 @@ type change struct {
|
||||
After cid.Cid
|
||||
}
|
||||
|
||||
func (api *ObjectAPI) Diff(ctx context.Context, a iface.Path, b iface.Path) ([]iface.ObjectChange, error) {
|
||||
func (api *ObjectAPI) Diff(ctx context.Context, a path.Path, b path.Path) ([]iface.ObjectChange, error) {
|
||||
var out struct {
|
||||
Changes []change
|
||||
}
|
||||
@ -247,10 +248,10 @@ func (api *ObjectAPI) Diff(ctx context.Context, a iface.Path, b iface.Path) ([]i
|
||||
Path: ch.Path,
|
||||
}
|
||||
if ch.Before != cid.Undef {
|
||||
res[i].Before = iface.IpfsPath(ch.Before)
|
||||
res[i].Before = path.IpfsPath(ch.Before)
|
||||
}
|
||||
if ch.After != cid.Undef {
|
||||
res[i].After = iface.IpfsPath(ch.After)
|
||||
res[i].After = path.IpfsPath(ch.After)
|
||||
}
|
||||
}
|
||||
return res, nil
|
||||
|
||||
@ -6,10 +6,10 @@ import (
|
||||
cid "github.com/ipfs/go-cid"
|
||||
ipld "github.com/ipfs/go-ipld-format"
|
||||
ipfspath "github.com/ipfs/go-path"
|
||||
"github.com/ipfs/interface-go-ipfs-core"
|
||||
"github.com/ipfs/interface-go-ipfs-core/path"
|
||||
)
|
||||
|
||||
func (api *HttpApi) ResolvePath(ctx context.Context, path iface.Path) (iface.ResolvedPath, error) {
|
||||
func (api *HttpApi) ResolvePath(ctx context.Context, p path.Path) (path.Resolved, error) {
|
||||
var out struct {
|
||||
Cid cid.Cid
|
||||
RemPath string
|
||||
@ -18,31 +18,31 @@ func (api *HttpApi) ResolvePath(ctx context.Context, path iface.Path) (iface.Res
|
||||
//TODO: this is hacky, fixing https://github.com/ipfs/go-ipfs/issues/5703 would help
|
||||
|
||||
var err error
|
||||
if path.Namespace() == "ipns" {
|
||||
if path, err = api.Name().Resolve(ctx, path.String()); err != nil {
|
||||
if p.Namespace() == "ipns" {
|
||||
if p, err = api.Name().Resolve(ctx, p.String()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if err := api.Request("dag/resolve", path.String()).Exec(ctx, &out); err != nil {
|
||||
if err := api.Request("dag/resolve", p.String()).Exec(ctx, &out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// TODO:
|
||||
ipath, err := ipfspath.FromSegments("/"+path.Namespace()+"/", out.Cid.String(), out.RemPath)
|
||||
ipath, err := ipfspath.FromSegments("/"+p.Namespace()+"/", out.Cid.String(), out.RemPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
root, err := cid.Parse(ipfspath.Path(path.String()).Segments()[1])
|
||||
root, err := cid.Parse(ipfspath.Path(p.String()).Segments()[1])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return iface.NewResolvedPath(ipath, out.Cid, root, out.RemPath), nil
|
||||
return path.NewResolvedPath(ipath, out.Cid, root, out.RemPath), nil
|
||||
}
|
||||
|
||||
func (api *HttpApi) ResolveNode(ctx context.Context, p iface.Path) (ipld.Node, error) {
|
||||
func (api *HttpApi) ResolveNode(ctx context.Context, p path.Path) (ipld.Node, error) {
|
||||
rp, err := api.ResolvePath(ctx, p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@ -7,6 +7,7 @@ import (
|
||||
"github.com/ipfs/go-cid"
|
||||
"github.com/ipfs/interface-go-ipfs-core"
|
||||
caopts "github.com/ipfs/interface-go-ipfs-core/options"
|
||||
"github.com/ipfs/interface-go-ipfs-core/path"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
@ -21,11 +22,11 @@ type pinRefKeyList struct {
|
||||
}
|
||||
|
||||
type pin struct {
|
||||
path iface.ResolvedPath
|
||||
path path.Resolved
|
||||
typ string
|
||||
}
|
||||
|
||||
func (p *pin) Path() iface.ResolvedPath {
|
||||
func (p *pin) Path() path.Resolved {
|
||||
return p.path
|
||||
}
|
||||
|
||||
@ -33,7 +34,7 @@ func (p *pin) Type() string {
|
||||
return p.typ
|
||||
}
|
||||
|
||||
func (api *PinAPI) Add(ctx context.Context, p iface.Path, opts ...caopts.PinAddOption) error {
|
||||
func (api *PinAPI) Add(ctx context.Context, p path.Path, opts ...caopts.PinAddOption) error {
|
||||
options, err := caopts.PinAddOptions(opts...)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -62,13 +63,13 @@ func (api *PinAPI) Ls(ctx context.Context, opts ...caopts.PinLsOption) ([]iface.
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
pins = append(pins, &pin{typ: p.Type, path: iface.IpldPath(c)})
|
||||
pins = append(pins, &pin{typ: p.Type, path: path.IpldPath(c)})
|
||||
}
|
||||
|
||||
return pins, nil
|
||||
}
|
||||
|
||||
func (api *PinAPI) Rm(ctx context.Context, p iface.Path, opts ...caopts.PinRmOption) error {
|
||||
func (api *PinAPI) Rm(ctx context.Context, p path.Path, opts ...caopts.PinRmOption) error {
|
||||
options, err := caopts.PinRmOptions(opts...)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -79,7 +80,7 @@ func (api *PinAPI) Rm(ctx context.Context, p iface.Path, opts ...caopts.PinRmOpt
|
||||
Exec(ctx, nil)
|
||||
}
|
||||
|
||||
func (api *PinAPI) Update(ctx context.Context, from iface.Path, to iface.Path, opts ...caopts.PinUpdateOption) error {
|
||||
func (api *PinAPI) Update(ctx context.Context, from path.Path, to path.Path, opts ...caopts.PinUpdateOption) error {
|
||||
options, err := caopts.PinUpdateOptions(opts...)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -107,8 +108,8 @@ type badNode struct {
|
||||
cid cid.Cid
|
||||
}
|
||||
|
||||
func (n *badNode) Path() iface.ResolvedPath {
|
||||
return iface.IpldPath(n.cid)
|
||||
func (n *badNode) Path() path.Resolved {
|
||||
return path.IpldPath(n.cid)
|
||||
}
|
||||
|
||||
func (n *badNode) Err() error {
|
||||
|
||||
@ -13,6 +13,7 @@ import (
|
||||
unixfs_pb "github.com/ipfs/go-unixfs/pb"
|
||||
iface "github.com/ipfs/interface-go-ipfs-core"
|
||||
caopts "github.com/ipfs/interface-go-ipfs-core/options"
|
||||
"github.com/ipfs/interface-go-ipfs-core/path"
|
||||
mh "github.com/multiformats/go-multihash"
|
||||
)
|
||||
|
||||
@ -25,7 +26,7 @@ type addEvent struct {
|
||||
|
||||
type UnixfsAPI HttpApi
|
||||
|
||||
func (api *UnixfsAPI) Add(ctx context.Context, f files.Node, opts ...caopts.UnixfsAddOption) (iface.ResolvedPath, error) {
|
||||
func (api *UnixfsAPI) Add(ctx context.Context, f files.Node, opts ...caopts.UnixfsAddOption) (path.Resolved, error) {
|
||||
options, _, err := caopts.UnixfsAddOptions(opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -98,7 +99,7 @@ loop:
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ifevt.Path = iface.IpfsPath(c)
|
||||
ifevt.Path = path.IpfsPath(c)
|
||||
}
|
||||
|
||||
select {
|
||||
@ -114,7 +115,7 @@ loop:
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return iface.IpfsPath(c), nil
|
||||
return path.IpfsPath(c), nil
|
||||
}
|
||||
|
||||
type lsLink struct {
|
||||
@ -133,7 +134,7 @@ type lsOutput struct {
|
||||
Objects []lsObject
|
||||
}
|
||||
|
||||
func (api *UnixfsAPI) Ls(ctx context.Context, p iface.Path, opts ...caopts.UnixfsLsOption) (<-chan iface.DirEntry, error) {
|
||||
func (api *UnixfsAPI) Ls(ctx context.Context, p path.Path, opts ...caopts.UnixfsLsOption) (<-chan iface.DirEntry, error) {
|
||||
options, err := caopts.UnixfsLsOptions(opts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
Loading…
Reference in New Issue
Block a user