couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject couch commit: updated refs/heads/master to 604edd1
Date Fri, 20 Jan 2017 00:14:45 GMT
Repository: couchdb-couch
Updated Branches:
  refs/heads/master 3188736c6 -> 604edd10e


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/master
Commit: 604edd10e28e144c57826630b1d92ab41a9377b9
Parents: 3188736
Author: Robert Newson <rnewson@apache.org>
Authored: Thu Jan 19 23:12:00 2017 +0000
Committer: Robert Newson <rnewson@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").
 


Mime
View raw message