Skip to content
This repository has been archived by the owner on May 25, 2021. It is now read-only.

Reset EOF if a partial write was possible #222

Merged
merged 1 commit into from Jan 20, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/couch_file.erl
Expand Up @@ -476,7 +476,7 @@ handle_call({append_bin, Bin}, _From, #file{fd = Fd, eof = Pos} = File) ->
ok ->
{reply, {ok, Pos, Size}, File#file{eof = Pos + Size}};
Error ->
{reply, Error, File}
{reply, Error, reset_eof(File)}
end;

handle_call({write_header, Bin}, _From, #file{fd = Fd, eof = Pos} = File) ->
Expand All @@ -492,7 +492,7 @@ handle_call({write_header, Bin}, _From, #file{fd = Fd, eof = Pos} = File) ->
ok ->
{reply, ok, File#file{eof = Pos + iolist_size(FinalBin)}};
Error ->
{reply, Error, File}
{reply, Error, reset_eof(File)}
end;

handle_call(find_header, _From, #file{fd = Fd, eof = Pos} = File) ->
Expand Down Expand Up @@ -738,6 +738,11 @@ get_pread_limit() ->
_ -> infinity
end.

%% in event of a partially successful write.
reset_eof(#file{} = File) ->
{ok, Eof} = file:position(File#file.fd, eof),
File#file{eof = Eof}.

-ifdef(TEST).
-include_lib("couch/include/couch_eunit.hrl").

Expand Down