diff options
author | Luke Bakken <luke@bakken.io> | 2021-12-18 08:30:54 -0800 |
---|---|---|
committer | mergify-bot <noreply@mergify.com> | 2021-12-19 04:31:35 +0000 |
commit | 0684155cdb97742705e09cfd5dcb3f3af09214b6 (patch) | |
tree | df3201d239e09072bfea5545e90243e2fa4d54f5 | |
parent | ac4bc0ae3974a4cbcc2d4b679633b779ea53b52f (diff) | |
download | rabbitmq-server-git-0684155cdb97742705e09cfd5dcb3f3af09214b6.tar.gz |
read term file using with_handle/1mergify/bp/v3.8.x/pr-3917
(cherry picked from commit 365de60c248407fef6261c5eddd6eb235bdf5da8)
(cherry picked from commit 5db59019cb8be0892e6ab7e576726b021afea7ad)
-rw-r--r-- | deps/rabbit/src/rabbit_file.erl | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/deps/rabbit/src/rabbit_file.erl b/deps/rabbit/src/rabbit_file.erl index 6f2ae5e6a5..2060c354c5 100644 --- a/deps/rabbit/src/rabbit_file.erl +++ b/deps/rabbit/src/rabbit_file.erl @@ -90,19 +90,22 @@ read_file_info(File) -> read_term_file(File) -> try - {ok, FInfo} = file:read_file_info(File, [raw]), - {ok, Fd} = file:open(File, [read, raw, binary]), - try - {ok, Data} = file:read(Fd, FInfo#file_info.size), - {ok, Tokens, _} = erl_scan:string(binary_to_list(Data)), - TokenGroups = group_tokens(Tokens), - {ok, [begin - {ok, Term} = erl_parse:parse_term(Tokens1), - Term - end || Tokens1 <- TokenGroups]} - after - ok = file:close(Fd) - end + F = fun() -> + {ok, FInfo} = file:read_file_info(File, [raw]), + {ok, Fd} = file:open(File, [read, raw, binary]), + try + file:read(Fd, FInfo#file_info.size) + after + file:close(Fd) + end + end, + {ok, Data} = with_handle(F), + {ok, Tokens, _} = erl_scan:string(binary_to_list(Data)), + TokenGroups = group_tokens(Tokens), + {ok, [begin + {ok, Term} = erl_parse:parse_term(Tokens1), + Term + end || Tokens1 <- TokenGroups]} catch error:{badmatch, Error} -> Error end. |