mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-29 17:36:38 +08:00
Merge pull request #3975 from Stebalien/fix/3974
pinning + pathresolver: fix pinning/unpinning of sharded directories
This commit is contained in:
@ -12,6 +12,7 @@ import (
|
|||||||
dag "github.com/ipfs/go-ipfs/merkledag"
|
dag "github.com/ipfs/go-ipfs/merkledag"
|
||||||
path "github.com/ipfs/go-ipfs/path"
|
path "github.com/ipfs/go-ipfs/path"
|
||||||
pin "github.com/ipfs/go-ipfs/pin"
|
pin "github.com/ipfs/go-ipfs/pin"
|
||||||
|
uio "github.com/ipfs/go-ipfs/unixfs/io"
|
||||||
|
|
||||||
context "context"
|
context "context"
|
||||||
u "gx/ipfs/QmWbjfz3u6HkAdPh34dgPchGbQjob6LXLhAeCGii2TX69n/go-ipfs-util"
|
u "gx/ipfs/QmWbjfz3u6HkAdPh34dgPchGbQjob6LXLhAeCGii2TX69n/go-ipfs-util"
|
||||||
@ -377,13 +378,18 @@ new pin and removing the old one.
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fromc, err := core.ResolveToCid(req.Context(), n, from)
|
r := &path.Resolver{
|
||||||
|
DAG: n.DAG,
|
||||||
|
ResolveOnce: uio.ResolveUnixfsOnce,
|
||||||
|
}
|
||||||
|
|
||||||
|
fromc, err := core.ResolveToCid(req.Context(), n.Namesys, r, from)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.SetError(err, cmds.ErrNormal)
|
res.SetError(err, cmds.ErrNormal)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
toc, err := core.ResolveToCid(req.Context(), n, to)
|
toc, err := core.ResolveToCid(req.Context(), n.Namesys, r, to)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.SetError(err, cmds.ErrNormal)
|
res.SetError(err, cmds.ErrNormal)
|
||||||
return
|
return
|
||||||
@ -486,13 +492,18 @@ func pinLsKeys(args []string, typeStr string, ctx context.Context, n *core.IpfsN
|
|||||||
|
|
||||||
keys := make(map[string]RefKeyObject)
|
keys := make(map[string]RefKeyObject)
|
||||||
|
|
||||||
|
r := &path.Resolver{
|
||||||
|
DAG: n.DAG,
|
||||||
|
ResolveOnce: uio.ResolveUnixfsOnce,
|
||||||
|
}
|
||||||
|
|
||||||
for _, p := range args {
|
for _, p := range args {
|
||||||
pth, err := path.ParsePath(p)
|
pth, err := path.ParsePath(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
c, err := core.ResolveToCid(ctx, n, pth)
|
c, err := core.ResolveToCid(ctx, n.Namesys, r, pth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ import (
|
|||||||
|
|
||||||
"github.com/ipfs/go-ipfs/core"
|
"github.com/ipfs/go-ipfs/core"
|
||||||
path "github.com/ipfs/go-ipfs/path"
|
path "github.com/ipfs/go-ipfs/path"
|
||||||
|
uio "github.com/ipfs/go-ipfs/unixfs/io"
|
||||||
|
|
||||||
cid "gx/ipfs/QmYhQaCYEcaPPjxJX7YcPcVKkQfRy6sJ7B3XmGFk82XYdQ/go-cid"
|
cid "gx/ipfs/QmYhQaCYEcaPPjxJX7YcPcVKkQfRy6sJ7B3XmGFk82XYdQ/go-cid"
|
||||||
node "gx/ipfs/Qmb3Hm9QDFmfYuET4pu7Kyg8JV78jFa1nvZx5vnCZsK4ck/go-ipld-format"
|
node "gx/ipfs/Qmb3Hm9QDFmfYuET4pu7Kyg8JV78jFa1nvZx5vnCZsK4ck/go-ipld-format"
|
||||||
@ -26,13 +27,19 @@ import (
|
|||||||
|
|
||||||
func Pin(n *core.IpfsNode, ctx context.Context, paths []string, recursive bool) ([]*cid.Cid, error) {
|
func Pin(n *core.IpfsNode, ctx context.Context, paths []string, recursive bool) ([]*cid.Cid, error) {
|
||||||
dagnodes := make([]node.Node, 0)
|
dagnodes := make([]node.Node, 0)
|
||||||
|
|
||||||
|
r := &path.Resolver{
|
||||||
|
DAG: n.DAG,
|
||||||
|
ResolveOnce: uio.ResolveUnixfsOnce,
|
||||||
|
}
|
||||||
|
|
||||||
for _, fpath := range paths {
|
for _, fpath := range paths {
|
||||||
p, err := path.ParsePath(fpath)
|
p, err := path.ParsePath(fpath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
dagnode, err := core.Resolve(ctx, n.Namesys, n.Resolver, p)
|
dagnode, err := core.Resolve(ctx, n.Namesys, r, p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("pin: %s", err)
|
return nil, fmt.Errorf("pin: %s", err)
|
||||||
}
|
}
|
||||||
@ -61,15 +68,20 @@ func Pin(n *core.IpfsNode, ctx context.Context, paths []string, recursive bool)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Unpin(n *core.IpfsNode, ctx context.Context, paths []string, recursive bool) ([]*cid.Cid, error) {
|
func Unpin(n *core.IpfsNode, ctx context.Context, paths []string, recursive bool) ([]*cid.Cid, error) {
|
||||||
|
|
||||||
var unpinned []*cid.Cid
|
var unpinned []*cid.Cid
|
||||||
|
|
||||||
|
r := &path.Resolver{
|
||||||
|
DAG: n.DAG,
|
||||||
|
ResolveOnce: uio.ResolveUnixfsOnce,
|
||||||
|
}
|
||||||
|
|
||||||
for _, p := range paths {
|
for _, p := range paths {
|
||||||
p, err := path.ParsePath(p)
|
p, err := path.ParsePath(p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
k, err := core.ResolveToCid(ctx, n, p)
|
k, err := core.ResolveToCid(ctx, n.Namesys, r, p)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -57,14 +57,14 @@ func Resolve(ctx context.Context, nsys namesys.NameSystem, r *path.Resolver, p p
|
|||||||
return r.ResolvePath(ctx, p)
|
return r.ResolvePath(ctx, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResolveToKey resolves a path to a key.
|
// ResolveToCid resolves a path to a cid.
|
||||||
//
|
//
|
||||||
// It first checks if the path is already in the form of just a key (<key> or
|
// It first checks if the path is already in the form of just a cid (<cid> or
|
||||||
// /ipfs/<key>) and returns immediately if so. Otherwise, it falls back onto
|
// /ipfs/<cid>) and returns immediately if so. Otherwise, it falls back onto
|
||||||
// Resolve to perform resolution of the dagnode being referenced.
|
// Resolve to perform resolution of the dagnode being referenced.
|
||||||
func ResolveToCid(ctx context.Context, n *IpfsNode, p path.Path) (*cid.Cid, error) {
|
func ResolveToCid(ctx context.Context, nsys namesys.NameSystem, r *path.Resolver, p path.Path) (*cid.Cid, error) {
|
||||||
|
|
||||||
// If the path is simply a key, parse and return it. Parsed paths are already
|
// 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
|
// normalized (read: prepended with /ipfs/ if needed), so segment[1] should
|
||||||
// always be the key.
|
// always be the key.
|
||||||
if p.IsJustAKey() {
|
if p.IsJustAKey() {
|
||||||
@ -77,12 +77,12 @@ func ResolveToCid(ctx context.Context, n *IpfsNode, p path.Path) (*cid.Cid, erro
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
dagnode, err := Resolve(ctx, n.Namesys, n.Resolver, head)
|
dagnode, err := Resolve(ctx, nsys, r, head)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract and return the key of the link to the target dag node.
|
// Extract and return the cid of the link to the target dag node.
|
||||||
link, _, err := dagnode.ResolveLink([]string{tail})
|
link, _, err := dagnode.ResolveLink([]string{tail})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -72,6 +72,16 @@ test_sharding() {
|
|||||||
test_cmp file_out file_exp
|
test_cmp file_out file_exp
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success "can pin a file from sharded directory" '
|
||||||
|
ipfs files stat --hash /foo/file42 > pin_file_hash &&
|
||||||
|
ipfs pin add < pin_file_hash > pin_hash
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success "can unpin a file from sharded directory" '
|
||||||
|
read -r _ HASH _ < pin_hash &&
|
||||||
|
ipfs pin rm $HASH
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success "output object was really sharded" '
|
test_expect_success "output object was really sharded" '
|
||||||
ipfs files stat --hash /foo > expected_foo_hash &&
|
ipfs files stat --hash /foo > expected_foo_hash &&
|
||||||
echo QmPkwLJTYZRGPJ8Lazr9qPdrLmswPtUjaDbEpmR9jEh1se > actual_foo_hash &&
|
echo QmPkwLJTYZRGPJ8Lazr9qPdrLmswPtUjaDbEpmR9jEh1se > actual_foo_hash &&
|
||||||
|
Reference in New Issue
Block a user