mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-30 18:13:54 +08:00
Merge pull request #702 from jbenet/fix/coreUI
address concerns about user interface with new Path type
This commit is contained in:
@ -4,7 +4,7 @@ import (
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
"path"
|
||||
gopath "path"
|
||||
|
||||
"github.com/jbenet/go-ipfs/commands/files"
|
||||
core "github.com/jbenet/go-ipfs/core"
|
||||
@ -14,14 +14,13 @@ import (
|
||||
"github.com/jbenet/go-ipfs/pin"
|
||||
"github.com/jbenet/go-ipfs/thirdparty/eventlog"
|
||||
unixfs "github.com/jbenet/go-ipfs/unixfs"
|
||||
u "github.com/jbenet/go-ipfs/util"
|
||||
)
|
||||
|
||||
var log = eventlog.Logger("coreunix")
|
||||
|
||||
// Add builds a merkledag from the a reader, pinning all objects to the local
|
||||
// datastore. Returns a key representing the root node.
|
||||
func Add(n *core.IpfsNode, r io.Reader) (u.Key, error) {
|
||||
func Add(n *core.IpfsNode, r io.Reader) (string, error) {
|
||||
// TODO more attractive function signature importer.BuildDagFromReader
|
||||
dagNode, err := importer.BuildDagFromReader(
|
||||
r,
|
||||
@ -35,7 +34,12 @@ func Add(n *core.IpfsNode, r io.Reader) (u.Key, error) {
|
||||
if err := n.Pinning.Flush(); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return dagNode.Key()
|
||||
k, err := dagNode.Key()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return k.String(), nil
|
||||
}
|
||||
|
||||
// AddR recursively adds files in |path|.
|
||||
@ -124,7 +128,7 @@ Loop:
|
||||
return nil, err
|
||||
}
|
||||
|
||||
_, name := path.Split(file.FileName())
|
||||
_, name := gopath.Split(file.FileName())
|
||||
|
||||
err = tree.AddNodeLink(name, node)
|
||||
if err != nil {
|
||||
|
@ -8,7 +8,8 @@ import (
|
||||
uio "github.com/jbenet/go-ipfs/unixfs/io"
|
||||
)
|
||||
|
||||
func Cat(n *core.IpfsNode, p path.Path) (io.Reader, error) {
|
||||
func Cat(n *core.IpfsNode, pstr string) (io.Reader, error) {
|
||||
p := path.FromString(pstr)
|
||||
dagNode, err := n.Resolver.ResolvePath(p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
12
path/path.go
12
path/path.go
@ -3,12 +3,24 @@ package path
|
||||
import (
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
u "github.com/jbenet/go-ipfs/util"
|
||||
)
|
||||
|
||||
// TODO: debate making this a private struct wrapped in a public interface
|
||||
// would allow us to control creation, and cache segments.
|
||||
type Path string
|
||||
|
||||
// FromString safely converts a string type to a Path type
|
||||
func FromString(s string) Path {
|
||||
return Path(s)
|
||||
}
|
||||
|
||||
// FromKey safely converts a Key type to a Path type
|
||||
func FromKey(k u.Key) Path {
|
||||
return Path(k.String())
|
||||
}
|
||||
|
||||
func (p Path) Segments() []string {
|
||||
cleaned := path.Clean(string(p))
|
||||
segments := strings.Split(cleaned, "/")
|
||||
|
@ -15,7 +15,6 @@ import (
|
||||
coreunix "github.com/jbenet/go-ipfs/core/coreunix"
|
||||
mocknet "github.com/jbenet/go-ipfs/p2p/net/mock"
|
||||
"github.com/jbenet/go-ipfs/p2p/peer"
|
||||
path "github.com/jbenet/go-ipfs/path"
|
||||
"github.com/jbenet/go-ipfs/thirdparty/unit"
|
||||
errors "github.com/jbenet/go-ipfs/util/debugerror"
|
||||
testutil "github.com/jbenet/go-ipfs/util/testutil"
|
||||
@ -126,12 +125,12 @@ func DirectAddCat(data []byte, conf testutil.LatencyConfig) error {
|
||||
return err
|
||||
}
|
||||
|
||||
keyAdded, err := coreunix.Add(adder, bytes.NewReader(data))
|
||||
added, err := coreunix.Add(adder, bytes.NewReader(data))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
readerCatted, err := coreunix.Cat(catter, path.Path(keyAdded.String()))
|
||||
readerCatted, err := coreunix.Cat(catter, added)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ import (
|
||||
coreunix "github.com/jbenet/go-ipfs/core/coreunix"
|
||||
mocknet "github.com/jbenet/go-ipfs/p2p/net/mock"
|
||||
"github.com/jbenet/go-ipfs/p2p/peer"
|
||||
path "github.com/jbenet/go-ipfs/path"
|
||||
"github.com/jbenet/go-ipfs/thirdparty/unit"
|
||||
errors "github.com/jbenet/go-ipfs/util/debugerror"
|
||||
testutil "github.com/jbenet/go-ipfs/util/testutil"
|
||||
@ -106,12 +105,12 @@ func RunThreeLeggedCat(data []byte, conf testutil.LatencyConfig) error {
|
||||
return err
|
||||
}
|
||||
|
||||
keyAdded, err := coreunix.Add(adder, bytes.NewReader(data))
|
||||
added, err := coreunix.Add(adder, bytes.NewReader(data))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
readerCatted, err := coreunix.Cat(catter, path.Path(keyAdded.String()))
|
||||
readerCatted, err := coreunix.Cat(catter, added)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Reference in New Issue
Block a user