Permalink
Browse files

MB-7631 Interpret bp of 0 as empty body

By convention, in Couchstore/.couch files a body pointer of zero
indicates that the item has no body/has an empty body.

This commit makes CouchDB also have this behavior (otherwise, it will
attempt to read data from position 0 in the file when encountering a
deleted item)

Change-Id: If4229b68a2b6fc79484535619b7acfbc5055ca0e
Reviewed-on: http://review.couchbase.org/24586
Reviewed-by: Junyi Xie <junyi.couchbase@gmail.com>
Reviewed-by: Filipe David Borba Manana <fdmanana@gmail.com>
Reviewed-by: Jin Lim <jin@couchbase.com>
Tested-by: Aaron Miller <apage43@ninjawhale.com>
Tested-by: Filipe David Borba Manana <fdmanana@gmail.com>
Reviewed-on: http://review.couchbase.org/24596
Reviewed-by: Aaron Miller <apage43@ninjawhale.com>
  • Loading branch information...
1 parent c6e7157 commit 8e961880696e0398229e7a837344b73053beed84 @apage43 apage43 committed with fdmanana Feb 13, 2013
Showing with 5 additions and 1 deletion.
  1. +5 −1 src/couchdb/couch_db.erl
View
@@ -687,7 +687,11 @@ open_doc_int(Db, <<?LOCAL_DOC_PREFIX, _/binary>> = Id, Options) ->
end;
open_doc_int(Db, #doc_info{id=Id,deleted=IsDeleted,rev=RevInfo, body_ptr=Bp,
content_meta=ContentMeta}=DocInfo, Options) ->
- {ok, Body} = couch_file:pread_iolist(Db#db.fd, Bp),
+ Body = case Bp of
+ 0 -> <<>>;
+ _ -> {ok, Body0} = couch_file:pread_iolist(Db#db.fd, Bp),
+ Body0
+ end,
Doc = #doc{
id = Id,
rev = RevInfo,

0 comments on commit 8e96188

Please sign in to comment.