Skip to content

Commit

Permalink
refactor!: consolidate path libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias committed Aug 10, 2023
1 parent d4e6cd9 commit f5fe4d8
Show file tree
Hide file tree
Showing 53 changed files with 730 additions and 843 deletions.
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.ResolvedPath
}

// BlockAPI specifies the interface to the block layer
Expand Down
5 changes: 2 additions & 3 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 @@ -48,7 +47,7 @@ type CoreAPI interface {
Routing() RoutingAPI

// ResolvePath resolves the path using Unixfs resolver
ResolvePath(context.Context, path.Path) (path.Resolved, error)
ResolvePath(context.Context, path.Path) (path.ResolvedPath, 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.ResolvedPath

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

// 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.ResolvedPath, 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.ResolvedPath, 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.ResolvedPath, 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.ResolvedPath, 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.ResolvedPath, 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.ResolvedPath

// 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.ResolvedPath

// Err is the reason why the node has been marked as bad
Err() error
Expand Down
5 changes: 2 additions & 3 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,7 +218,7 @@ 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)
if err != nil {
Expand Down
9 changes: 5 additions & 4 deletions coreiface/tests/dag.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@ package tests
import (
"context"
"math"
gopath "path"
"strings"
"testing"

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

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

ipldcbor "github.com/ipfs/go-ipld-cbor"
ipld "github.com/ipfs/go-ipld-format"
Expand Down Expand Up @@ -115,7 +113,10 @@ func (tp *TestSuite) TestDagPath(t *testing.T) {
t.Fatal(err)
}

p := path.New(gopath.Join(nd.Cid().String(), "lnk"))
p, err := path.Join(path.NewIPFSPath(nd.Cid()), "lnk")
if err != nil {
t.Fatal(err)
}

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

0 comments on commit f5fe4d8

Please sign in to comment.