From 1a89d54582628a4a42daf89dac3256e3af17099c Mon Sep 17 00:00:00 2001 From: Simon MacMullen Date: Fri, 22 Jun 2012 16:20:04 +0100 Subject: Revert the wrapper around the copy in append_file/2 --- src/rabbit_file.erl | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/rabbit_file.erl b/src/rabbit_file.erl index 5937a335..a95f8f26 100644 --- a/src/rabbit_file.erl +++ b/src/rabbit_file.erl @@ -168,7 +168,24 @@ make_binary(List) -> {error, Reason} end. +%% TODO the semantics of this function are rather odd. But see bug 25021. append_file(File, Suffix) -> + case read_file_info(File) of + {ok, FInfo} -> append_file(File, FInfo#file_info.size, Suffix); + {error, enoent} -> append_file(File, 0, Suffix); + Error -> Error + end. + +append_file(_, _, "") -> + ok; +append_file(File, 0, Suffix) -> + with_fhc_handle(fun () -> + case prim_file:open([File, Suffix], [append]) of + {ok, Fd} -> prim_file:close(Fd); + Error -> Error + end + end); +append_file(File, _, Suffix) -> case with_fhc_handle(2, fun () -> file:copy(File, {[File, Suffix], [append]}) end) of -- cgit v1.2.1