mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-20 02:21:48 +08:00
Cleanup instances of manual resolver construction
License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
This commit is contained in:
@ -6,9 +6,8 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
core "github.com/ipfs/go-ipfs/core"
|
|
||||||
cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
|
cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
|
||||||
coreunix "github.com/ipfs/go-ipfs/core/coreunix"
|
"github.com/ipfs/go-ipfs/core/coreapi/interface"
|
||||||
|
|
||||||
"gx/ipfs/QmSP88ryZkHSRn1fnngAaV2Vcn63WUJzAavnRM9CVdU1Ky/go-ipfs-cmdkit"
|
"gx/ipfs/QmSP88ryZkHSRn1fnngAaV2Vcn63WUJzAavnRM9CVdU1Ky/go-ipfs-cmdkit"
|
||||||
cmds "gx/ipfs/QmXTmUCBtDUrzDYVzASogLiNph7EBuYqEgPL7QoHNMzUnz/go-ipfs-cmds"
|
cmds "gx/ipfs/QmXTmUCBtDUrzDYVzASogLiNph7EBuYqEgPL7QoHNMzUnz/go-ipfs-cmds"
|
||||||
@ -35,6 +34,11 @@ var CatCmd = &cmds.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
api, err := cmdenv.GetApi(env)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if !node.OnlineMode() {
|
if !node.OnlineMode() {
|
||||||
if err := node.SetupOfflineRouting(); err != nil {
|
if err := node.SetupOfflineRouting(); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -62,7 +66,7 @@ var CatCmd = &cmds.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
readers, length, err := cat(req.Context, node, req.Arguments, int64(offset), int64(max))
|
readers, length, err := cat(req.Context, api, req.Arguments, int64(offset), int64(max))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -115,14 +119,19 @@ var CatCmd = &cmds.Command{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func cat(ctx context.Context, node *core.IpfsNode, paths []string, offset int64, max int64) ([]io.Reader, uint64, error) {
|
func cat(ctx context.Context, api iface.CoreAPI, paths []string, offset int64, max int64) ([]io.Reader, uint64, error) {
|
||||||
readers := make([]io.Reader, 0, len(paths))
|
readers := make([]io.Reader, 0, len(paths))
|
||||||
length := uint64(0)
|
length := uint64(0)
|
||||||
if max == 0 {
|
if max == 0 {
|
||||||
return nil, 0, nil
|
return nil, 0, nil
|
||||||
}
|
}
|
||||||
for _, fpath := range paths {
|
for _, p := range paths {
|
||||||
read, err := coreunix.Cat(ctx, node, fpath)
|
fpath, err := iface.ParsePath(p)
|
||||||
|
if err != nil {
|
||||||
|
return nil, 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
read, err := api.Unixfs().Cat(ctx, fpath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, err
|
return nil, 0, err
|
||||||
}
|
}
|
||||||
|
@ -16,21 +16,19 @@ import (
|
|||||||
core "github.com/ipfs/go-ipfs/core"
|
core "github.com/ipfs/go-ipfs/core"
|
||||||
cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
|
cmdenv "github.com/ipfs/go-ipfs/core/commands/cmdenv"
|
||||||
e "github.com/ipfs/go-ipfs/core/commands/e"
|
e "github.com/ipfs/go-ipfs/core/commands/e"
|
||||||
ft "gx/ipfs/QmU4x3742bvgfxJsByEDpBnifJqjJdV6x528co4hwKCn46/go-unixfs"
|
"github.com/ipfs/go-ipfs/core/coreapi/interface"
|
||||||
uio "gx/ipfs/QmU4x3742bvgfxJsByEDpBnifJqjJdV6x528co4hwKCn46/go-unixfs/io"
|
|
||||||
dag "gx/ipfs/QmcBoNcAP6qDjgRBew7yjvCqHq7p5jMstE44jPUBWBxzsV/go-merkledag"
|
|
||||||
bservice "gx/ipfs/QmcRecCZWM2NZfCQrCe97Ch3Givv8KKEP82tGUDntzdLFe/go-blockservice"
|
|
||||||
path "gx/ipfs/QmcjwUb36Z16NJkvDX6ccXPqsFswo6AsRXynyXcLLCphV2/go-path"
|
|
||||||
resolver "gx/ipfs/QmcjwUb36Z16NJkvDX6ccXPqsFswo6AsRXynyXcLLCphV2/go-path/resolver"
|
|
||||||
|
|
||||||
humanize "gx/ipfs/QmPSBJL4momYnE7DcUyk2DVhD6rH488ZmHBGLbxNdhU44K/go-humanize"
|
humanize "gx/ipfs/QmPSBJL4momYnE7DcUyk2DVhD6rH488ZmHBGLbxNdhU44K/go-humanize"
|
||||||
cid "gx/ipfs/QmPSQnBKM9g7BaUcZCvswUJVscQ1ipjmwxN5PXCjkp9EQ7/go-cid"
|
cid "gx/ipfs/QmPSQnBKM9g7BaUcZCvswUJVscQ1ipjmwxN5PXCjkp9EQ7/go-cid"
|
||||||
mh "gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
|
mh "gx/ipfs/QmPnFwZ2JXKnXgMw8CdBPxn7FWh6LLdjUjxV1fKHuJnkr8/go-multihash"
|
||||||
offline "gx/ipfs/QmR5miWuikPxWyUrzMYJVmFUcD44pGdtc98h9Qsbp4YcJw/go-ipfs-exchange-offline"
|
offline "gx/ipfs/QmR5miWuikPxWyUrzMYJVmFUcD44pGdtc98h9Qsbp4YcJw/go-ipfs-exchange-offline"
|
||||||
cmdkit "gx/ipfs/QmSP88ryZkHSRn1fnngAaV2Vcn63WUJzAavnRM9CVdU1Ky/go-ipfs-cmdkit"
|
cmdkit "gx/ipfs/QmSP88ryZkHSRn1fnngAaV2Vcn63WUJzAavnRM9CVdU1Ky/go-ipfs-cmdkit"
|
||||||
|
ft "gx/ipfs/QmU4x3742bvgfxJsByEDpBnifJqjJdV6x528co4hwKCn46/go-unixfs"
|
||||||
cmds "gx/ipfs/QmXTmUCBtDUrzDYVzASogLiNph7EBuYqEgPL7QoHNMzUnz/go-ipfs-cmds"
|
cmds "gx/ipfs/QmXTmUCBtDUrzDYVzASogLiNph7EBuYqEgPL7QoHNMzUnz/go-ipfs-cmds"
|
||||||
logging "gx/ipfs/QmZChCsSt8DctjceaL56Eibc29CVQq4dGKRXC5JRZ6Ppae/go-log"
|
logging "gx/ipfs/QmZChCsSt8DctjceaL56Eibc29CVQq4dGKRXC5JRZ6Ppae/go-log"
|
||||||
mfs "gx/ipfs/QmahrY1adY4wvtYEtoGjpZ2GUohTyukrkMkwUR9ytRjTG2/go-mfs"
|
mfs "gx/ipfs/QmahrY1adY4wvtYEtoGjpZ2GUohTyukrkMkwUR9ytRjTG2/go-mfs"
|
||||||
|
dag "gx/ipfs/QmcBoNcAP6qDjgRBew7yjvCqHq7p5jMstE44jPUBWBxzsV/go-merkledag"
|
||||||
|
bservice "gx/ipfs/QmcRecCZWM2NZfCQrCe97Ch3Givv8KKEP82tGUDntzdLFe/go-blockservice"
|
||||||
ipld "gx/ipfs/QmdDXJs4axxefSPgK6Y1QhpJWKuDPnGJiqgq4uncb4rFHL/go-ipld-format"
|
ipld "gx/ipfs/QmdDXJs4axxefSPgK6Y1QhpJWKuDPnGJiqgq4uncb4rFHL/go-ipld-format"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -120,6 +118,11 @@ var filesStatCmd = &cmds.Command{
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
api, err := cmdenv.GetApi(env)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
path, err := checkPath(req.Arguments[0])
|
path, err := checkPath(req.Arguments[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -138,7 +141,7 @@ var filesStatCmd = &cmds.Command{
|
|||||||
dagserv = node.DAG
|
dagserv = node.DAG
|
||||||
}
|
}
|
||||||
|
|
||||||
nd, err := getNodeFromPath(req.Context, node, dagserv, path)
|
nd, err := getNodeFromPath(req.Context, node, api, path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -305,6 +308,12 @@ var filesCpCmd = &oldcmds.Command{
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
api, err := req.InvocContext().GetApi()
|
||||||
|
if err != nil {
|
||||||
|
res.SetError(err, cmdkit.ErrNormal)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
flush, _, _ := req.Option("flush").Bool()
|
flush, _, _ := req.Option("flush").Bool()
|
||||||
|
|
||||||
src, err := checkPath(req.Arguments()[0])
|
src, err := checkPath(req.Arguments()[0])
|
||||||
@ -324,7 +333,7 @@ var filesCpCmd = &oldcmds.Command{
|
|||||||
dst += gopath.Base(src)
|
dst += gopath.Base(src)
|
||||||
}
|
}
|
||||||
|
|
||||||
nd, err := getNodeFromPath(req.Context(), node, node.DAG, src)
|
nd, err := getNodeFromPath(req.Context(), node, api, src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.SetError(fmt.Errorf("cp: cannot get node from path %s: %s", src, err), cmdkit.ErrNormal)
|
res.SetError(fmt.Errorf("cp: cannot get node from path %s: %s", src, err), cmdkit.ErrNormal)
|
||||||
return
|
return
|
||||||
@ -348,20 +357,15 @@ var filesCpCmd = &oldcmds.Command{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func getNodeFromPath(ctx context.Context, node *core.IpfsNode, dagservice ipld.DAGService, p string) (ipld.Node, error) {
|
func getNodeFromPath(ctx context.Context, node *core.IpfsNode, api iface.CoreAPI, p string) (ipld.Node, error) {
|
||||||
switch {
|
switch {
|
||||||
case strings.HasPrefix(p, "/ipfs/"):
|
case strings.HasPrefix(p, "/ipfs/"):
|
||||||
np, err := path.ParsePath(p)
|
np, err := iface.ParsePath(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
resolver := &resolver.Resolver{
|
return api.ResolveNode(ctx, np)
|
||||||
DAG: dagservice,
|
|
||||||
ResolveOnce: uio.ResolveUnixfsOnce,
|
|
||||||
}
|
|
||||||
|
|
||||||
return core.Resolve(ctx, node.Namesys, resolver, np)
|
|
||||||
default:
|
default:
|
||||||
fsn, err := mfs.Lookup(node.FilesRoot, p)
|
fsn, err := mfs.Lookup(node.FilesRoot, p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -7,19 +7,17 @@ import (
|
|||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
|
|
||||||
cmds "github.com/ipfs/go-ipfs/commands"
|
cmds "github.com/ipfs/go-ipfs/commands"
|
||||||
core "github.com/ipfs/go-ipfs/core"
|
|
||||||
e "github.com/ipfs/go-ipfs/core/commands/e"
|
e "github.com/ipfs/go-ipfs/core/commands/e"
|
||||||
|
iface "github.com/ipfs/go-ipfs/core/coreapi/interface"
|
||||||
|
|
||||||
|
cid "gx/ipfs/QmPSQnBKM9g7BaUcZCvswUJVscQ1ipjmwxN5PXCjkp9EQ7/go-cid"
|
||||||
|
offline "gx/ipfs/QmR5miWuikPxWyUrzMYJVmFUcD44pGdtc98h9Qsbp4YcJw/go-ipfs-exchange-offline"
|
||||||
|
"gx/ipfs/QmSP88ryZkHSRn1fnngAaV2Vcn63WUJzAavnRM9CVdU1Ky/go-ipfs-cmdkit"
|
||||||
unixfs "gx/ipfs/QmU4x3742bvgfxJsByEDpBnifJqjJdV6x528co4hwKCn46/go-unixfs"
|
unixfs "gx/ipfs/QmU4x3742bvgfxJsByEDpBnifJqjJdV6x528co4hwKCn46/go-unixfs"
|
||||||
uio "gx/ipfs/QmU4x3742bvgfxJsByEDpBnifJqjJdV6x528co4hwKCn46/go-unixfs/io"
|
uio "gx/ipfs/QmU4x3742bvgfxJsByEDpBnifJqjJdV6x528co4hwKCn46/go-unixfs/io"
|
||||||
unixfspb "gx/ipfs/QmU4x3742bvgfxJsByEDpBnifJqjJdV6x528co4hwKCn46/go-unixfs/pb"
|
unixfspb "gx/ipfs/QmU4x3742bvgfxJsByEDpBnifJqjJdV6x528co4hwKCn46/go-unixfs/pb"
|
||||||
merkledag "gx/ipfs/QmcBoNcAP6qDjgRBew7yjvCqHq7p5jMstE44jPUBWBxzsV/go-merkledag"
|
merkledag "gx/ipfs/QmcBoNcAP6qDjgRBew7yjvCqHq7p5jMstE44jPUBWBxzsV/go-merkledag"
|
||||||
blockservice "gx/ipfs/QmcRecCZWM2NZfCQrCe97Ch3Givv8KKEP82tGUDntzdLFe/go-blockservice"
|
blockservice "gx/ipfs/QmcRecCZWM2NZfCQrCe97Ch3Givv8KKEP82tGUDntzdLFe/go-blockservice"
|
||||||
path "gx/ipfs/QmcjwUb36Z16NJkvDX6ccXPqsFswo6AsRXynyXcLLCphV2/go-path"
|
|
||||||
resolver "gx/ipfs/QmcjwUb36Z16NJkvDX6ccXPqsFswo6AsRXynyXcLLCphV2/go-path/resolver"
|
|
||||||
|
|
||||||
cid "gx/ipfs/QmPSQnBKM9g7BaUcZCvswUJVscQ1ipjmwxN5PXCjkp9EQ7/go-cid"
|
|
||||||
offline "gx/ipfs/QmR5miWuikPxWyUrzMYJVmFUcD44pGdtc98h9Qsbp4YcJw/go-ipfs-exchange-offline"
|
|
||||||
"gx/ipfs/QmSP88ryZkHSRn1fnngAaV2Vcn63WUJzAavnRM9CVdU1Ky/go-ipfs-cmdkit"
|
|
||||||
ipld "gx/ipfs/QmdDXJs4axxefSPgK6Y1QhpJWKuDPnGJiqgq4uncb4rFHL/go-ipld-format"
|
ipld "gx/ipfs/QmdDXJs4axxefSPgK6Y1QhpJWKuDPnGJiqgq4uncb4rFHL/go-ipld-format"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -65,6 +63,12 @@ The JSON output contains type information.
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
api, err := req.InvocContext().GetApi()
|
||||||
|
if err != nil {
|
||||||
|
res.SetError(err, cmdkit.ErrNormal)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// get options early -> exit early in case of error
|
// get options early -> exit early in case of error
|
||||||
if _, _, err := req.Option("headers").Bool(); err != nil {
|
if _, _, err := req.Option("headers").Bool(); err != nil {
|
||||||
res.SetError(err, cmdkit.ErrNormal)
|
res.SetError(err, cmdkit.ErrNormal)
|
||||||
@ -88,18 +92,13 @@ The JSON output contains type information.
|
|||||||
|
|
||||||
var dagnodes []ipld.Node
|
var dagnodes []ipld.Node
|
||||||
for _, fpath := range paths {
|
for _, fpath := range paths {
|
||||||
p, err := path.ParsePath(fpath)
|
p, err := iface.ParsePath(fpath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.SetError(err, cmdkit.ErrNormal)
|
res.SetError(err, cmdkit.ErrNormal)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
r := &resolver.Resolver{
|
dagnode, err := api.ResolveNode(req.Context(), p)
|
||||||
DAG: nd.DAG,
|
|
||||||
ResolveOnce: uio.ResolveUnixfsOnce,
|
|
||||||
}
|
|
||||||
|
|
||||||
dagnode, err := core.Resolve(req.Context(), nd.Namesys, r, p)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.SetError(err, cmdkit.ErrNormal)
|
res.SetError(err, cmdkit.ErrNormal)
|
||||||
return
|
return
|
||||||
|
@ -10,9 +10,10 @@ import (
|
|||||||
cmds "github.com/ipfs/go-ipfs/commands"
|
cmds "github.com/ipfs/go-ipfs/commands"
|
||||||
core "github.com/ipfs/go-ipfs/core"
|
core "github.com/ipfs/go-ipfs/core"
|
||||||
e "github.com/ipfs/go-ipfs/core/commands/e"
|
e "github.com/ipfs/go-ipfs/core/commands/e"
|
||||||
|
iface "github.com/ipfs/go-ipfs/core/coreapi/interface"
|
||||||
|
options "github.com/ipfs/go-ipfs/core/coreapi/interface/options"
|
||||||
corerepo "github.com/ipfs/go-ipfs/core/corerepo"
|
corerepo "github.com/ipfs/go-ipfs/core/corerepo"
|
||||||
pin "github.com/ipfs/go-ipfs/pin"
|
pin "github.com/ipfs/go-ipfs/pin"
|
||||||
uio "gx/ipfs/QmU4x3742bvgfxJsByEDpBnifJqjJdV6x528co4hwKCn46/go-unixfs/io"
|
|
||||||
|
|
||||||
cid "gx/ipfs/QmPSQnBKM9g7BaUcZCvswUJVscQ1ipjmwxN5PXCjkp9EQ7/go-cid"
|
cid "gx/ipfs/QmPSQnBKM9g7BaUcZCvswUJVscQ1ipjmwxN5PXCjkp9EQ7/go-cid"
|
||||||
offline "gx/ipfs/QmR5miWuikPxWyUrzMYJVmFUcD44pGdtc98h9Qsbp4YcJw/go-ipfs-exchange-offline"
|
offline "gx/ipfs/QmR5miWuikPxWyUrzMYJVmFUcD44pGdtc98h9Qsbp4YcJw/go-ipfs-exchange-offline"
|
||||||
@ -20,8 +21,6 @@ import (
|
|||||||
"gx/ipfs/QmVkMRSkXrpjqrroEXWuYBvDBnXCdMMY6gsKicBGVGUqKT/go-verifcid"
|
"gx/ipfs/QmVkMRSkXrpjqrroEXWuYBvDBnXCdMMY6gsKicBGVGUqKT/go-verifcid"
|
||||||
dag "gx/ipfs/QmcBoNcAP6qDjgRBew7yjvCqHq7p5jMstE44jPUBWBxzsV/go-merkledag"
|
dag "gx/ipfs/QmcBoNcAP6qDjgRBew7yjvCqHq7p5jMstE44jPUBWBxzsV/go-merkledag"
|
||||||
bserv "gx/ipfs/QmcRecCZWM2NZfCQrCe97Ch3Givv8KKEP82tGUDntzdLFe/go-blockservice"
|
bserv "gx/ipfs/QmcRecCZWM2NZfCQrCe97Ch3Givv8KKEP82tGUDntzdLFe/go-blockservice"
|
||||||
path "gx/ipfs/QmcjwUb36Z16NJkvDX6ccXPqsFswo6AsRXynyXcLLCphV2/go-path"
|
|
||||||
resolver "gx/ipfs/QmcjwUb36Z16NJkvDX6ccXPqsFswo6AsRXynyXcLLCphV2/go-path/resolver"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var PinCmd = &cmds.Command{
|
var PinCmd = &cmds.Command{
|
||||||
@ -68,6 +67,12 @@ var addPinCmd = &cmds.Command{
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
api, err := req.InvocContext().GetApi()
|
||||||
|
if err != nil {
|
||||||
|
res.SetError(err, cmdkit.ErrNormal)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
defer n.Blockstore.PinLock().Unlock()
|
defer n.Blockstore.PinLock().Unlock()
|
||||||
|
|
||||||
// set recursive flag
|
// set recursive flag
|
||||||
@ -79,7 +84,7 @@ var addPinCmd = &cmds.Command{
|
|||||||
showProgress, _, _ := req.Option("progress").Bool()
|
showProgress, _, _ := req.Option("progress").Bool()
|
||||||
|
|
||||||
if !showProgress {
|
if !showProgress {
|
||||||
added, err := corerepo.Pin(n, req.Context(), req.Arguments(), recursive)
|
added, err := corerepo.Pin(n, api, req.Context(), req.Arguments(), recursive)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.SetError(err, cmdkit.ErrNormal)
|
res.SetError(err, cmdkit.ErrNormal)
|
||||||
return
|
return
|
||||||
@ -99,7 +104,7 @@ var addPinCmd = &cmds.Command{
|
|||||||
}
|
}
|
||||||
ch := make(chan pinResult, 1)
|
ch := make(chan pinResult, 1)
|
||||||
go func() {
|
go func() {
|
||||||
added, err := corerepo.Pin(n, ctx, req.Arguments(), recursive)
|
added, err := corerepo.Pin(n, api, ctx, req.Arguments(), recursive)
|
||||||
ch <- pinResult{pins: added, err: err}
|
ch <- pinResult{pins: added, err: err}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -193,6 +198,12 @@ collected if needed. (By default, recursively. Use -r=false for direct pins.)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
api, err := req.InvocContext().GetApi()
|
||||||
|
if err != nil {
|
||||||
|
res.SetError(err, cmdkit.ErrNormal)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// set recursive flag
|
// set recursive flag
|
||||||
recursive, _, err := req.Option("recursive").Bool()
|
recursive, _, err := req.Option("recursive").Bool()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -200,7 +211,7 @@ collected if needed. (By default, recursively. Use -r=false for direct pins.)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
removed, err := corerepo.Unpin(n, req.Context(), req.Arguments(), recursive)
|
removed, err := corerepo.Unpin(n, api, req.Context(), req.Arguments(), recursive)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.SetError(err, cmdkit.ErrNormal)
|
res.SetError(err, cmdkit.ErrNormal)
|
||||||
return
|
return
|
||||||
@ -287,6 +298,12 @@ Example:
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
api, err := req.InvocContext().GetApi()
|
||||||
|
if err != nil {
|
||||||
|
res.SetError(err, cmdkit.ErrNormal)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
typeStr, _, err := req.Option("type").String()
|
typeStr, _, err := req.Option("type").String()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.SetError(err, cmdkit.ErrNormal)
|
res.SetError(err, cmdkit.ErrNormal)
|
||||||
@ -304,7 +321,7 @@ Example:
|
|||||||
var keys map[string]RefKeyObject
|
var keys map[string]RefKeyObject
|
||||||
|
|
||||||
if len(req.Arguments()) > 0 {
|
if len(req.Arguments()) > 0 {
|
||||||
keys, err = pinLsKeys(req.Context(), req.Arguments(), typeStr, n)
|
keys, err = pinLsKeys(req.Context(), req.Arguments(), typeStr, n, api)
|
||||||
} else {
|
} else {
|
||||||
keys, err = pinLsAll(req.Context(), typeStr, n)
|
keys, err = pinLsAll(req.Context(), typeStr, n)
|
||||||
}
|
}
|
||||||
@ -364,7 +381,7 @@ new pin and removing the old one.
|
|||||||
},
|
},
|
||||||
Type: PinOutput{},
|
Type: PinOutput{},
|
||||||
Run: func(req cmds.Request, res cmds.Response) {
|
Run: func(req cmds.Request, res cmds.Response) {
|
||||||
n, err := req.InvocContext().GetNode()
|
api, err := req.InvocContext().GetApi()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.SetError(err, cmdkit.ErrNormal)
|
res.SetError(err, cmdkit.ErrNormal)
|
||||||
return
|
return
|
||||||
@ -376,42 +393,19 @@ new pin and removing the old one.
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
from, err := path.ParsePath(req.Arguments()[0])
|
from, err := iface.ParsePath(req.Arguments()[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.SetError(err, cmdkit.ErrNormal)
|
res.SetError(err, cmdkit.ErrNormal)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
to, err := path.ParsePath(req.Arguments()[1])
|
to, err := iface.ParsePath(req.Arguments()[1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.SetError(err, cmdkit.ErrNormal)
|
res.SetError(err, cmdkit.ErrNormal)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
r := &resolver.Resolver{
|
err = api.Pin().Update(req.Context(), from, to, options.Pin.Unpin(unpin))
|
||||||
DAG: n.DAG,
|
|
||||||
ResolveOnce: uio.ResolveUnixfsOnce,
|
|
||||||
}
|
|
||||||
|
|
||||||
fromc, err := core.ResolveToCid(req.Context(), n.Namesys, r, from)
|
|
||||||
if err != nil {
|
|
||||||
res.SetError(err, cmdkit.ErrNormal)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
toc, err := core.ResolveToCid(req.Context(), n.Namesys, r, to)
|
|
||||||
if err != nil {
|
|
||||||
res.SetError(err, cmdkit.ErrNormal)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err = n.Pinning.Update(req.Context(), fromc, toc, unpin)
|
|
||||||
if err != nil {
|
|
||||||
res.SetError(err, cmdkit.ErrNormal)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err = n.Pinning.Flush()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.SetError(err, cmdkit.ErrNormal)
|
res.SetError(err, cmdkit.ErrNormal)
|
||||||
return
|
return
|
||||||
@ -501,7 +495,7 @@ type RefKeyList struct {
|
|||||||
Keys map[string]RefKeyObject
|
Keys map[string]RefKeyObject
|
||||||
}
|
}
|
||||||
|
|
||||||
func pinLsKeys(ctx context.Context, args []string, typeStr string, n *core.IpfsNode) (map[string]RefKeyObject, error) {
|
func pinLsKeys(ctx context.Context, args []string, typeStr string, n *core.IpfsNode, api iface.CoreAPI) (map[string]RefKeyObject, error) {
|
||||||
|
|
||||||
mode, ok := pin.StringToMode(typeStr)
|
mode, ok := pin.StringToMode(typeStr)
|
||||||
if !ok {
|
if !ok {
|
||||||
@ -510,23 +504,18 @@ func pinLsKeys(ctx context.Context, args []string, typeStr string, n *core.IpfsN
|
|||||||
|
|
||||||
keys := make(map[string]RefKeyObject)
|
keys := make(map[string]RefKeyObject)
|
||||||
|
|
||||||
r := &resolver.Resolver{
|
|
||||||
DAG: n.DAG,
|
|
||||||
ResolveOnce: uio.ResolveUnixfsOnce,
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, p := range args {
|
for _, p := range args {
|
||||||
pth, err := path.ParsePath(p)
|
pth, err := iface.ParsePath(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
c, err := core.ResolveToCid(ctx, n.Namesys, r, pth)
|
c, err := api.ResolvePath(ctx, pth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
pinType, pinned, err := n.Pinning.IsPinnedWithType(c, mode)
|
pinType, pinned, err := n.Pinning.IsPinnedWithType(c.Cid(), mode)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -7,16 +7,13 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
|
|
||||||
cmdkit "gx/ipfs/QmSP88ryZkHSRn1fnngAaV2Vcn63WUJzAavnRM9CVdU1Ky/go-ipfs-cmdkit"
|
|
||||||
|
|
||||||
cmds "github.com/ipfs/go-ipfs/commands"
|
cmds "github.com/ipfs/go-ipfs/commands"
|
||||||
core "github.com/ipfs/go-ipfs/core"
|
|
||||||
e "github.com/ipfs/go-ipfs/core/commands/e"
|
e "github.com/ipfs/go-ipfs/core/commands/e"
|
||||||
|
iface "github.com/ipfs/go-ipfs/core/coreapi/interface"
|
||||||
|
|
||||||
|
cmdkit "gx/ipfs/QmSP88ryZkHSRn1fnngAaV2Vcn63WUJzAavnRM9CVdU1Ky/go-ipfs-cmdkit"
|
||||||
unixfs "gx/ipfs/QmU4x3742bvgfxJsByEDpBnifJqjJdV6x528co4hwKCn46/go-unixfs"
|
unixfs "gx/ipfs/QmU4x3742bvgfxJsByEDpBnifJqjJdV6x528co4hwKCn46/go-unixfs"
|
||||||
uio "gx/ipfs/QmU4x3742bvgfxJsByEDpBnifJqjJdV6x528co4hwKCn46/go-unixfs/io"
|
|
||||||
merkledag "gx/ipfs/QmcBoNcAP6qDjgRBew7yjvCqHq7p5jMstE44jPUBWBxzsV/go-merkledag"
|
merkledag "gx/ipfs/QmcBoNcAP6qDjgRBew7yjvCqHq7p5jMstE44jPUBWBxzsV/go-merkledag"
|
||||||
path "gx/ipfs/QmcjwUb36Z16NJkvDX6ccXPqsFswo6AsRXynyXcLLCphV2/go-path"
|
|
||||||
resolver "gx/ipfs/QmcjwUb36Z16NJkvDX6ccXPqsFswo6AsRXynyXcLLCphV2/go-path/resolver"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type LsLink struct {
|
type LsLink struct {
|
||||||
@ -82,6 +79,12 @@ possible, please use 'ipfs ls' instead.
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
api, err := req.InvocContext().GetApi()
|
||||||
|
if err != nil {
|
||||||
|
res.SetError(err, cmdkit.ErrNormal)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
paths := req.Arguments()
|
paths := req.Arguments()
|
||||||
|
|
||||||
output := LsOutput{
|
output := LsOutput{
|
||||||
@ -89,15 +92,16 @@ possible, please use 'ipfs ls' instead.
|
|||||||
Objects: map[string]*LsObject{},
|
Objects: map[string]*LsObject{},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, fpath := range paths {
|
for _, p := range paths {
|
||||||
ctx := req.Context()
|
ctx := req.Context()
|
||||||
|
|
||||||
resolver := &resolver.Resolver{
|
fpath, err := iface.ParsePath(p)
|
||||||
DAG: node.DAG,
|
if err != nil {
|
||||||
ResolveOnce: uio.ResolveUnixfsOnce,
|
res.SetError(err, cmdkit.ErrNormal)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
merkleNode, err := core.Resolve(ctx, node.Namesys, resolver, path.Path(fpath))
|
merkleNode, err := api.ResolveNode(ctx, fpath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.SetError(err, cmdkit.ErrNormal)
|
res.SetError(err, cmdkit.ErrNormal)
|
||||||
return
|
return
|
||||||
@ -106,7 +110,7 @@ possible, please use 'ipfs ls' instead.
|
|||||||
c := merkleNode.Cid()
|
c := merkleNode.Cid()
|
||||||
|
|
||||||
hash := c.String()
|
hash := c.String()
|
||||||
output.Arguments[fpath] = hash
|
output.Arguments[p] = hash
|
||||||
|
|
||||||
if _, ok := output.Objects[hash]; ok {
|
if _, ok := output.Objects[hash]; ok {
|
||||||
// duplicate argument for an already-listed node
|
// duplicate argument for an already-listed node
|
||||||
|
@ -1,10 +1,20 @@
|
|||||||
package iface
|
package iface
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Reader interface {
|
type Reader interface {
|
||||||
io.ReadSeeker
|
ReadSeekCloser
|
||||||
io.Closer
|
Size() uint64
|
||||||
|
CtxReadFull(context.Context, []byte) (int, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// A ReadSeekCloser implements interfaces to read, copy, seek and close.
|
||||||
|
type ReadSeekCloser interface {
|
||||||
|
io.Reader
|
||||||
|
io.Seeker
|
||||||
|
io.Closer
|
||||||
|
io.WriterTo
|
||||||
}
|
}
|
||||||
|
@ -29,12 +29,12 @@ func (api *PinAPI) Add(ctx context.Context, p coreiface.Path, opts ...caopts.Pin
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = corerepo.Pin(api.node, ctx, []string{rp.Cid().String()}, settings.Recursive)
|
_, err = corerepo.Pin(api.node, api.core(), ctx, []string{rp.Cid().String()}, settings.Recursive)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return api.node.Pinning.Flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PinAPI) Ls(ctx context.Context, opts ...caopts.PinLsOption) ([]coreiface.Pin, error) {
|
func (api *PinAPI) Ls(ctx context.Context, opts ...caopts.PinLsOption) ([]coreiface.Pin, error) {
|
||||||
@ -53,12 +53,12 @@ func (api *PinAPI) Ls(ctx context.Context, opts ...caopts.PinLsOption) ([]coreif
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (api *PinAPI) Rm(ctx context.Context, p coreiface.Path) error {
|
func (api *PinAPI) Rm(ctx context.Context, p coreiface.Path) error {
|
||||||
_, err := corerepo.Unpin(api.node, ctx, []string{p.String()}, true)
|
_, err := corerepo.Unpin(api.node, api.core(), ctx, []string{p.String()}, true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return api.node.Pinning.Flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (api *PinAPI) Update(ctx context.Context, from coreiface.Path, to coreiface.Path, opts ...caopts.PinUpdateOption) error {
|
func (api *PinAPI) Update(ctx context.Context, from coreiface.Path, to coreiface.Path, opts ...caopts.PinUpdateOption) error {
|
||||||
@ -77,7 +77,12 @@ func (api *PinAPI) Update(ctx context.Context, from coreiface.Path, to coreiface
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return api.node.Pinning.Update(ctx, fp.Cid(), tp.Cid(), settings.Unpin)
|
err = api.node.Pinning.Update(ctx, fp.Cid(), tp.Cid(), settings.Unpin)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return api.node.Pinning.Flush()
|
||||||
}
|
}
|
||||||
|
|
||||||
type pinStatus struct {
|
type pinStatus struct {
|
||||||
|
@ -18,28 +18,21 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/ipfs/go-ipfs/core"
|
"github.com/ipfs/go-ipfs/core"
|
||||||
uio "gx/ipfs/QmU4x3742bvgfxJsByEDpBnifJqjJdV6x528co4hwKCn46/go-unixfs/io"
|
"github.com/ipfs/go-ipfs/core/coreapi/interface"
|
||||||
path "gx/ipfs/QmcjwUb36Z16NJkvDX6ccXPqsFswo6AsRXynyXcLLCphV2/go-path"
|
|
||||||
resolver "gx/ipfs/QmcjwUb36Z16NJkvDX6ccXPqsFswo6AsRXynyXcLLCphV2/go-path/resolver"
|
|
||||||
|
|
||||||
cid "gx/ipfs/QmPSQnBKM9g7BaUcZCvswUJVscQ1ipjmwxN5PXCjkp9EQ7/go-cid"
|
"gx/ipfs/QmPSQnBKM9g7BaUcZCvswUJVscQ1ipjmwxN5PXCjkp9EQ7/go-cid"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Pin(n *core.IpfsNode, ctx context.Context, paths []string, recursive bool) ([]cid.Cid, error) {
|
func Pin(n *core.IpfsNode, api iface.CoreAPI, ctx context.Context, paths []string, recursive bool) ([]cid.Cid, error) {
|
||||||
out := make([]cid.Cid, len(paths))
|
out := make([]cid.Cid, len(paths))
|
||||||
|
|
||||||
r := &resolver.Resolver{
|
|
||||||
DAG: n.DAG,
|
|
||||||
ResolveOnce: uio.ResolveUnixfsOnce,
|
|
||||||
}
|
|
||||||
|
|
||||||
for i, fpath := range paths {
|
for i, fpath := range paths {
|
||||||
p, err := path.ParsePath(fpath)
|
p, err := iface.ParsePath(fpath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
dagnode, err := core.Resolve(ctx, n.Namesys, r, p)
|
dagnode, err := api.ResolveNode(ctx, p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("pin: %s", err)
|
return nil, fmt.Errorf("pin: %s", err)
|
||||||
}
|
}
|
||||||
@ -58,30 +51,25 @@ func Pin(n *core.IpfsNode, ctx context.Context, paths []string, recursive bool)
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Unpin(n *core.IpfsNode, ctx context.Context, paths []string, recursive bool) ([]cid.Cid, error) {
|
func Unpin(n *core.IpfsNode, api iface.CoreAPI, ctx context.Context, paths []string, recursive bool) ([]cid.Cid, error) {
|
||||||
unpinned := make([]cid.Cid, len(paths))
|
unpinned := make([]cid.Cid, len(paths))
|
||||||
|
|
||||||
r := &resolver.Resolver{
|
|
||||||
DAG: n.DAG,
|
|
||||||
ResolveOnce: uio.ResolveUnixfsOnce,
|
|
||||||
}
|
|
||||||
|
|
||||||
for i, p := range paths {
|
for i, p := range paths {
|
||||||
p, err := path.ParsePath(p)
|
p, err := iface.ParsePath(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
k, err := core.ResolveToCid(ctx, n.Namesys, r, p)
|
k, err := api.ResolvePath(ctx, p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = n.Pinning.Unpin(ctx, k, recursive)
|
err = n.Pinning.Unpin(ctx, k.Cid(), recursive)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
unpinned[i] = k
|
unpinned[i] = k.Cid()
|
||||||
}
|
}
|
||||||
|
|
||||||
err := n.Pinning.Flush()
|
err := n.Pinning.Flush()
|
||||||
|
@ -1,24 +0,0 @@
|
|||||||
package coreunix
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
core "github.com/ipfs/go-ipfs/core"
|
|
||||||
uio "gx/ipfs/QmU4x3742bvgfxJsByEDpBnifJqjJdV6x528co4hwKCn46/go-unixfs/io"
|
|
||||||
path "gx/ipfs/QmcjwUb36Z16NJkvDX6ccXPqsFswo6AsRXynyXcLLCphV2/go-path"
|
|
||||||
resolver "gx/ipfs/QmcjwUb36Z16NJkvDX6ccXPqsFswo6AsRXynyXcLLCphV2/go-path/resolver"
|
|
||||||
)
|
|
||||||
|
|
||||||
func Cat(ctx context.Context, n *core.IpfsNode, pstr string) (uio.DagReader, error) {
|
|
||||||
r := &resolver.Resolver{
|
|
||||||
DAG: n.DAG,
|
|
||||||
ResolveOnce: uio.ResolveUnixfsOnce,
|
|
||||||
}
|
|
||||||
|
|
||||||
dagNode, err := core.Resolve(ctx, n.Namesys, r, path.Path(pstr))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return uio.NewDagReader(ctx, dagNode, n.DAG)
|
|
||||||
}
|
|
@ -6,11 +6,10 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
namesys "github.com/ipfs/go-ipfs/namesys"
|
namesys "github.com/ipfs/go-ipfs/namesys"
|
||||||
|
|
||||||
|
logging "gx/ipfs/QmZChCsSt8DctjceaL56Eibc29CVQq4dGKRXC5JRZ6Ppae/go-log"
|
||||||
path "gx/ipfs/QmcjwUb36Z16NJkvDX6ccXPqsFswo6AsRXynyXcLLCphV2/go-path"
|
path "gx/ipfs/QmcjwUb36Z16NJkvDX6ccXPqsFswo6AsRXynyXcLLCphV2/go-path"
|
||||||
resolver "gx/ipfs/QmcjwUb36Z16NJkvDX6ccXPqsFswo6AsRXynyXcLLCphV2/go-path/resolver"
|
resolver "gx/ipfs/QmcjwUb36Z16NJkvDX6ccXPqsFswo6AsRXynyXcLLCphV2/go-path/resolver"
|
||||||
|
|
||||||
cid "gx/ipfs/QmPSQnBKM9g7BaUcZCvswUJVscQ1ipjmwxN5PXCjkp9EQ7/go-cid"
|
|
||||||
logging "gx/ipfs/QmZChCsSt8DctjceaL56Eibc29CVQq4dGKRXC5JRZ6Ppae/go-log"
|
|
||||||
ipld "gx/ipfs/QmdDXJs4axxefSPgK6Y1QhpJWKuDPnGJiqgq4uncb4rFHL/go-ipld-format"
|
ipld "gx/ipfs/QmdDXJs4axxefSPgK6Y1QhpJWKuDPnGJiqgq4uncb4rFHL/go-ipld-format"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -74,37 +73,3 @@ func Resolve(ctx context.Context, nsys namesys.NameSystem, r *resolver.Resolver,
|
|||||||
// ok, we have an IPFS path now (or what we'll treat as one)
|
// ok, we have an IPFS path now (or what we'll treat as one)
|
||||||
return r.ResolvePath(ctx, p)
|
return r.ResolvePath(ctx, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResolveToCid resolves a path to a cid.
|
|
||||||
//
|
|
||||||
// It first checks if the path is already in the form of just a cid (<cid> or
|
|
||||||
// /ipfs/<cid>) and returns immediately if so. Otherwise, it falls back onto
|
|
||||||
// Resolve to perform resolution of the dagnode being referenced.
|
|
||||||
func ResolveToCid(ctx context.Context, nsys namesys.NameSystem, r *resolver.Resolver, p path.Path) (cid.Cid, error) {
|
|
||||||
|
|
||||||
// If the path is simply a cid, parse and return it. Parsed paths are already
|
|
||||||
// normalized (read: prepended with /ipfs/ if needed), so segment[1] should
|
|
||||||
// always be the key.
|
|
||||||
if p.IsJustAKey() {
|
|
||||||
return cid.Decode(p.Segments()[1])
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fall back onto regular dagnode resolution. Retrieve the second-to-last
|
|
||||||
// segment of the path and resolve its link to the last segment.
|
|
||||||
head, tail, err := p.PopLastSegment()
|
|
||||||
if err != nil {
|
|
||||||
return cid.Cid{}, err
|
|
||||||
}
|
|
||||||
dagnode, err := Resolve(ctx, nsys, r, head)
|
|
||||||
if err != nil {
|
|
||||||
return cid.Cid{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Extract and return the cid of the link to the target dag node.
|
|
||||||
link, _, err := dagnode.ResolveLink([]string{tail})
|
|
||||||
if err != nil {
|
|
||||||
return cid.Cid{}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return link.Cid, nil
|
|
||||||
}
|
|
||||||
|
@ -14,16 +14,17 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
core "github.com/ipfs/go-ipfs/core"
|
core "github.com/ipfs/go-ipfs/core"
|
||||||
coreunix "github.com/ipfs/go-ipfs/core/coreunix"
|
coreapi "github.com/ipfs/go-ipfs/core/coreapi"
|
||||||
|
iface "github.com/ipfs/go-ipfs/core/coreapi/interface"
|
||||||
coremock "github.com/ipfs/go-ipfs/core/mock"
|
coremock "github.com/ipfs/go-ipfs/core/mock"
|
||||||
importer "gx/ipfs/QmU4x3742bvgfxJsByEDpBnifJqjJdV6x528co4hwKCn46/go-unixfs/importer"
|
|
||||||
uio "gx/ipfs/QmU4x3742bvgfxJsByEDpBnifJqjJdV6x528co4hwKCn46/go-unixfs/io"
|
|
||||||
dag "gx/ipfs/QmcBoNcAP6qDjgRBew7yjvCqHq7p5jMstE44jPUBWBxzsV/go-merkledag"
|
|
||||||
|
|
||||||
ci "gx/ipfs/QmNfQbgBfARAtrYsBguChX6VJ5nbjeoYy1KdC36aaYWqG8/go-testutil/ci"
|
ci "gx/ipfs/QmNfQbgBfARAtrYsBguChX6VJ5nbjeoYy1KdC36aaYWqG8/go-testutil/ci"
|
||||||
u "gx/ipfs/QmPdKqUcHGFdeSpvjVoaTRPPstGif9GBZb5Q56RVw9o69A/go-ipfs-util"
|
u "gx/ipfs/QmPdKqUcHGFdeSpvjVoaTRPPstGif9GBZb5Q56RVw9o69A/go-ipfs-util"
|
||||||
fstest "gx/ipfs/QmSJBsmLP1XMjv8hxYg2rUMdPDB7YUpyBo9idjrJ6Cmq6F/fuse/fs/fstestutil"
|
fstest "gx/ipfs/QmSJBsmLP1XMjv8hxYg2rUMdPDB7YUpyBo9idjrJ6Cmq6F/fuse/fs/fstestutil"
|
||||||
|
importer "gx/ipfs/QmU4x3742bvgfxJsByEDpBnifJqjJdV6x528co4hwKCn46/go-unixfs/importer"
|
||||||
|
uio "gx/ipfs/QmU4x3742bvgfxJsByEDpBnifJqjJdV6x528co4hwKCn46/go-unixfs/io"
|
||||||
chunker "gx/ipfs/QmULKgr55cSWR8Kiwy3cVRcAiGVnR6EVSaB7hJcWS4138p/go-ipfs-chunker"
|
chunker "gx/ipfs/QmULKgr55cSWR8Kiwy3cVRcAiGVnR6EVSaB7hJcWS4138p/go-ipfs-chunker"
|
||||||
|
dag "gx/ipfs/QmcBoNcAP6qDjgRBew7yjvCqHq7p5jMstE44jPUBWBxzsV/go-merkledag"
|
||||||
ipld "gx/ipfs/QmdDXJs4axxefSPgK6Y1QhpJWKuDPnGJiqgq4uncb4rFHL/go-ipld-format"
|
ipld "gx/ipfs/QmdDXJs4axxefSPgK6Y1QhpJWKuDPnGJiqgq4uncb4rFHL/go-ipld-format"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -116,6 +117,8 @@ func TestIpfsStressRead(t *testing.T) {
|
|||||||
nd, mnt := setupIpfsTest(t, nil)
|
nd, mnt := setupIpfsTest(t, nil)
|
||||||
defer mnt.Close()
|
defer mnt.Close()
|
||||||
|
|
||||||
|
api := coreapi.NewCoreAPI(nd)
|
||||||
|
|
||||||
var nodes []ipld.Node
|
var nodes []ipld.Node
|
||||||
var paths []string
|
var paths []string
|
||||||
|
|
||||||
@ -165,14 +168,14 @@ func TestIpfsStressRead(t *testing.T) {
|
|||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
|
||||||
for i := 0; i < 2000; i++ {
|
for i := 0; i < 2000; i++ {
|
||||||
item := paths[rand.Intn(len(paths))]
|
item, _ := iface.ParsePath(paths[rand.Intn(len(paths))])
|
||||||
fname := path.Join(mnt.Dir, item)
|
fname := path.Join(mnt.Dir, item.String())
|
||||||
rbuf, err := ioutil.ReadFile(fname)
|
rbuf, err := ioutil.ReadFile(fname)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errs <- err
|
errs <- err
|
||||||
}
|
}
|
||||||
|
|
||||||
read, err := coreunix.Cat(nd.Context(), nd, item)
|
read, err := api.Unixfs().Cat(nd.Context(), item)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errs <- err
|
errs <- err
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,8 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ipfs/go-ipfs/core"
|
"github.com/ipfs/go-ipfs/core"
|
||||||
|
"github.com/ipfs/go-ipfs/core/coreapi"
|
||||||
|
"github.com/ipfs/go-ipfs/core/coreapi/interface"
|
||||||
coreunix "github.com/ipfs/go-ipfs/core/coreunix"
|
coreunix "github.com/ipfs/go-ipfs/core/coreunix"
|
||||||
mock "github.com/ipfs/go-ipfs/core/mock"
|
mock "github.com/ipfs/go-ipfs/core/mock"
|
||||||
"github.com/ipfs/go-ipfs/thirdparty/unit"
|
"github.com/ipfs/go-ipfs/thirdparty/unit"
|
||||||
@ -118,6 +120,8 @@ func DirectAddCat(data []byte, conf testutil.LatencyConfig) error {
|
|||||||
}
|
}
|
||||||
defer catter.Close()
|
defer catter.Close()
|
||||||
|
|
||||||
|
catterApi := coreapi.NewCoreAPI(catter)
|
||||||
|
|
||||||
err = mn.LinkAll()
|
err = mn.LinkAll()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -138,7 +142,12 @@ func DirectAddCat(data []byte, conf testutil.LatencyConfig) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
readerCatted, err := coreunix.Cat(ctx, catter, added)
|
ap, err := iface.ParsePath(added)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
readerCatted, err := catterApi.Unixfs().Cat(ctx, ap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,8 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/ipfs/go-ipfs/core"
|
"github.com/ipfs/go-ipfs/core"
|
||||||
|
"github.com/ipfs/go-ipfs/core/coreapi"
|
||||||
|
"github.com/ipfs/go-ipfs/core/coreapi/interface"
|
||||||
coreunix "github.com/ipfs/go-ipfs/core/coreunix"
|
coreunix "github.com/ipfs/go-ipfs/core/coreunix"
|
||||||
mock "github.com/ipfs/go-ipfs/core/mock"
|
mock "github.com/ipfs/go-ipfs/core/mock"
|
||||||
"github.com/ipfs/go-ipfs/thirdparty/unit"
|
"github.com/ipfs/go-ipfs/thirdparty/unit"
|
||||||
@ -64,6 +66,8 @@ func benchCat(b *testing.B, data []byte, conf testutil.LatencyConfig) error {
|
|||||||
}
|
}
|
||||||
defer catter.Close()
|
defer catter.Close()
|
||||||
|
|
||||||
|
catterApi := coreapi.NewCoreAPI(catter)
|
||||||
|
|
||||||
err = mn.LinkAll()
|
err = mn.LinkAll()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -84,8 +88,13 @@ func benchCat(b *testing.B, data []byte, conf testutil.LatencyConfig) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ap, err := iface.ParsePath(added)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
b.StartTimer()
|
b.StartTimer()
|
||||||
readerCatted, err := coreunix.Cat(ctx, catter, added)
|
readerCatted, err := catterApi.Unixfs().Cat(ctx, ap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,8 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
core "github.com/ipfs/go-ipfs/core"
|
core "github.com/ipfs/go-ipfs/core"
|
||||||
|
"github.com/ipfs/go-ipfs/core/coreapi"
|
||||||
|
"github.com/ipfs/go-ipfs/core/coreapi/interface"
|
||||||
coreunix "github.com/ipfs/go-ipfs/core/coreunix"
|
coreunix "github.com/ipfs/go-ipfs/core/coreunix"
|
||||||
mock "github.com/ipfs/go-ipfs/core/mock"
|
mock "github.com/ipfs/go-ipfs/core/mock"
|
||||||
"github.com/ipfs/go-ipfs/thirdparty/unit"
|
"github.com/ipfs/go-ipfs/thirdparty/unit"
|
||||||
@ -100,6 +102,9 @@ func RunThreeLeggedCat(data []byte, conf testutil.LatencyConfig) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer catter.Close()
|
defer catter.Close()
|
||||||
|
|
||||||
|
catterApi := coreapi.NewCoreAPI(catter)
|
||||||
|
|
||||||
mn.LinkAll()
|
mn.LinkAll()
|
||||||
|
|
||||||
bis := bootstrap.Peerstore.PeerInfo(bootstrap.PeerHost.ID())
|
bis := bootstrap.Peerstore.PeerInfo(bootstrap.PeerHost.ID())
|
||||||
@ -116,7 +121,12 @@ func RunThreeLeggedCat(data []byte, conf testutil.LatencyConfig) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
readerCatted, err := coreunix.Cat(ctx, catter, added)
|
ap, err := iface.ParsePath(added)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
readerCatted, err := catterApi.Unixfs().Cat(ctx, ap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user