mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-02 23:08:07 +08:00
path: rename ParsePath and ResolvedPath
This commit was moved from ipfs/interface-go-ipfs-core@21a72398d9 This commit was moved from ipfs/boxo@fbc9ab8769
This commit is contained in:
parent
51a937fffd
commit
3669a774ff
@ -14,7 +14,7 @@ type BlockStat interface {
|
||||
Size() int
|
||||
|
||||
// Path returns path to the block
|
||||
Path() path.ResolvedPath
|
||||
Path() path.Resolved
|
||||
}
|
||||
|
||||
// BlockAPI specifies the interface to the block layer
|
||||
|
||||
@ -44,7 +44,7 @@ type CoreAPI interface {
|
||||
PubSub() PubSubAPI
|
||||
|
||||
// ResolvePath resolves the path using Unixfs resolver
|
||||
ResolvePath(context.Context, path.Path) (path.ResolvedPath, error)
|
||||
ResolvePath(context.Context, path.Path) (path.Resolved, error)
|
||||
|
||||
// ResolveNode resolves the path (if not resolved already) using Unixfs
|
||||
// resolver, gets and returns the resolved Node
|
||||
|
||||
@ -59,11 +59,11 @@ type ObjectChange struct {
|
||||
|
||||
// Before holds the link path before the change. Note that when a link is
|
||||
// added, this will be nil.
|
||||
Before path.ResolvedPath
|
||||
Before path.Resolved
|
||||
|
||||
// After holds the link path after the change. Note that when a link is
|
||||
// removed, this will be nil.
|
||||
After path.ResolvedPath
|
||||
After path.Resolved
|
||||
}
|
||||
|
||||
// ObjectAPI specifies the interface to MerkleDAG and contains useful utilities
|
||||
@ -73,7 +73,7 @@ type ObjectAPI interface {
|
||||
New(context.Context, ...options.ObjectNewOption) (ipld.Node, error)
|
||||
|
||||
// Put imports the data into merkledag
|
||||
Put(context.Context, io.Reader, ...options.ObjectPutOption) (path.ResolvedPath, error)
|
||||
Put(context.Context, io.Reader, ...options.ObjectPutOption) (path.Resolved, error)
|
||||
|
||||
// Get returns the node for the path
|
||||
Get(context.Context, path.Path) (ipld.Node, error)
|
||||
@ -90,16 +90,16 @@ type ObjectAPI interface {
|
||||
// AddLink adds a link under the specified path. child path can point to a
|
||||
// subdirectory within the patent which must be present (can be overridden
|
||||
// with WithCreate option).
|
||||
AddLink(ctx context.Context, base path.Path, name string, child path.Path, opts ...options.ObjectAddLinkOption) (path.ResolvedPath, error)
|
||||
AddLink(ctx context.Context, base path.Path, name string, child path.Path, opts ...options.ObjectAddLinkOption) (path.Resolved, error)
|
||||
|
||||
// RmLink removes a link from the node
|
||||
RmLink(ctx context.Context, base path.Path, link string) (path.ResolvedPath, error)
|
||||
RmLink(ctx context.Context, base path.Path, link string) (path.Resolved, error)
|
||||
|
||||
// AppendData appends data to the node
|
||||
AppendData(context.Context, path.Path, io.Reader) (path.ResolvedPath, error)
|
||||
AppendData(context.Context, path.Path, io.Reader) (path.Resolved, error)
|
||||
|
||||
// SetData sets the data contained in the node
|
||||
SetData(context.Context, path.Path, io.Reader) (path.ResolvedPath, error)
|
||||
SetData(context.Context, path.Path, io.Reader) (path.Resolved, error)
|
||||
|
||||
// Diff returns a set of changes needed to transform the first object into the
|
||||
// second.
|
||||
|
||||
@ -1,4 +0,0 @@
|
||||
package iface
|
||||
|
||||
//TODO: merge with ipfspath so we don't depend on it
|
||||
|
||||
@ -39,9 +39,9 @@ type Path interface {
|
||||
IsValid() error
|
||||
}
|
||||
|
||||
// ResolvedPath is a path which was resolved to the last resolvable node.
|
||||
// Resolved is a path which was resolved to the last resolvable node.
|
||||
// ResolvedPaths are guaranteed to return nil from `IsValid`
|
||||
type ResolvedPath interface {
|
||||
type Resolved interface {
|
||||
// Cid returns the CID of the node referenced by the path. Remainder of the
|
||||
// path is guaranteed to be within the node.
|
||||
//
|
||||
@ -120,7 +120,7 @@ func Join(base Path, a ...string) Path {
|
||||
}
|
||||
|
||||
// IpfsPath creates new /ipfs path from the provided CID
|
||||
func IpfsPath(c cid.Cid) ResolvedPath {
|
||||
func IpfsPath(c cid.Cid) Resolved {
|
||||
return &resolvedPath{
|
||||
path: path{"/ipfs/" + c.String()},
|
||||
cid: c,
|
||||
@ -130,7 +130,7 @@ func IpfsPath(c cid.Cid) ResolvedPath {
|
||||
}
|
||||
|
||||
// IpldPath creates new /ipld path from the provided CID
|
||||
func IpldPath(c cid.Cid) ResolvedPath {
|
||||
func IpldPath(c cid.Cid) Resolved {
|
||||
return &resolvedPath{
|
||||
path: path{"/ipld/" + c.String()},
|
||||
cid: c,
|
||||
@ -139,8 +139,8 @@ func IpldPath(c cid.Cid) ResolvedPath {
|
||||
}
|
||||
}
|
||||
|
||||
// ParsePath parses string path to a Path
|
||||
func ParsePath(p string) Path {
|
||||
// New parses string path to a Path
|
||||
func New(p string) Path {
|
||||
if pp, err := ipfspath.ParsePath(p); err == nil {
|
||||
p = pp.String()
|
||||
}
|
||||
@ -148,10 +148,10 @@ func ParsePath(p string) Path {
|
||||
return &path{path: p}
|
||||
}
|
||||
|
||||
// NewResolvedPath creates new ResolvedPath. This function performs no checks
|
||||
// NewResolvedPath creates new Resolved path. This function performs no checks
|
||||
// and is intended to be used by resolver implementations. Incorrect inputs may
|
||||
// cause panics. Handle with care.
|
||||
func NewResolvedPath(ipath ipfspath.Path, c cid.Cid, root cid.Cid, remainder string) ResolvedPath {
|
||||
func NewResolvedPath(ipath ipfspath.Path, c cid.Cid, root cid.Cid, remainder string) Resolved {
|
||||
return &resolvedPath{
|
||||
path: path{ipath.String()},
|
||||
cid: c,
|
||||
|
||||
@ -10,7 +10,7 @@ import (
|
||||
// Pin holds information about pinned resource
|
||||
type Pin interface {
|
||||
// Path to the pinned object
|
||||
Path() path.ResolvedPath
|
||||
Path() path.Resolved
|
||||
|
||||
// Type of the pin
|
||||
Type() string
|
||||
@ -28,7 +28,7 @@ type PinStatus interface {
|
||||
// BadPinNode is a node that has been marked as bad by Pin.Verify
|
||||
type BadPinNode interface {
|
||||
// Path is the path of the node
|
||||
Path() path.ResolvedPath
|
||||
Path() path.Resolved
|
||||
|
||||
// Err is the reason why the node has been marked as bad
|
||||
Err() error
|
||||
|
||||
@ -111,7 +111,7 @@ func (tp *provider) TestBlockGet(t *testing.T) {
|
||||
t.Error("didn't get correct data back")
|
||||
}
|
||||
|
||||
p := path.ParsePath("/ipfs/" + res.Path().Cid().String())
|
||||
p := path.New("/ipfs/" + res.Path().Cid().String())
|
||||
|
||||
rp, err := api.ResolvePath(ctx, p)
|
||||
if err != nil {
|
||||
|
||||
@ -114,7 +114,7 @@ func (tp *provider) TestDagPath(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
p := path.ParsePath(gopath.Join(nd.Cid().String(), "lnk"))
|
||||
p := path.New(gopath.Join(nd.Cid().String(), "lnk"))
|
||||
|
||||
rp, err := api.ResolvePath(ctx, p)
|
||||
if err != nil {
|
||||
|
||||
@ -36,7 +36,7 @@ func addTestObject(ctx context.Context, api coreiface.CoreAPI) (path.Path, error
|
||||
}
|
||||
|
||||
func appendPath(p path.Path, sub string) path.Path {
|
||||
return path.ParsePath(gopath.Join(p.String(), sub))
|
||||
return path.New(gopath.Join(p.String(), sub))
|
||||
}
|
||||
|
||||
func (tp *provider) TestPublishResolve(t *testing.T) {
|
||||
|
||||
@ -75,7 +75,7 @@ func (tp *provider) TestPathRemainder(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
rp1, err := api.ResolvePath(ctx, path.ParsePath(nd.String()+"/foo/bar"))
|
||||
rp1, err := api.ResolvePath(ctx, path.New(nd.String()+"/foo/bar"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -106,7 +106,7 @@ func (tp *provider) TestEmptyPathRemainder(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
rp1, err := api.ResolvePath(ctx, path.ParsePath(nd.Cid().String()))
|
||||
rp1, err := api.ResolvePath(ctx, path.New(nd.Cid().String()))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -137,7 +137,7 @@ func (tp *provider) TestInvalidPathRemainder(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = api.ResolvePath(ctx, path.ParsePath("/ipld/"+nd.Cid().String()+"/bar/baz"))
|
||||
_, err = api.ResolvePath(ctx, path.New("/ipld/"+nd.Cid().String()+"/bar/baz"))
|
||||
if err == nil || !strings.Contains(err.Error(), "no such link found") {
|
||||
t.Fatalf("unexpected error: %s", err)
|
||||
}
|
||||
@ -173,7 +173,7 @@ func (tp *provider) TestPathRoot(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
rp, err := api.ResolvePath(ctx, path.ParsePath("/ipld/"+nd.Cid().String()+"/foo"))
|
||||
rp, err := api.ResolvePath(ctx, path.New("/ipld/"+nd.Cid().String()+"/foo"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -188,7 +188,7 @@ func (tp *provider) TestPathRoot(t *testing.T) {
|
||||
}
|
||||
|
||||
func (tp *provider) TestPathJoin(t *testing.T) {
|
||||
p1 := path.ParsePath("/ipfs/QmYNmQKp6SuaVrpgWRsPTgCQCnpxUYGq76YEKBXuj2N4H6/bar/baz")
|
||||
p1 := path.New("/ipfs/QmYNmQKp6SuaVrpgWRsPTgCQCnpxUYGq76YEKBXuj2N4H6/bar/baz")
|
||||
|
||||
if path.Join(p1, "foo").String() != "/ipfs/QmYNmQKp6SuaVrpgWRsPTgCQCnpxUYGq76YEKBXuj2N4H6/bar/baz/foo" {
|
||||
t.Error("unexpected path")
|
||||
|
||||
@ -102,7 +102,7 @@ func (tp *provider) TestAdd(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
p := func(h string) path.ResolvedPath {
|
||||
p := func(h string) path.Resolved {
|
||||
c, err := cid.Parse(h)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -593,7 +593,7 @@ func (tp *provider) TestGetEmptyFile(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
emptyFilePath := path.ParsePath(emptyFile)
|
||||
emptyFilePath := path.New(emptyFile)
|
||||
|
||||
r, err := api.Unixfs().Get(ctx, emptyFilePath)
|
||||
if err != nil {
|
||||
|
||||
@ -11,9 +11,9 @@ import (
|
||||
|
||||
type AddEvent struct {
|
||||
Name string
|
||||
Path path.ResolvedPath `json:",omitempty"`
|
||||
Bytes int64 `json:",omitempty"`
|
||||
Size string `json:",omitempty"`
|
||||
Path path.Resolved `json:",omitempty"`
|
||||
Bytes int64 `json:",omitempty"`
|
||||
Size string `json:",omitempty"`
|
||||
}
|
||||
|
||||
// FileType is an enum of possible UnixFS file types.
|
||||
@ -65,7 +65,7 @@ type UnixfsAPI interface {
|
||||
// Add imports the data from the reader into merkledag file
|
||||
//
|
||||
// TODO: a long useful comment on how to use this for many different scenarios
|
||||
Add(context.Context, files.Node, ...options.UnixfsAddOption) (path.ResolvedPath, error)
|
||||
Add(context.Context, files.Node, ...options.UnixfsAddOption) (path.Resolved, error)
|
||||
|
||||
// Get returns a read-only handle to a file tree referenced by a path
|
||||
//
|
||||
|
||||
Loading…
Reference in New Issue
Block a user