Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(path)!: consolidated path libraries #334

Merged
merged 14 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ The following emojis are used to highlight certain changes:
`files.Node`.
* `boxo/routing/http/client.Client` is now exported. This means you can now pass
it around functions, or add it to a struct if you want.
* 🛠 The `path` package has been massively refactored. With this refactor, we have
condensed the different path-related packages under a single one. Therefore, there
hacdias marked this conversation as resolved.
Show resolved Hide resolved
are many breaking changes. Please consult the [documentation](https://pkg.go.dev/github.com/ipfs/boxo/path)
for more details on how to use the new package.
hacdias marked this conversation as resolved.
Show resolved Hide resolved
* 🛠 The signature of `CoreAPI.ResolvePath` in `coreiface` has changed to now return
the remainder segments as a second return value, matching the signature of `resolver.ResolveToLastNode`.

### Removed

Expand Down
5 changes: 2 additions & 3 deletions coreiface/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import (
"context"
"io"

path "github.com/ipfs/boxo/coreiface/path"

"github.com/ipfs/boxo/coreiface/options"
"github.com/ipfs/boxo/path"
)

// BlockStat contains information about a block
Expand All @@ -15,7 +14,7 @@ type BlockStat interface {
Size() int

// Path returns path to the block
Path() path.Resolved
Path() path.ImmutablePath
}

// BlockAPI specifies the interface to the block layer
Expand Down
9 changes: 5 additions & 4 deletions coreiface/coreapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ package iface
import (
"context"

path "github.com/ipfs/boxo/coreiface/path"

"github.com/ipfs/boxo/coreiface/options"
"github.com/ipfs/boxo/path"

ipld "github.com/ipfs/go-ipld-format"
)
Expand Down Expand Up @@ -47,8 +46,10 @@ type CoreAPI interface {
// Routing returns an implementation of Routing API
Routing() RoutingAPI

// ResolvePath resolves the path using Unixfs resolver
ResolvePath(context.Context, path.Path) (path.Resolved, error)
// ResolvePath resolves the path using UnixFS resolver, and returns the resolved
// immutable path, and the remainder of the path segments that cannot be resolved
// within UnixFS.
ResolvePath(context.Context, path.Path) (path.ImmutablePath, []string, error)

// ResolveNode resolves the path (if not resolved already) using Unixfs
// resolver, gets and returns the resolved Node
Expand Down
2 changes: 1 addition & 1 deletion coreiface/dht.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package iface
import (
"context"

"github.com/ipfs/boxo/coreiface/path"
"github.com/ipfs/boxo/path"

"github.com/ipfs/boxo/coreiface/options"

Expand Down
2 changes: 1 addition & 1 deletion coreiface/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package iface
import (
"context"

"github.com/ipfs/boxo/coreiface/path"
"github.com/ipfs/boxo/path"

"github.com/ipfs/boxo/coreiface/options"

Expand Down
5 changes: 2 additions & 3 deletions coreiface/name.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import (
"context"
"errors"

path "github.com/ipfs/boxo/coreiface/path"
"github.com/ipfs/boxo/ipns"

"github.com/ipfs/boxo/coreiface/options"
"github.com/ipfs/boxo/ipns"
"github.com/ipfs/boxo/path"
)

var ErrResolveFailed = errors.New("could not resolve name")
Expand Down
17 changes: 8 additions & 9 deletions coreiface/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import (
"context"
"io"

path "github.com/ipfs/boxo/coreiface/path"

"github.com/ipfs/boxo/coreiface/options"
"github.com/ipfs/boxo/path"

"github.com/ipfs/go-cid"
ipld "github.com/ipfs/go-ipld-format"
Expand Down Expand Up @@ -60,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.Resolved
Before path.ImmutablePath

// After holds the link path after the change. Note that when a link is
// removed, this will be nil.
After path.Resolved
After path.ImmutablePath
}

// ObjectAPI specifies the interface to MerkleDAG and contains useful utilities
Expand All @@ -74,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.Resolved, error)
Put(context.Context, io.Reader, ...options.ObjectPutOption) (path.ImmutablePath, error)

// Get returns the node for the path
Get(context.Context, path.Path) (ipld.Node, error)
Expand All @@ -91,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.Resolved, error)
AddLink(ctx context.Context, base path.Path, name string, child path.Path, opts ...options.ObjectAddLinkOption) (path.ImmutablePath, error)

// RmLink removes a link from the node
RmLink(ctx context.Context, base path.Path, link string) (path.Resolved, error)
RmLink(ctx context.Context, base path.Path, link string) (path.ImmutablePath, error)

// AppendData appends data to the node
AppendData(context.Context, path.Path, io.Reader) (path.Resolved, error)
AppendData(context.Context, path.Path, io.Reader) (path.ImmutablePath, error)

// SetData sets the data contained in the node
SetData(context.Context, path.Path, io.Reader) (path.Resolved, error)
SetData(context.Context, path.Path, io.Reader) (path.ImmutablePath, error)

// Diff returns a set of changes needed to transform the first object into the
// second.
Expand Down
199 changes: 0 additions & 199 deletions coreiface/path/path.go

This file was deleted.

6 changes: 3 additions & 3 deletions coreiface/pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package iface
import (
"context"

path "github.com/ipfs/boxo/coreiface/path"
"github.com/ipfs/boxo/path"

"github.com/ipfs/boxo/coreiface/options"
)

// Pin holds information about pinned resource
type Pin interface {
// Path to the pinned object
Path() path.Resolved
Path() path.ImmutablePath

// Type of the pin
Type() string
Expand All @@ -35,7 +35,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.Resolved
Path() path.ImmutablePath

// Err is the reason why the node has been marked as bad
Err() error
Expand Down
7 changes: 3 additions & 4 deletions coreiface/tests/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import (

coreiface "github.com/ipfs/boxo/coreiface"
opt "github.com/ipfs/boxo/coreiface/options"
"github.com/ipfs/boxo/coreiface/path"
"github.com/ipfs/boxo/path"
ipld "github.com/ipfs/go-ipld-format"

mh "github.com/multiformats/go-multihash"
)

Expand Down Expand Up @@ -219,9 +218,9 @@ func (tp *TestSuite) TestBlockGet(t *testing.T) {
t.Error("didn't get correct data back")
}

p := path.New("/ipfs/" + res.Path().Cid().String())
p := path.NewIPFSPath(res.Path().Cid())

rp, err := api.ResolvePath(ctx, p)
rp, _, err := api.ResolvePath(ctx, p)
if err != nil {
t.Fatal(err)
}
Expand Down
Loading