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

Commit

Permalink
Merge pull request #16 from ipfs/fix/get-size-not-found
Browse files Browse the repository at this point in the history
make arccache.GetSize return ErrNotFound when not found
  • Loading branch information
Stebalien authored Oct 4, 2018
2 parents 31243bd + 79b1edf commit 74024d0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
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

0 comments on commit 74024d0

Please sign in to comment.