diff --git a/filestore.go b/filestore.go index 6382a6d..2372a60 100644 --- a/filestore.go +++ b/filestore.go @@ -16,6 +16,7 @@ import ( dsq "github.com/ipfs/go-datastore/query" blockstore "github.com/ipfs/go-ipfs-blockstore" posinfo "github.com/ipfs/go-ipfs-posinfo" + ipld "github.com/ipfs/go-ipld-format" logging "github.com/ipfs/go-log" ) @@ -117,7 +118,7 @@ func (f *Filestore) AllKeysChan(ctx context.Context) (<-chan cid.Cid, error) { // ErrNotFound when the block is not stored. func (f *Filestore) DeleteBlock(ctx context.Context, c cid.Cid) error { err1 := f.bs.DeleteBlock(ctx, c) - if err1 != nil && err1 != blockstore.ErrNotFound { + if err1 != nil && !ipld.IsNotFound(err1) { return err1 } @@ -125,45 +126,38 @@ func (f *Filestore) DeleteBlock(ctx context.Context, c cid.Cid) error { // if we successfully removed something from the blockstore, but the // filestore didnt have it, return success - switch err2 { - case nil: - return nil - case blockstore.ErrNotFound: - if err1 == blockstore.ErrNotFound { - return blockstore.ErrNotFound + if ipld.IsNotFound(err2) { + if ipld.IsNotFound(err1) { + return err1 } + // being here means err1 was nil and err2 NotFound. return nil - default: - return err2 } + + return err2 } // Get retrieves the block with the given Cid. It may return // ErrNotFound when the block is not stored. func (f *Filestore) Get(ctx context.Context, c cid.Cid) (blocks.Block, error) { blk, err := f.bs.Get(ctx, c) - switch err { - case nil: - return blk, nil - case blockstore.ErrNotFound: + if ipld.IsNotFound(err) { return f.fm.Get(ctx, c) - default: - return nil, err } + return blk, err } // GetSize returns the size of the requested block. It may return ErrNotFound // when the block is not stored. func (f *Filestore) GetSize(ctx context.Context, c cid.Cid) (int, error) { size, err := f.bs.GetSize(ctx, c) - switch err { - case nil: - return size, nil - case blockstore.ErrNotFound: - return f.fm.GetSize(ctx, c) - default: + if err != nil { + if ipld.IsNotFound(err) { + return f.fm.GetSize(ctx, c) + } return -1, err } + return size, nil } // Has returns true if the block with the given Cid is diff --git a/filestore_test.go b/filestore_test.go index e3b822c..8117a23 100644 --- a/filestore_test.go +++ b/filestore_test.go @@ -13,6 +13,7 @@ import ( ds "github.com/ipfs/go-datastore" blockstore "github.com/ipfs/go-ipfs-blockstore" posinfo "github.com/ipfs/go-ipfs-posinfo" + ipld "github.com/ipfs/go-ipld-format" ) var bg = context.Background() @@ -148,7 +149,7 @@ func TestDeletes(t *testing.T) { deleted := make(map[string]bool) for _, c := range todelete { _, err := fs.Get(bg, c) - if err != blockstore.ErrNotFound { + if !ipld.IsNotFound(err) { t.Fatal("expected blockstore not found error") } deleted[c.KeyString()] = true diff --git a/fsrefstore.go b/fsrefstore.go index 9eb2b43..2cb41d0 100644 --- a/fsrefstore.go +++ b/fsrefstore.go @@ -16,9 +16,9 @@ import ( ds "github.com/ipfs/go-datastore" dsns "github.com/ipfs/go-datastore/namespace" dsq "github.com/ipfs/go-datastore/query" - blockstore "github.com/ipfs/go-ipfs-blockstore" dshelp "github.com/ipfs/go-ipfs-ds-help" posinfo "github.com/ipfs/go-ipfs-posinfo" + ipld "github.com/ipfs/go-ipld-format" mh "github.com/multiformats/go-multihash" ) @@ -103,7 +103,7 @@ func (f *FileManager) AllKeysChan(ctx context.Context) (<-chan cid.Cid, error) { func (f *FileManager) DeleteBlock(ctx context.Context, c cid.Cid) error { err := f.ds.Delete(ctx, dshelp.MultihashToDsKey(c.Hash())) if err == ds.ErrNotFound { - return blockstore.ErrNotFound + return ipld.ErrNotFound{c} } return err } @@ -148,7 +148,7 @@ func (f *FileManager) getDataObj(ctx context.Context, m mh.Multihash) (*pb.DataO o, err := f.ds.Get(ctx, dshelp.MultihashToDsKey(m)) switch err { case ds.ErrNotFound: - return nil, blockstore.ErrNotFound + return nil, ipld.ErrNotFound{Cid: cid.NewCidV1(cid.Raw, m)} case nil: // default: diff --git a/go.mod b/go.mod index 5ee071b..30c8bcc 100644 --- a/go.mod +++ b/go.mod @@ -7,10 +7,11 @@ require ( github.com/ipfs/go-block-format v0.0.3 github.com/ipfs/go-cid v0.0.7 github.com/ipfs/go-datastore v0.5.0 - github.com/ipfs/go-ipfs-blockstore v1.1.1 + github.com/ipfs/go-ipfs-blockstore v1.1.3-0.20220302142350-af197de1c3da github.com/ipfs/go-ipfs-ds-help v1.1.0 github.com/ipfs/go-ipfs-posinfo v0.0.1 + github.com/ipfs/go-ipld-format v0.2.1-0.20220302134852-d02e0e18fc65 github.com/ipfs/go-log v1.0.5 - github.com/ipfs/go-merkledag v0.5.1 + github.com/ipfs/go-merkledag v0.5.2-0.20220302145706-4c7f7bfbe598 github.com/multiformats/go-multihash v0.0.15 ) diff --git a/go.sum b/go.sum index 8f181a5..c18013e 100644 --- a/go.sum +++ b/go.sum @@ -238,13 +238,13 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt github.com/influxdata/influxdb1-client v0.0.0-20191209144304-8bf82d3c094d/go.mod h1:qj24IKcXYK6Iy9ceXlo3Tc+vtHo9lIhSX5JddghvEPo= github.com/ipfs/bbloom v0.0.4 h1:Gi+8EGJ2y5qiD5FbsbpX/TMNcJw8gSqr7eyjHa4Fhvs= github.com/ipfs/bbloom v0.0.4/go.mod h1:cS9YprKXpoZ9lT0n/Mw/a6/aFV6DTjTLYHeA+gyqMG0= -github.com/ipfs/go-bitswap v0.5.1 h1:721YAEDBnLIrvcIMkCHCdqp34hA8jwL9yKMkyJpSpco= -github.com/ipfs/go-bitswap v0.5.1/go.mod h1:P+ckC87ri1xFLvk74NlXdP0Kj9RmWAh4+H78sC6Qopo= +github.com/ipfs/go-bitswap v0.5.2-0.20220302142610-595ae6937936 h1:1Ps0PF7jFKqO8/QwHaFvwCpQ0AITuYSbOI50gts3OiM= +github.com/ipfs/go-bitswap v0.5.2-0.20220302142610-595ae6937936/go.mod h1:Ro9XYuNUQxtx/YIZm+OA5mEnADStr5fyowhSUIgZtaU= github.com/ipfs/go-block-format v0.0.2/go.mod h1:AWR46JfpcObNfg3ok2JHDUfdiHRgWhJgCQF+KIgOPJY= github.com/ipfs/go-block-format v0.0.3 h1:r8t66QstRp/pd/or4dpnbVfXT5Gt7lOqRvC+/dDTpMc= github.com/ipfs/go-block-format v0.0.3/go.mod h1:4LmD4ZUw0mhO+JSKdpWwrzATiEfM7WWgQ8H5l6P8MVk= -github.com/ipfs/go-blockservice v0.2.1 h1:NJ4j/cwEfIg60rzAWcCIxRtOwbf6ZPK49MewNxObCPQ= -github.com/ipfs/go-blockservice v0.2.1/go.mod h1:k6SiwmgyYgs4M/qt+ww6amPeUH9EISLRBnvUurKJhi8= +github.com/ipfs/go-blockservice v0.2.2-0.20220302144055-931fbecb724e h1:Nqyg2HAa7lS19g6N7UTpbiJQFHKSO7yp+DvcqY4iBFk= +github.com/ipfs/go-blockservice v0.2.2-0.20220302144055-931fbecb724e/go.mod h1:0rezJNcrjTA32XEEXiV/DQAztHZrVduLb7GiktRq6lg= github.com/ipfs/go-cid v0.0.1/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM= github.com/ipfs/go-cid v0.0.2/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM= github.com/ipfs/go-cid v0.0.3/go.mod h1:GHWU/WuQdMPmIosc4Yn1bcCT7dSeX4lBafM7iqUPQvM= @@ -271,8 +271,8 @@ github.com/ipfs/go-ds-leveldb v0.0.1/go.mod h1:feO8V3kubwsEF22n0YRQCffeb79OOYIyk github.com/ipfs/go-ds-leveldb v0.4.1/go.mod h1:jpbku/YqBSsBc1qgME8BkWS4AxzF2cEu1Ii2r79Hh9s= github.com/ipfs/go-ds-leveldb v0.4.2/go.mod h1:jpbku/YqBSsBc1qgME8BkWS4AxzF2cEu1Ii2r79Hh9s= github.com/ipfs/go-ipfs-blockstore v0.2.1/go.mod h1:jGesd8EtCM3/zPgx+qr0/feTXGUeRai6adgwC+Q+JvE= -github.com/ipfs/go-ipfs-blockstore v1.1.1 h1:a4koS3l+Fzl43LAAn51/N+Yn4AjCX4AGvoZLqqkrD/g= -github.com/ipfs/go-ipfs-blockstore v1.1.1/go.mod h1:w51tNR9y5+QXB0wkNcHt4O2aSZjTdqaEWaQdSxEyUOY= +github.com/ipfs/go-ipfs-blockstore v1.1.3-0.20220302142350-af197de1c3da h1:/TU6rnYvsuKOwqpWxQXtO/K1Uj7IYY2GFE0WUr4Gh2Y= +github.com/ipfs/go-ipfs-blockstore v1.1.3-0.20220302142350-af197de1c3da/go.mod h1:dFOiy6XAxbK5x1Jvx7OAO1rQsrcyHxaXdTLWN085QoE= github.com/ipfs/go-ipfs-blocksutil v0.0.1 h1:Eh/H4pc1hsvhzsQoMEP3Bke/aW5P5rVM1IWFJMcGIPQ= github.com/ipfs/go-ipfs-blocksutil v0.0.1/go.mod h1:Yq4M86uIOmxmGPUHv/uI7uKqZNtLb449gwKqXjIsnRk= github.com/ipfs/go-ipfs-delay v0.0.0-20181109222059-70721b86a9a8/go.mod h1:8SP1YXK1M1kXuc4KJZINY3TQQ03J2rwBG9QfXmbRPrw= @@ -283,8 +283,9 @@ github.com/ipfs/go-ipfs-ds-help v1.1.0 h1:yLE2w9RAsl31LtfMt91tRZcrx+e61O5mDxFRR9 github.com/ipfs/go-ipfs-ds-help v1.1.0/go.mod h1:YR5+6EaebOhfcqVCyqemItCLthrpVNot+rsOU/5IatU= github.com/ipfs/go-ipfs-exchange-interface v0.1.0 h1:TiMekCrOGQuWYtZO3mf4YJXDIdNgnKWZ9IE3fGlnWfo= github.com/ipfs/go-ipfs-exchange-interface v0.1.0/go.mod h1:ych7WPlyHqFvCi/uQI48zLZuAWVP5iTQPXEfVaw5WEI= -github.com/ipfs/go-ipfs-exchange-offline v0.1.1 h1:mEiXWdbMN6C7vtDG21Fphx8TGCbZPpQnz/496w/PL4g= github.com/ipfs/go-ipfs-exchange-offline v0.1.1/go.mod h1:vTiBRIbzSwDD0OWm+i3xeT0mO7jG2cbJYatp3HPk5XY= +github.com/ipfs/go-ipfs-exchange-offline v0.1.2-0.20220302144615-a919970e8153 h1:GtLORXk45GpVMfhPz+IyZ9YNAe36BQ+rKZvem5Bo49Y= +github.com/ipfs/go-ipfs-exchange-offline v0.1.2-0.20220302144615-a919970e8153/go.mod h1:fjwwh1LDdR2LrZ0qYeDbWx4pgdTq+Tw48YaLBjCS2qk= 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.2 h1:e1vOOW6MuOwG2lqxcLA+wEn93i/9laCY8sXAw76jFOY= @@ -297,8 +298,9 @@ github.com/ipfs/go-ipfs-util v0.0.2/go.mod h1:CbPtkWJzjLdEcezDns2XYaehFVNXG9zrdr github.com/ipfs/go-ipld-cbor v0.0.5 h1:ovz4CHKogtG2KB/h1zUp5U0c/IzZrL435rCh5+K/5G8= github.com/ipfs/go-ipld-cbor v0.0.5/go.mod h1:BkCduEx3XBCO6t2Sfo5BaHzuok7hbhdMm9Oh8B2Ftq4= github.com/ipfs/go-ipld-format v0.0.1/go.mod h1:kyJtbkDALmFHv3QR6et67i35QzO3S0dCDnkOJhcZkms= -github.com/ipfs/go-ipld-format v0.2.0 h1:xGlJKkArkmBvowr+GMCX0FEZtkro71K1AwiKnL37mwA= github.com/ipfs/go-ipld-format v0.2.0/go.mod h1:3l3C1uKoadTPbeNfrDi+xMInYKlx2Cvg1BuydPSdzQs= +github.com/ipfs/go-ipld-format v0.2.1-0.20220302134852-d02e0e18fc65 h1:xxnD+fUS7hziDAnfrn3qsl0ql18DOjq4rwvzBTCr1iA= +github.com/ipfs/go-ipld-format v0.2.1-0.20220302134852-d02e0e18fc65/go.mod h1:co/SdBE8h99968X0hViiw1MNlh6fvxxnHpvVLnH7jSM= github.com/ipfs/go-ipld-legacy v0.1.0 h1:wxkkc4k8cnvIGIjPO0waJCe7SHEyFgl+yQdafdjGrpA= github.com/ipfs/go-ipld-legacy v0.1.0/go.mod h1:86f5P/srAmh9GcIcWQR9lfFLZPrIyyXQeVlOWeeWEuI= github.com/ipfs/go-log v0.0.1/go.mod h1:kL1d2/hzSpI0thNYjiKfjanbVNU+IIGA/WnNESY9leM= @@ -314,8 +316,8 @@ github.com/ipfs/go-log/v2 v2.1.1/go.mod h1:2v2nsGfZsvvAJz13SyFzf9ObaqwHiHxsPLEHn github.com/ipfs/go-log/v2 v2.1.3/go.mod h1:/8d0SH3Su5Ooc31QlL1WysJhvyOTDCjcCZ9Axpmri6g= github.com/ipfs/go-log/v2 v2.3.0 h1:31Re/cPqFHpsRHgyVwjWADPoF0otB1WrjTy8ZFYwEZU= github.com/ipfs/go-log/v2 v2.3.0/go.mod h1:QqGoj30OTpnKaG/LKTGTxoP2mmQtjVMEnK72gynbe/g= -github.com/ipfs/go-merkledag v0.5.1 h1:tr17GPP5XtPhvPPiWtu20tSGZiZDuTaJRXBLcr79Umk= -github.com/ipfs/go-merkledag v0.5.1/go.mod h1:cLMZXx8J08idkp5+id62iVftUQV+HlYJ3PIhDfZsjA4= +github.com/ipfs/go-merkledag v0.5.2-0.20220302145706-4c7f7bfbe598 h1:LBBmuAf+riiqOFU/YbErKaHF2kZ5ajc1cjy2puuNyLs= +github.com/ipfs/go-merkledag v0.5.2-0.20220302145706-4c7f7bfbe598/go.mod h1:nYh/2ZlUEAHL8glS7y93pPA3Ut7JHkY5fYThsrp8+RY= github.com/ipfs/go-metrics-interface v0.0.1 h1:j+cpbjYvu4R8zbleSs36gvB7jR+wsL2fGD6n0jO4kdg= github.com/ipfs/go-metrics-interface v0.0.1/go.mod h1:6s6euYU4zowdslK0GKHmqaIZ3j/b/tL7HTWtJ4VPgWY= github.com/ipfs/go-peertaskqueue v0.7.0 h1:VyO6G4sbzX80K58N60cCaHsSsypbUNs1GjO5seGNsQ0= diff --git a/util.go b/util.go index 4bd1226..125b96b 100644 --- a/util.go +++ b/util.go @@ -10,8 +10,8 @@ import ( cid "github.com/ipfs/go-cid" ds "github.com/ipfs/go-datastore" dsq "github.com/ipfs/go-datastore/query" - blockstore "github.com/ipfs/go-ipfs-blockstore" dshelp "github.com/ipfs/go-ipfs-ds-help" + ipld "github.com/ipfs/go-ipld-format" mh "github.com/multiformats/go-multihash" ) @@ -261,7 +261,7 @@ func mkListRes(m mh.Multihash, d *pb.DataObj, err error) *ListRes { status := StatusOk errorMsg := "" if err != nil { - if err == ds.ErrNotFound || err == blockstore.ErrNotFound { + if err == ds.ErrNotFound || ipld.IsNotFound(err) { status = StatusKeyNotFound } else if err, ok := err.(*CorruptReferenceError); ok { status = err.Code