diff options
author | Linus Nordberg <linus@nordu.net> | 2015-08-19 16:21:14 +0200 |
---|---|---|
committer | Linus Nordberg <linus@nordu.net> | 2015-08-19 16:21:14 +0200 |
commit | 85411c74332775b6b2dbc06f40074a26e7f6ba3e (patch) | |
tree | b9be823ce70877e0bf5c8bc12cf850a15ef166ce /src/storagedb.erl | |
parent | 85982c4033da4d54937078f8ae1d9c8fde072372 (diff) | |
parent | 329490ec8167ffe5b2bd8a390ae4d34fd8b808c0 (diff) |
Merge remote-tracking branch 'refs/remotes/map/storagegc'
Diffstat (limited to 'src/storagedb.erl')
-rw-r--r-- | src/storagedb.erl | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/storagedb.erl b/src/storagedb.erl index c94a13e..d781033 100644 --- a/src/storagedb.erl +++ b/src/storagedb.erl @@ -7,7 +7,7 @@ -behaviour(gen_server). %% API -export([start_link/0, stop/0]). --export([add/1, fetchnewhashes/1]). +-export([add/1, fetchnewhashes/1, lastverifiednewentry/0]). %% gen_server callbacks. -export([init/1, handle_call/3, terminate/2, handle_cast/2, handle_info/2, code_change/3]). @@ -23,6 +23,10 @@ start_link() -> stop() -> call(?MODULE, stop). +lastverifiednewentry_path() -> + {ok, Value} = application:get_env(plop, lastverifiednewentry_path), + Value. + %%%%%%%%%%%%%%%%%%%% %% Public API. @@ -34,6 +38,17 @@ fetchnewhashes(Index) -> index:getrange(newentries_path(), Index, Size - 1) end. +lastverifiednewentry() -> + case atomic:readfile(lastverifiednewentry_path()) of + noentry -> + {0, none}; + Contents -> + {struct, PropList} = mochijson2:decode(Contents), + Index = proplists:get_value(<<"index">>, PropList), + Hash = proplists:get_value(<<"hash">>, PropList), + {Index, mochihex:to_bin(binary_to_list(Hash))} + end. + -spec add(binary()) -> ok. add(LeafHash) -> ok = call(?MODULE, {add_nosync, LeafHash}), |