diff options
author | Sverker Eriksson <[email protected]> | 2015-05-21 20:01:45 +0200 |
---|---|---|
committer | Sverker Eriksson <[email protected]> | 2015-05-21 20:01:45 +0200 |
commit | 31d663b47a20f2fff9b6a35f91d1ca2b28ce8b9f (patch) | |
tree | 355aa4576280d6c126d242a6ffe2de1e7a6f364e /lib/stdlib/src | |
parent | db7446a0235f5379ed230a51cc1d55475549f36b (diff) | |
parent | c6d38c93b80395ee9dbe65d6dd6751254402ea21 (diff) | |
download | otp-31d663b47a20f2fff9b6a35f91d1ca2b28ce8b9f.tar.gz otp-31d663b47a20f2fff9b6a35f91d1ca2b28ce8b9f.tar.bz2 otp-31d663b47a20f2fff9b6a35f91d1ca2b28ce8b9f.zip |
Merge branch 'sverk/ets-tab2file-syn/OTP-12737'
* sverk/ets-tab2file-syn/OTP-12737:
stdlib: Add 'sync' option to ets:tab2file/3
Diffstat (limited to 'lib/stdlib/src')
-rw-r--r-- | lib/stdlib/src/ets.erl | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/lib/stdlib/src/ets.erl b/lib/stdlib/src/ets.erl index 1df069755d..0e2d59d0c3 100644 --- a/lib/stdlib/src/ets.erl +++ b/lib/stdlib/src/ets.erl @@ -739,7 +739,8 @@ do_filter(Tab, Key, F, A, Ack) -> -record(filetab_options, { object_count = false :: boolean(), - md5sum = false :: boolean() + md5sum = false :: boolean(), + sync = false :: boolean() }). -spec tab2file(Tab, Filename) -> 'ok' | {'error', Reason} when @@ -754,7 +755,7 @@ tab2file(Tab, File) -> Tab :: tab(), Filename :: file:name(), Options :: [Option], - Option :: {'extended_info', [ExtInfo]}, + Option :: {'extended_info', [ExtInfo]} | {'sync', boolean()}, ExtInfo :: 'md5sum' | 'object_count', Reason :: term(). @@ -835,6 +836,15 @@ tab2file(Tab, File, Options) -> List -> LogFun(NewState1,[['$end_of_table',List]]) end, + case FtOptions#filetab_options.sync of + true -> + case disk_log:sync(Name) of + ok -> ok; + {error, Reason2} -> throw(Reason2) + end; + false -> + ok + end, disk_log:close(Name) catch throw:TReason -> @@ -887,23 +897,24 @@ md5terms(State, [H|T]) -> {FinState, [B|TL]}. parse_ft_options(Options) when is_list(Options) -> - {Opt,Rest} = case (catch lists:keytake(extended_info,1,Options)) of - false -> - {[],Options}; - {value,{extended_info,L},R} when is_list(L) -> - {L,R} - end, - case Rest of - [] -> - parse_ft_info_options(#filetab_options{}, Opt); - Other -> - throw({unknown_option, Other}) - end; -parse_ft_options(Malformed) -> + {ok, parse_ft_options(Options, #filetab_options{}, false)}. + +parse_ft_options([], FtOpt, _) -> + FtOpt; +parse_ft_options([{sync,true} | Rest], FtOpt, EI) -> + parse_ft_options(Rest, FtOpt#filetab_options{sync = true}, EI); +parse_ft_options([{sync,false} | Rest], FtOpt, EI) -> + parse_ft_options(Rest, FtOpt, EI); +parse_ft_options([{extended_info,L} | Rest], FtOpt0, false) -> + FtOpt1 = parse_ft_info_options(FtOpt0, L), + parse_ft_options(Rest, FtOpt1, true); +parse_ft_options([Other | _], _, _) -> + throw({unknown_option, Other}); +parse_ft_options(Malformed, _, _) -> throw({malformed_option, Malformed}). parse_ft_info_options(FtOpt,[]) -> - {ok,FtOpt}; + FtOpt; parse_ft_info_options(FtOpt,[object_count | T]) -> parse_ft_info_options(FtOpt#filetab_options{object_count = true}, T); parse_ft_info_options(FtOpt,[md5sum | T]) -> |