summaryrefslogtreecommitdiff
path: root/src/db.erl
diff options
context:
space:
mode:
authorMagnus Ahltorp <map@kth.se>2014-10-19 01:37:29 +0200
committerMagnus Ahltorp <map@kth.se>2014-10-19 01:37:29 +0200
commitd58b69c5d37ecf484da2bdd128d872d2aabb2e16 (patch)
treee17e63dabe6ef9a177719f751b81e308c5e3d71c /src/db.erl
parent159e0ab3f42ff0a8f8475d25335d7862b8c150bb (diff)
db:get_by_leaf_hash(): Return notfound instead of crashing when no entry could be found.
db:get_by_entry_hash(): Don't fetch index, isn't used and might not exist. index:add(): Allow writes at exiting indicies.
Diffstat (limited to 'src/db.erl')
-rw-r--r--src/db.erl25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/db.erl b/src/db.erl
index 4bcdc1c..aa10937 100644
--- a/src/db.erl
+++ b/src/db.erl
@@ -104,7 +104,12 @@ entry_for_leafhash(LeafHash) ->
perm:readfile(entry_root_path(), LeafHash).
index_for_leafhash(LeafHash) ->
- binary_to_integer(perm:readfile(indexforhash_root_path(), LeafHash)).
+ case perm:readfile(indexforhash_root_path(), LeafHash) of
+ noentry ->
+ noentry;
+ Index ->
+ binary_to_integer(Index)
+ end.
leafhash_for_index(Index) ->
index:get(index_path(), Index).
@@ -149,9 +154,17 @@ handle_call({get_by_index, Index}, _From, State) ->
{reply, R, State};
handle_call({get_by_leaf_hash, LeafHash}, _From, State) ->
- Entry = entry_for_leafhash(LeafHash),
- Index = index_for_leafhash(LeafHash),
- R = {Index, LeafHash, Entry},
+ R = case entry_for_leafhash(LeafHash) of
+ noentry ->
+ notfound;
+ Entry ->
+ case index_for_leafhash(LeafHash) of
+ noentry ->
+ notfound;
+ Index ->
+ {Index, LeafHash, Entry}
+ end
+ end,
{reply, R, State};
handle_call({get_by_entry_hash, EntryHash}, _From, State) ->
@@ -160,7 +173,7 @@ handle_call({get_by_entry_hash, EntryHash}, _From, State) ->
notfound;
LeafHash ->
Entry = entry_for_leafhash(LeafHash),
- Index = index_for_leafhash(LeafHash),
- {Index, LeafHash, Entry}
+ %% Don't fetch index, isn't used and might not exist
+ {notfetched, LeafHash, Entry}
end,
{reply, R, State}.