couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kxe...@apache.org
Subject [12/25] couch commit: updated refs/heads/master to 92598cd
Date Thu, 15 Oct 2015 16:35:46 GMT
Move simplified version of doc_from_multi_part_stream back to couch_doc


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

Branch: refs/heads/master
Commit: f8e7d61a8583325ca3054e070a4ab20f936a56f4
Parents: 51f3aa5
Author: ILYA Khlopotov <iilyak@ca.ibm.com>
Authored: Thu Nov 27 15:50:32 2014 -0800
Committer: ILYA Khlopotov <iilyak@ca.ibm.com>
Committed: Wed May 6 06:55:58 2015 -0700

----------------------------------------------------------------------
 src/couch_doc.erl             | 23 ++++++++++++++++++++++-
 src/couch_httpd_db.erl        |  2 +-
 src/couch_httpd_multipart.erl | 25 +------------------------
 test/couch_doc_tests.erl      |  2 +-
 4 files changed, 25 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/f8e7d61a/src/couch_doc.erl
----------------------------------------------------------------------
diff --git a/src/couch_doc.erl b/src/couch_doc.erl
index a7fd147..3a25ac5 100644
--- a/src/couch_doc.erl
+++ b/src/couch_doc.erl
@@ -15,7 +15,7 @@
 -export([to_doc_info/1,to_doc_info_path/1,parse_rev/1,parse_revs/1,rev_to_str/1,revs_to_strs/1]).
 -export([from_json_obj/1,to_json_obj/2,has_stubs/1, merge_stubs/2]).
 -export([validate_docid/1, get_validate_doc_fun/1]).
-
+-export([doc_from_multi_part_stream/2, doc_from_multi_part_stream/3]).
 -export([doc_to_multi_part_stream/5, len_doc_to_multi_part_stream/4]).
 -export([abort_multi_part_stream/1]).
 -export([restart_open_doc_revs/3]).
@@ -453,6 +453,27 @@ atts_to_mp([Att | RestAtts], Boundary, WriteFun, SendEncodedAtts)  ->
             atts_to_mp(RestAtts, Boundary, WriteFun, SendEncodedAtts)
     end.
 
+doc_from_multi_part_stream(ContentType, DataFun) ->
+    doc_from_multi_part_stream(ContentType, DataFun, make_ref()).
+
+doc_from_multi_part_stream(ContentType, DataFun, Ref) ->
+    case couch_httpd_multipart:parse_multipart_stream(ContentType, DataFun, Ref) of
+    {{started_open_doc_revs, NewRef}, Parser, _ParserRef} ->
+        restart_open_doc_revs(Parser, Ref, NewRef);
+    {{doc_bytes, Ref, DocBytes}, Parser, ParserRef} ->
+        Doc = from_json_obj(?JSON_DECODE(DocBytes)),
+        % we'll send the Parser process ID to the remote nodes so they can
+        % retrieve their own copies of the attachment data
+        WithParser = fun(follows) -> {follows, Parser, Ref}; (D) -> D end,
+        Atts = [couch_att:transform(data, WithParser, A) || A <- Doc#doc.atts],
+        WaitFun = fun() ->
+            receive {'DOWN', ParserRef, _, _, _} -> ok end,
+            erlang:put(mochiweb_request_recv, true)
+        end,
+        {ok, Doc#doc{atts=Atts}, WaitFun, Parser};
+    ok -> ok
+    end.
+
 abort_multi_part_stream(Parser) ->
     couch_log:warning("couch_doc:abort_multi_part_stream/1 is deprecated use couch_httpd_multipart:abort_multipart_stream/1",
[]),
     couch_httpd_multipart:abort_multipart_stream(Parser).

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/f8e7d61a/src/couch_httpd_db.erl
----------------------------------------------------------------------
diff --git a/src/couch_httpd_db.erl b/src/couch_httpd_db.erl
index 46f9fc9..e8c2629 100644
--- a/src/couch_httpd_db.erl
+++ b/src/couch_httpd_db.erl
@@ -578,7 +578,7 @@ db_doc_req(#httpd{method='PUT'}=Req, Db, DocId) ->
 
     case couch_util:to_list(couch_httpd:header_value(Req, "Content-Type")) of
     ("multipart/related;" ++ _) = ContentType ->
-        {ok, Doc0, WaitFun, Parser} = couch_httpd_multipart:doc_from_multi_part_stream(
+        {ok, Doc0, WaitFun, Parser} = couch_doc:doc_from_multi_part_stream(
             ContentType, fun() -> receive_request_data(Req) end),
         Doc = couch_doc_from_req(Req, DocId, Doc0),
         try

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/f8e7d61a/src/couch_httpd_multipart.erl
----------------------------------------------------------------------
diff --git a/src/couch_httpd_multipart.erl b/src/couch_httpd_multipart.erl
index 5ea8327..1110751 100644
--- a/src/couch_httpd_multipart.erl
+++ b/src/couch_httpd_multipart.erl
@@ -1,33 +1,10 @@
 -module(couch_httpd_multipart).
 
--export([doc_from_multi_part_stream/2, doc_from_multi_part_stream/3]).
-
+-export([parse_multipart_stream/3]).
 -export([abort_multi_part_stream/1]).
 
 -include_lib("couch/include/couch_db.hrl").
 
-doc_from_multi_part_stream(ContentType, DataFun) ->
-    doc_from_multi_part_stream(ContentType, DataFun, make_ref()).
-
-
-doc_from_multi_part_stream(ContentType, DataFun, Ref) ->
-    case parse_multipart_stream(ContentType, DataFun, Ref) of
-    {{started_open_doc_revs, NewRef}, Parser, _ParserRef} ->
-        couch_doc:restart_open_doc_revs(Parser, Ref, NewRef);
-    {{doc_bytes, Ref, DocBytes}, Parser, ParserRef} ->
-        Doc = couch_doc:from_json_obj(?JSON_DECODE(DocBytes)),
-        % we'll send the Parser process ID to the remote nodes so they can
-        % retrieve their own copies of the attachment data
-        WithParser = fun(follows) -> {follows, Parser, Ref}; (D) -> D end,
-        Atts = [couch_att:transform(data, WithParser, A) || A <- Doc#doc.atts],
-        WaitFun = fun() ->
-            receive {'DOWN', ParserRef, _, _, _} -> ok end,
-            erlang:put(mochiweb_request_recv, true)
-        end,
-        {ok, Doc#doc{atts=Atts}, WaitFun, Parser};
-    ok -> ok
-    end.
-
 parse_multipart_stream(ContentType, DataFun, Ref) ->
     Parent = self(),
     NumMpWriters = num_mp_writers(),

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/f8e7d61a/test/couch_doc_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_doc_tests.erl b/test/couch_doc_tests.erl
index c9d32a8..5a3f79f 100644
--- a/test/couch_doc_tests.erl
+++ b/test/couch_doc_tests.erl
@@ -30,7 +30,7 @@ doc_from_multi_part_stream_test() ->
     DataFun = fun() -> request(start) end,
 
     {ok, #doc{id = <<"doc0">>, atts = [_]} = Doc, _Fun, _Parser} =
-        couch_httpd_multipart:doc_from_multi_part_stream(ContentType, DataFun),
+        couch_doc:doc_from_multi_part_stream(ContentType, DataFun),
     ok.
 
 request(start) ->


Mime
View raw message