From 86da181f7f5ac430cdcf7a9aae194083cf82085d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Wed, 22 Feb 2023 16:56:59 +0100 Subject: [PATCH] feat(pinning): connect some missing go context (#9557) Co-authored-by: Henrique Dias --- core/coreapi/block.go | 4 +++- core/coreapi/dag.go | 11 ++++++++--- core/coreapi/object.go | 8 ++++++-- core/coreunix/add.go | 7 ++++++- docs/examples/kubo-as-a-library/go.mod | 2 +- docs/examples/kubo-as-a-library/go.sum | 4 ++-- go.mod | 2 +- go.sum | 4 ++-- 8 files changed, 29 insertions(+), 13 deletions(-) diff --git a/core/coreapi/block.go b/core/coreapi/block.go index 4f086ae8616..450f06f3bdc 100644 --- a/core/coreapi/block.go +++ b/core/coreapi/block.go @@ -60,7 +60,9 @@ func (api *BlockAPI) Put(ctx context.Context, src io.Reader, opts ...caopts.Bloc } if settings.Pin { - api.pinning.PinWithMode(b.Cid(), pin.Recursive) + if err = api.pinning.PinWithMode(ctx, b.Cid(), pin.Recursive); err != nil { + return nil, err + } if err := api.pinning.Flush(ctx); err != nil { return nil, err } diff --git a/core/coreapi/dag.go b/core/coreapi/dag.go index 0f38fc4d56a..b352a2d3f46 100644 --- a/core/coreapi/dag.go +++ b/core/coreapi/dag.go @@ -7,9 +7,10 @@ import ( pin "github.com/ipfs/go-ipfs-pinner" ipld "github.com/ipfs/go-ipld-format" dag "github.com/ipfs/go-merkledag" - "github.com/ipfs/kubo/tracing" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" + + "github.com/ipfs/kubo/tracing" ) type dagAPI struct { @@ -29,7 +30,9 @@ func (adder *pinningAdder) Add(ctx context.Context, nd ipld.Node) error { return err } - adder.pinning.PinWithMode(nd.Cid(), pin.Recursive) + if err := adder.pinning.PinWithMode(ctx, nd.Cid(), pin.Recursive); err != nil { + return err + } return adder.pinning.Flush(ctx) } @@ -48,7 +51,9 @@ func (adder *pinningAdder) AddMany(ctx context.Context, nds []ipld.Node) error { for _, nd := range nds { c := nd.Cid() if cids.Visit(c) { - adder.pinning.PinWithMode(c, pin.Recursive) + if err := adder.pinning.PinWithMode(ctx, c, pin.Recursive); err != nil { + return err + } } } diff --git a/core/coreapi/object.go b/core/coreapi/object.go index 28dd0df08f6..4b509c78210 100644 --- a/core/coreapi/object.go +++ b/core/coreapi/object.go @@ -19,9 +19,10 @@ import ( coreiface "github.com/ipfs/interface-go-ipfs-core" caopts "github.com/ipfs/interface-go-ipfs-core/options" ipath "github.com/ipfs/interface-go-ipfs-core/path" - "github.com/ipfs/kubo/tracing" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" + + "github.com/ipfs/kubo/tracing" ) const inputLimit = 2 << 20 @@ -132,7 +133,10 @@ func (api *ObjectAPI) Put(ctx context.Context, src io.Reader, opts ...caopts.Obj } if options.Pin { - api.pinning.PinWithMode(dagnode.Cid(), pin.Recursive) + if err := api.pinning.PinWithMode(ctx, dagnode.Cid(), pin.Recursive); err != nil { + return nil, err + } + err = api.pinning.Flush(ctx) if err != nil { return nil, err diff --git a/core/coreunix/add.go b/core/coreunix/add.go index f895baf738e..d2c4c3dff43 100644 --- a/core/coreunix/add.go +++ b/core/coreunix/add.go @@ -24,6 +24,7 @@ import ( "github.com/ipfs/go-unixfs/importer/trickle" coreiface "github.com/ipfs/interface-go-ipfs-core" "github.com/ipfs/interface-go-ipfs-core/path" + "github.com/ipfs/kubo/tracing" ) @@ -185,7 +186,11 @@ func (adder *Adder) PinRoot(ctx context.Context, root ipld.Node) error { adder.tempRoot = rnk } - adder.pinning.PinWithMode(rnk, pin.Recursive) + err = adder.pinning.PinWithMode(ctx, rnk, pin.Recursive) + if err != nil { + return err + } + return adder.pinning.Flush(ctx) } diff --git a/docs/examples/kubo-as-a-library/go.mod b/docs/examples/kubo-as-a-library/go.mod index 7c421a937cc..8e29e2333a1 100644 --- a/docs/examples/kubo-as-a-library/go.mod +++ b/docs/examples/kubo-as-a-library/go.mod @@ -84,7 +84,7 @@ require ( github.com/ipfs/go-ipfs-exchange-interface v0.2.0 // indirect github.com/ipfs/go-ipfs-exchange-offline v0.3.0 // indirect github.com/ipfs/go-ipfs-keystore v0.1.0 // indirect - github.com/ipfs/go-ipfs-pinner v0.2.1 // indirect + github.com/ipfs/go-ipfs-pinner v0.3.0 // indirect github.com/ipfs/go-ipfs-posinfo v0.0.1 // indirect github.com/ipfs/go-ipfs-pq v0.0.3 // indirect github.com/ipfs/go-ipfs-provider v0.8.1 // indirect diff --git a/docs/examples/kubo-as-a-library/go.sum b/docs/examples/kubo-as-a-library/go.sum index d83b0c50754..ff42c13b6cd 100644 --- a/docs/examples/kubo-as-a-library/go.sum +++ b/docs/examples/kubo-as-a-library/go.sum @@ -533,8 +533,8 @@ github.com/ipfs/go-ipfs-exchange-offline v0.3.0/go.mod h1:MOdJ9DChbb5u37M1IcbrRB github.com/ipfs/go-ipfs-files v0.0.3/go.mod h1:INEFm0LL2LWXBhNJ2PMIIb2w45hpXgPjNoE7yA8Y1d4= github.com/ipfs/go-ipfs-keystore v0.1.0 h1:gfuQUO/cyGZgZIHE6OrJas4OnwuxXCqJG7tI0lrB5Qc= github.com/ipfs/go-ipfs-keystore v0.1.0/go.mod h1:LvLw7Qhnb0RlMOfCzK6OmyWxICip6lQ06CCmdbee75U= -github.com/ipfs/go-ipfs-pinner v0.2.1 h1:kw9hiqh2p8TatILYZ3WAfQQABby7SQARdrdA+5Z5QfY= -github.com/ipfs/go-ipfs-pinner v0.2.1/go.mod h1:l1AtLL5bovb7opnG77sh4Y10waINz3Y1ni6CvTzx7oo= +github.com/ipfs/go-ipfs-pinner v0.3.0 h1:jwe5ViX3BON3KgOAYrrhav2+1ONB0QzFAWQd7HUlbuM= +github.com/ipfs/go-ipfs-pinner v0.3.0/go.mod h1:oX0I0nC6zlNIh0LslSrUnjfNKPq8ufoFtqV1/wcJvyo= github.com/ipfs/go-ipfs-posinfo v0.0.1 h1:Esoxj+1JgSjX0+ylc0hUmJCOv6V2vFoZiETLR6OtpRs= github.com/ipfs/go-ipfs-posinfo v0.0.1/go.mod h1:SwyeVP+jCwiDu0C313l/8jg6ZxM0qqtlt2a0vILTc1A= github.com/ipfs/go-ipfs-pq v0.0.1/go.mod h1:LWIqQpqfRG3fNc5XsnIhz/wQ2XXGyugQwls7BgUmUfY= diff --git a/go.mod b/go.mod index a9634a22be5..c42d9bd0702 100644 --- a/go.mod +++ b/go.mod @@ -36,7 +36,7 @@ require ( github.com/ipfs/go-ipfs-exchange-interface v0.2.0 github.com/ipfs/go-ipfs-exchange-offline v0.3.0 github.com/ipfs/go-ipfs-keystore v0.1.0 - github.com/ipfs/go-ipfs-pinner v0.2.1 + github.com/ipfs/go-ipfs-pinner v0.3.0 github.com/ipfs/go-ipfs-posinfo v0.0.1 github.com/ipfs/go-ipfs-provider v0.8.1 github.com/ipfs/go-ipfs-routing v0.3.0 diff --git a/go.sum b/go.sum index 5a89b69af2d..5b8cf6d46a2 100644 --- a/go.sum +++ b/go.sum @@ -553,8 +553,8 @@ github.com/ipfs/go-ipfs-exchange-offline v0.3.0/go.mod h1:MOdJ9DChbb5u37M1IcbrRB github.com/ipfs/go-ipfs-files v0.0.3/go.mod h1:INEFm0LL2LWXBhNJ2PMIIb2w45hpXgPjNoE7yA8Y1d4= github.com/ipfs/go-ipfs-keystore v0.1.0 h1:gfuQUO/cyGZgZIHE6OrJas4OnwuxXCqJG7tI0lrB5Qc= github.com/ipfs/go-ipfs-keystore v0.1.0/go.mod h1:LvLw7Qhnb0RlMOfCzK6OmyWxICip6lQ06CCmdbee75U= -github.com/ipfs/go-ipfs-pinner v0.2.1 h1:kw9hiqh2p8TatILYZ3WAfQQABby7SQARdrdA+5Z5QfY= -github.com/ipfs/go-ipfs-pinner v0.2.1/go.mod h1:l1AtLL5bovb7opnG77sh4Y10waINz3Y1ni6CvTzx7oo= +github.com/ipfs/go-ipfs-pinner v0.3.0 h1:jwe5ViX3BON3KgOAYrrhav2+1ONB0QzFAWQd7HUlbuM= +github.com/ipfs/go-ipfs-pinner v0.3.0/go.mod h1:oX0I0nC6zlNIh0LslSrUnjfNKPq8ufoFtqV1/wcJvyo= github.com/ipfs/go-ipfs-posinfo v0.0.1 h1:Esoxj+1JgSjX0+ylc0hUmJCOv6V2vFoZiETLR6OtpRs= github.com/ipfs/go-ipfs-posinfo v0.0.1/go.mod h1:SwyeVP+jCwiDu0C313l/8jg6ZxM0qqtlt2a0vILTc1A= github.com/ipfs/go-ipfs-pq v0.0.1/go.mod h1:LWIqQpqfRG3fNc5XsnIhz/wQ2XXGyugQwls7BgUmUfY=