From b7c5e21791d238815badf2665ef813f730b602ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Mon, 16 Jan 2023 17:28:43 +0100 Subject: [PATCH 1/3] pinning: connect some missing go context --- core/coreapi/block.go | 2 +- core/coreapi/dag.go | 7 ++++--- core/coreapi/object.go | 5 +++-- core/coreunix/add.go | 3 ++- go.mod | 2 ++ go.sum | 4 ++-- 6 files changed, 14 insertions(+), 9 deletions(-) diff --git a/core/coreapi/block.go b/core/coreapi/block.go index 4f086ae8616..84bd47bdd1d 100644 --- a/core/coreapi/block.go +++ b/core/coreapi/block.go @@ -60,7 +60,7 @@ func (api *BlockAPI) Put(ctx context.Context, src io.Reader, opts ...caopts.Bloc } if settings.Pin { - api.pinning.PinWithMode(b.Cid(), pin.Recursive) + api.pinning.PinWithMode(ctx, b.Cid(), pin.Recursive) 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..06c67d5bd31 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,7 @@ func (adder *pinningAdder) Add(ctx context.Context, nd ipld.Node) error { return err } - adder.pinning.PinWithMode(nd.Cid(), pin.Recursive) + adder.pinning.PinWithMode(ctx, nd.Cid(), pin.Recursive) return adder.pinning.Flush(ctx) } @@ -48,7 +49,7 @@ 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) + adder.pinning.PinWithMode(ctx, c, pin.Recursive) } } diff --git a/core/coreapi/object.go b/core/coreapi/object.go index 28dd0df08f6..34000a1e112 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,7 @@ func (api *ObjectAPI) Put(ctx context.Context, src io.Reader, opts ...caopts.Obj } if options.Pin { - api.pinning.PinWithMode(dagnode.Cid(), pin.Recursive) + api.pinning.PinWithMode(ctx, dagnode.Cid(), pin.Recursive) 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..5ba6569f9b0 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,7 @@ func (adder *Adder) PinRoot(ctx context.Context, root ipld.Node) error { adder.tempRoot = rnk } - adder.pinning.PinWithMode(rnk, pin.Recursive) + adder.pinning.PinWithMode(ctx, rnk, pin.Recursive) return adder.pinning.Flush(ctx) } diff --git a/go.mod b/go.mod index a9634a22be5..f90f9a1473f 100644 --- a/go.mod +++ b/go.mod @@ -112,6 +112,8 @@ require ( golang.org/x/sys v0.4.0 ) +replace github.com/ipfs/go-ipfs-pinner => github.com/MichaelMure/go-ipfs-pinner v0.0.0-20230116161927-3b0d257e2a6c + require ( github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96 // indirect github.com/Kubuxu/go-os-helper v0.0.1 // indirect diff --git a/go.sum b/go.sum index 5a89b69af2d..8259ca2e83c 100644 --- a/go.sum +++ b/go.sum @@ -51,6 +51,8 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= github.com/Kubuxu/go-os-helper v0.0.1 h1:EJiD2VUQyh5A9hWJLmc6iWg6yIcJ7jpBcwC8GMGXfDk= github.com/Kubuxu/go-os-helper v0.0.1/go.mod h1:N8B+I7vPCT80IcP58r50u4+gEEcsZETFUpAzWW2ep1Y= +github.com/MichaelMure/go-ipfs-pinner v0.0.0-20230116161927-3b0d257e2a6c h1:8PKS8S5ryc67cid6E9orlFDNUz2x/Tv8zyUBXaCaO3Y= +github.com/MichaelMure/go-ipfs-pinner v0.0.0-20230116161927-3b0d257e2a6c/go.mod h1:Mk3EnQbiM93fRnoedoPky3KjjmwFLddW7OhbLrQ7jow= github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= @@ -553,8 +555,6 @@ 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-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= From 24809d230d31ccfff91853959fa3aaa403d73ab9 Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Wed, 22 Feb 2023 15:57:55 +0100 Subject: [PATCH 2/3] chore: bump github.com/ipfs/go-ipfs-pinner --- docs/examples/kubo-as-a-library/go.mod | 2 +- docs/examples/kubo-as-a-library/go.sum | 4 ++-- go.mod | 4 +--- go.sum | 4 ++-- 4 files changed, 6 insertions(+), 8 deletions(-) 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 f90f9a1473f..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 @@ -112,8 +112,6 @@ require ( golang.org/x/sys v0.4.0 ) -replace github.com/ipfs/go-ipfs-pinner => github.com/MichaelMure/go-ipfs-pinner v0.0.0-20230116161927-3b0d257e2a6c - require ( github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96 // indirect github.com/Kubuxu/go-os-helper v0.0.1 // indirect diff --git a/go.sum b/go.sum index 8259ca2e83c..5b8cf6d46a2 100644 --- a/go.sum +++ b/go.sum @@ -51,8 +51,6 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= github.com/Kubuxu/go-os-helper v0.0.1 h1:EJiD2VUQyh5A9hWJLmc6iWg6yIcJ7jpBcwC8GMGXfDk= github.com/Kubuxu/go-os-helper v0.0.1/go.mod h1:N8B+I7vPCT80IcP58r50u4+gEEcsZETFUpAzWW2ep1Y= -github.com/MichaelMure/go-ipfs-pinner v0.0.0-20230116161927-3b0d257e2a6c h1:8PKS8S5ryc67cid6E9orlFDNUz2x/Tv8zyUBXaCaO3Y= -github.com/MichaelMure/go-ipfs-pinner v0.0.0-20230116161927-3b0d257e2a6c/go.mod h1:Mk3EnQbiM93fRnoedoPky3KjjmwFLddW7OhbLrQ7jow= github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE= github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU= github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= @@ -555,6 +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.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= From 3c14130d1f6930432148ee019cd91bc7c557983f Mon Sep 17 00:00:00 2001 From: Henrique Dias Date: Wed, 22 Feb 2023 16:01:40 +0100 Subject: [PATCH 3/3] fix: check for error --- core/coreapi/block.go | 4 +++- core/coreapi/dag.go | 8 ++++++-- core/coreapi/object.go | 5 ++++- core/coreunix/add.go | 6 +++++- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/core/coreapi/block.go b/core/coreapi/block.go index 84bd47bdd1d..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(ctx, 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 06c67d5bd31..b352a2d3f46 100644 --- a/core/coreapi/dag.go +++ b/core/coreapi/dag.go @@ -30,7 +30,9 @@ func (adder *pinningAdder) Add(ctx context.Context, nd ipld.Node) error { return err } - adder.pinning.PinWithMode(ctx, nd.Cid(), pin.Recursive) + if err := adder.pinning.PinWithMode(ctx, nd.Cid(), pin.Recursive); err != nil { + return err + } return adder.pinning.Flush(ctx) } @@ -49,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(ctx, 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 34000a1e112..4b509c78210 100644 --- a/core/coreapi/object.go +++ b/core/coreapi/object.go @@ -133,7 +133,10 @@ func (api *ObjectAPI) Put(ctx context.Context, src io.Reader, opts ...caopts.Obj } if options.Pin { - api.pinning.PinWithMode(ctx, 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 5ba6569f9b0..d2c4c3dff43 100644 --- a/core/coreunix/add.go +++ b/core/coreunix/add.go @@ -186,7 +186,11 @@ func (adder *Adder) PinRoot(ctx context.Context, root ipld.Node) error { adder.tempRoot = rnk } - adder.pinning.PinWithMode(ctx, rnk, pin.Recursive) + err = adder.pinning.PinWithMode(ctx, rnk, pin.Recursive) + if err != nil { + return err + } + return adder.pinning.Flush(ctx) }