couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject [couchdb] branch prototype/fdb-layer updated: Fix more elixir tests
Date Tue, 16 Jul 2019 17:05:53 GMT
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch prototype/fdb-layer
in repository https://gitbox.apache.org/repos/asf/couchdb.git


The following commit(s) were added to refs/heads/prototype/fdb-layer by this push:
     new 4786766  Fix more elixir tests
4786766 is described below

commit 4786766895a43b822cdeb1d8a47e30b2561fc7ff
Author: Paul J. Davis <paul.joseph.davis@gmail.com>
AuthorDate: Tue Jul 16 12:05:35 2019 -0500

    Fix more elixir tests
---
 src/chttpd/src/chttpd_db.erl  |  8 ++++----
 src/couch/src/couch_att.erl   | 10 +++++++---
 src/fabric/src/fabric2_db.erl | 35 ++++++++++++++++++++++++++++++++---
 3 files changed, 43 insertions(+), 10 deletions(-)

diff --git a/src/chttpd/src/chttpd_db.erl b/src/chttpd/src/chttpd_db.erl
index a252041..0c7e4d5 100644
--- a/src/chttpd/src/chttpd_db.erl
+++ b/src/chttpd/src/chttpd_db.erl
@@ -1046,7 +1046,7 @@ db_doc_req(#httpd{method='GET', mochi_req=MochiReq}=Req, Db, DocId)
->
 
 db_doc_req(#httpd{method='POST', user_ctx=Ctx}=Req, Db, DocId) ->
     couch_httpd:validate_referer(Req),
-    couch_db:validate_docid(Db, DocId),
+    couch_doc:validate_docid(DocId, fabric2_db:name(Db)),
     chttpd:validate_ctype(Req, "multipart/form-data"),
 
     Options = [{user_ctx,Ctx}],
@@ -1106,7 +1106,7 @@ db_doc_req(#httpd{method='PUT', user_ctx=Ctx}=Req, Db, DocId) ->
         update_type = UpdateType
     } = parse_doc_query(Req),
     DbName = fabric2_db:name(Db),
-    couch_doc:validate_docid(DocId),
+    couch_doc:validate_docid(DocId, fabric2_db:name(Db)),
 
     Options = [{user_ctx, Ctx}],
 
@@ -1667,7 +1667,7 @@ db_attachment_req(#httpd{method=Method}=Req, Db, DocId, FileNameParts)
                 % check for the existence of the doc to handle the 404 case.
                 couch_doc_open(Db, DocId, nil, [])
             end,
-            couch_db:validate_docid(Db, DocId),
+            couch_doc:validate_docid(DocId, fabric2_db:name(Db)),
             #doc{id=DocId};
         Rev ->
             case fabric2_db:open_doc_revs(Db, DocId, [Rev], [{user_ctx,Ctx}]) of
@@ -2030,7 +2030,7 @@ bulk_get_open_doc_revs1(Db, Props, Options, {}) ->
             {null, {error, Error}, Options};
         DocId ->
             try
-                couch_db:validate_docid(Db, DocId),
+                couch_doc:validate_docid(DocId, fabric2_db:name(Db)),
                 bulk_get_open_doc_revs1(Db, Props, Options, {DocId})
             catch throw:{Error, Reason} ->
                 {DocId, {error, {null, Error, Reason}}, Options}
diff --git a/src/couch/src/couch_att.erl b/src/couch/src/couch_att.erl
index d3c8966..2c33362 100644
--- a/src/couch/src/couch_att.erl
+++ b/src/couch/src/couch_att.erl
@@ -384,8 +384,12 @@ flush(Db, DocId, Att1) ->
     % If we were sent a gzip'ed attachment with no
     % length data, we have to set it here.
     Att3 = case DiskLen of
-        undefined -> store(disk_len, AttLen, Att2);
-        _ -> Att2
+        undefined when AttLen /= undefined ->
+            store(disk_len, AttLen, Att2);
+        undefined when is_binary(Data) ->
+            store(disk_len, size(Data), Att2);
+        _ ->
+            Att2
     end,
 
     % If no encoding has been set, default to
@@ -537,7 +541,7 @@ range_foldl(Bin1, From, To, Fun, Acc) when is_binary(Bin1) ->
     ReadLen = To - From,
     Bin2 = case Bin1 of
         _ when size(Bin1) < From -> <<>>;
-        <<_:From/binary, B2>> -> B2
+        <<_:From/binary, B2/binary>> -> B2
     end,
     Bin3 = case Bin2 of
         _ when size(Bin2) < ReadLen -> Bin2;
diff --git a/src/fabric/src/fabric2_db.erl b/src/fabric/src/fabric2_db.erl
index 7114903..3c3b7d3 100644
--- a/src/fabric/src/fabric2_db.erl
+++ b/src/fabric/src/fabric2_db.erl
@@ -897,7 +897,7 @@ get_members(SecProps) ->
     end.
 
 
-apply_open_doc_opts(Doc, Revs, Options) ->
+apply_open_doc_opts(Doc0, Revs, Options) ->
     IncludeRevsInfo = lists:member(revs_info, Options),
     IncludeConflicts = lists:member(conflicts, Options),
     IncludeDelConflicts = lists:member(deleted_conflicts, Options),
@@ -906,7 +906,7 @@ apply_open_doc_opts(Doc, Revs, Options) ->
     % This revs_info becomes fairly useless now that we're
     % not keeping old document bodies around...
     Meta1 = if not IncludeRevsInfo -> []; true ->
-        {Pos, [Rev | RevPath]} = Doc#doc.revs,
+        {Pos, [Rev | RevPath]} = Doc0#doc.revs,
         RevPathMissing = lists:map(fun(R) -> {R, missing} end, RevPath),
         [{revs_info, Pos, [{Rev, available} | RevPathMissing]}]
     end,
@@ -932,7 +932,36 @@ apply_open_doc_opts(Doc, Revs, Options) ->
         [{local_seq, fabric2_fdb:vs_to_seq(SeqVS)}]
     end,
 
-    {ok, Doc#doc{meta = Meta1 ++ Meta2 ++ Meta3 ++ Meta4}}.
+    Doc1 = case lists:keyfind(atts_since, 1, Options) of
+        {_, PossibleAncestors} ->
+            #doc{
+                revs = DocRevs,
+                atts = Atts0
+            } = Doc0,
+            RevPos = find_ancestor_rev_pos(DocRevs, PossibleAncestors),
+            Atts1 = lists:map(fun(Att) ->
+                [AttPos, Data] = couch_att:fetch([revpos, data], Att),
+                if  AttPos > RevPos -> couch_att:store(data, Data, Att);
+                    true -> couch_att:store(data, stub, Att)
+                end
+            end, Atts0),
+            Doc0#doc{atts = Atts1};
+        false ->
+            Doc0
+    end,
+
+    {ok, Doc1#doc{meta = Meta1 ++ Meta2 ++ Meta3 ++ Meta4}}.
+
+
+find_ancestor_rev_pos({_, []}, _PossibleAncestors) ->
+    0;
+find_ancestor_rev_pos(_DocRevs, []) ->
+    0;
+find_ancestor_rev_pos({RevPos, [RevId | Rest]}, AttsSinceRevs) ->
+    case lists:member({RevPos, RevId}, AttsSinceRevs) of
+        true -> RevPos;
+        false -> find_ancestor_rev_pos({RevPos - 1, Rest}, AttsSinceRevs)
+    end.
 
 
 filter_found_revs(RevInfo, Revs) ->


Mime
View raw message