You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ko...@apache.org on 2017/03/01 16:39:23 UTC

[36/50] couch commit: updated refs/heads/2971-count-distinct to ee32cd5

Reset EOF if a partial write was possible

We can't know if one or more bytes were written by a file:write/2 call
that results in an error and so it is not correct to leave #file.eof
at its original value. In the event of error, use file:position(Fd,
eof) to find the new, true length of the file, and update #file{}
accordingly.

COUCHDB-3274


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/604edd10
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/604edd10
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/604edd10

Branch: refs/heads/2971-count-distinct
Commit: 604edd10e28e144c57826630b1d92ab41a9377b9
Parents: 3188736
Author: Robert Newson <rn...@apache.org>
Authored: Thu Jan 19 23:12:00 2017 +0000
Committer: Robert Newson <rn...@apache.org>
Committed: Thu Jan 19 23:12:36 2017 +0000

----------------------------------------------------------------------
 src/couch_file.erl | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/604edd10/src/couch_file.erl
----------------------------------------------------------------------
diff --git a/src/couch_file.erl b/src/couch_file.erl
index 7cf8b02..2623824 100644
--- a/src/couch_file.erl
+++ b/src/couch_file.erl
@@ -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) ->
@@ -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) ->
@@ -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").