summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/rabbit_file.erl17
1 files changed, 17 insertions, 0 deletions
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