diff options
Diffstat (limited to 'lib/stdlib/src/ets.erl')
-rw-r--r-- | lib/stdlib/src/ets.erl | 61 |
1 files changed, 41 insertions, 20 deletions
diff --git a/lib/stdlib/src/ets.erl b/lib/stdlib/src/ets.erl index 77c8029f59..f05bfd12a7 100644 --- a/lib/stdlib/src/ets.erl +++ b/lib/stdlib/src/ets.erl @@ -719,7 +719,7 @@ tab2file(Tab, File) -> tab2file(Tab, File, Options) -> try {ok, FtOptions} = parse_ft_options(Options), - file:delete(File), + _ = file:delete(File), case file:read_file_info(File) of {error, enoent} -> ok; _ -> throw(eaccess) @@ -750,14 +750,18 @@ tab2file(Tab, File, Options) -> {fun(Oldstate,Termlist) -> {NewState,BinList} = md5terms(Oldstate,Termlist), - disk_log:blog_terms(Name,BinList), - NewState + case disk_log:blog_terms(Name,BinList) of + ok -> NewState; + {error, Reason2} -> throw(Reason2) + end end, erlang:md5_init()}; false -> {fun(_,Termlist) -> - disk_log:log_terms(Name,Termlist), - true + case disk_log:log_terms(Name,Termlist) of + ok -> true; + {error, Reason2} -> throw(Reason2) + end end, true} end, @@ -792,16 +796,16 @@ tab2file(Tab, File, Options) -> disk_log:close(Name) catch throw:TReason -> - disk_log:close(Name), - file:delete(File), + _ = disk_log:close(Name), + _ = file:delete(File), throw(TReason); exit:ExReason -> - disk_log:close(Name), - file:delete(File), + _ = disk_log:close(Name), + _ = file:delete(File), exit(ExReason); error:ErReason -> - disk_log:close(Name), - file:delete(File), + _ = disk_log:close(Name), + _ = file:delete(File), erlang:raise(error,ErReason,erlang:get_stacktrace()) end catch @@ -892,25 +896,32 @@ file2tab(File, Opts) -> try {ok,Verify,TabArg} = parse_f2t_opts(Opts,false,[]), Name = make_ref(), - {ok, Major, Minor, FtOptions, MD5State, FullHeader, DLContext} = + {ok, Name} = case disk_log:open([{name, Name}, {file, File}, {mode, read_only}]) of {ok, Name} -> - get_header_data(Name,Verify); + {ok, Name}; {repaired, Name, _,_} -> %Uh? cannot happen? case Verify of true -> - disk_log:close(Name), + _ = disk_log:close(Name), throw(badfile); false -> - get_header_data(Name,Verify) + {ok, Name} end; {error, Other1} -> throw({read_error, Other1}); Other2 -> throw(Other2) end, + {ok, Major, Minor, FtOptions, MD5State, FullHeader, DLContext} = + try get_header_data(Name, Verify) + catch + badfile -> + _ = disk_log:close(Name), + throw(badfile) + end, try if Major > ?MAJOR_F2T_VERSION -> @@ -974,7 +985,7 @@ file2tab(File, Opts) -> erlang:raise(error,ErReason,erlang:get_stacktrace()) end after - disk_log:close(Name) + _ = disk_log:close(Name) end catch throw:TReason2 -> @@ -1293,20 +1304,30 @@ named_table(false) -> []. tabfile_info(File) when is_list(File) ; is_atom(File) -> try Name = make_ref(), - {ok, Major, Minor, _FtOptions, _MD5State, FullHeader, _DLContext} = + {ok, Name} = case disk_log:open([{name, Name}, {file, File}, {mode, read_only}]) of {ok, Name} -> - get_header_data(Name,false); + {ok, Name}; {repaired, Name, _,_} -> %Uh? cannot happen? - get_header_data(Name,false); + {ok, Name}; {error, Other1} -> throw({read_error, Other1}); Other2 -> throw(Other2) end, - disk_log:close(Name), + {ok, Major, Minor, _FtOptions, _MD5State, FullHeader, _DLContext} = + try get_header_data(Name, false) + catch + badfile -> + _ = disk_log:close(Name), + throw(badfile) + end, + case disk_log:close(Name) of + ok -> ok; + {error, Reason} -> throw(Reason) + end, {value, N} = lists:keysearch(name, 1, FullHeader), {value, Type} = lists:keysearch(type, 1, FullHeader), {value, P} = lists:keysearch(protection, 1, FullHeader), |