Skip to content

Commit

Permalink
feat(path)!: consolidated path libraries (#334)
Browse files Browse the repository at this point in the history
  • Loading branch information
hacdias authored Oct 6, 2023
1 parent b388690 commit 85c180e
Show file tree
Hide file tree
Showing 70 changed files with 1,298 additions and 1,341 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ 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 and/or Kubo-specific packages under a single generic one. Therefore, there
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.
* Note: content paths created with `boxo/path` are automatically normalized:
- Replace multiple slashes with a single slash.
- Eliminate each `.` path name element (the current directory).
- Eliminate each inner `..` path name element (the parent directory) along with the non-`..` element that precedes it.
- Eliminate `..` elements that begin a rooted path: that is, replace "`/..`" by "`/`" at the beginning of a path.
* 🛠 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
Loading

0 comments on commit 85c180e

Please sign in to comment.