diff options
Diffstat (limited to 'src/db.erl')
-rw-r--r-- | src/db.erl | 10 |
1 files changed, 8 insertions, 2 deletions
@@ -9,6 +9,7 @@ -export([add/4, add/2, add_entryhash/2, add_index/2, set_treesize/1, size/0]). -export([get_by_index/1, get_by_indices/3, get_by_leaf_hash/1]). -export([get_by_entry_hash/1, entry_for_leafhash/1, leafhash_for_index/1]). +-export([leafhash_for_indices/2, indexsize/0]). %% gen_server callbacks. -export([init/1, handle_call/3, terminate/2, handle_cast/2, handle_info/2, code_change/3]). @@ -19,6 +20,9 @@ size() -> binary_to_integer(atomic:readfile(treesize_path())). +indexsize() -> + index:indexsize(index_path()). + init(_Args) -> {ok, []}. @@ -159,11 +163,13 @@ handle_call({add, {LeafHash, EntryHash, Data, Index}}, _From, State) -> ok = perm:ensurefile(indexforhash_root_path(), LeafHash, integer_to_binary(Index)), ok = index:add(index_path(), Index, LeafHash), - ok = atomic:replacefile(treesize_path(), integer_to_list(Index+1)), + ok = atomic:replacefile(treesize_path(), integer_to_binary(Index+1)), {reply, ok, State}; handle_call({add, {LeafHash, Data}}, _From, State) -> + lager:debug("add leafhash ~p", [LeafHash]), ok = perm:ensurefile(entry_root_path(), LeafHash, Data), + lager:debug("leafhash ~p added", [LeafHash]), {reply, ok, State}; handle_call({add_entryhash, {LeafHash, EntryHash}}, _From, State) -> @@ -177,7 +183,7 @@ handle_call({add_index, {LeafHash, Index}}, _From, State) -> {reply, ok, State}; handle_call({set_treesize, Size}, _From, State) -> - ok = atomic:replacefile(treesize_path(), integer_to_list(Size)), + ok = atomic:replacefile(treesize_path(), integer_to_binary(Size)), {reply, ok, State}; handle_call({get_by_indices, {Start, End, _Sorted}}, _From, State) -> |