Skip to content
This repository has been archived by the owner on Jun 19, 2023. It is now read-only.

make arccache.GetSize return ErrNotFound when not found #16

Merged
merged 1 commit into from
Oct 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions arc_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,11 @@ func (b *arccache) Has(k cid.Cid) (bool, error) {
}

func (b *arccache) GetSize(k cid.Cid) (int, error) {
if _, blockSize, ok := b.hasCached(k); ok {
return blockSize, nil
if has, blockSize, ok := b.hasCached(k); ok {
if has {
return blockSize, nil
}
return -1, ErrNotFound
}
blockSize, err := b.blockstore.GetSize(k)
if err == ErrNotFound {
Expand Down
5 changes: 2 additions & 3 deletions arc_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func TestGetFillsCache(t *testing.T) {
if has, err := arc.Has(exampleBlock.Cid()); has || err != nil {
t.Fatal("has was true but there is no such block")
}
if blockSize, err := arc.GetSize(exampleBlock.Cid()); blockSize > -1 || err != nil {
if _, err := arc.GetSize(exampleBlock.Cid()); err != ErrNotFound {
t.Fatal("getsize was true but there is no such block")
}

Expand Down Expand Up @@ -203,12 +203,11 @@ func TestGetSizeMissingZeroSizeBlock(t *testing.T) {
arc.Get(missingBlock.Cid())

trap("has hit datastore", cd, t)
if blockSize, err := arc.GetSize(missingBlock.Cid()); blockSize != -1 || err != nil {
if _, err := arc.GetSize(missingBlock.Cid()); err != ErrNotFound {
t.Fatal("getsize returned invalid result")
}
}


func TestDifferentKeyObjectsWork(t *testing.T) {
arc, bs, cd := createStores(t)

Expand Down