diff options
-rw-r--r-- | src/index.erl | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/index.erl b/src/index.erl index 5382485..5fd468b 100644 --- a/src/index.erl +++ b/src/index.erl @@ -7,6 +7,10 @@ %% that stores an ordered list of fixed-size entries. Entries can be %% added at the end and are retrieved by index. The list can also be %% truncated. +%% +%% Writes(add, truncate, addlast) need to be serialized. + +%% TODO: Checksums -module(index). -export([get/2, add/3, addlast/2, truncate/2]). @@ -28,7 +32,8 @@ add(Basepath, Index, Entry) when is_binary(Entry), size(Entry) == ?ENTRYSIZE -> end, EntryText = hex:bin_to_hexstr(Entry) ++ "\n", ok = file:write(File, EntryText), - file:close(File); + ok = file:close(File), + util:fsync([Basepath, filename:dirname(Basepath)]); {error, Error} -> util:exit_with_error(Error, writefile, "Error opening file for writing") @@ -39,7 +44,8 @@ truncate(Basepath, Index) -> {ok, File} -> {ok, _Position} = file:position(File, Index * ?ENTRYSIZEINFILE), ok = file:truncate(File), - file:close(File); + ok = file:close(File), + util:fsync([Basepath, filename:dirname(Basepath)]); {error, Error} -> util:exit_with_error(Error, writefile, "Error opening file for writing") |