Unverified Commit 74024d0b authored by Steven Allen's avatar Steven Allen Committed by GitHub

Merge pull request #16 from ipfs/fix/get-size-not-found

make arccache.GetSize return ErrNotFound when not found
parents 31243bdd 79b1edf4
......@@ -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 {
......
......@@ -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")
}
......@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment