From 809a3ba07cac6527a967a180cdb45bf96dfede16 Mon Sep 17 00:00:00 2001 From: whyrusleeping Date: Thu, 2 Jul 2020 16:48:14 -0700 Subject: [PATCH] check underlying datastore for objects before putting to bufbstore --- lib/bufbstore/buf_bstore.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/bufbstore/buf_bstore.go b/lib/bufbstore/buf_bstore.go index e1aad94df..4b430828b 100644 --- a/lib/bufbstore/buf_bstore.go +++ b/lib/bufbstore/buf_bstore.go @@ -108,6 +108,15 @@ func (bs *BufferedBS) GetSize(c cid.Cid) (int, error) { } func (bs *BufferedBS) Put(blk block.Block) error { + has, err := bs.read.Has(blk.Cid()) + if err != nil { + return err + } + + if has { + return nil + } + return bs.write.Put(blk) }