From 1b0146dd004c1b9cd6769c11969cc13f8a37fcd9 Mon Sep 17 00:00:00 2001 From: "Damien F. Katz" Date: Sun, 15 Nov 2009 04:11:11 +0000 Subject: Testing of incremental attachments and more testing of multipart/handling. git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@836324 13f79535-47bb-0310-9956-ffa450edef68 --- src/couchdb/couch_db.erl | 7 +++++-- src/couchdb/couch_doc.erl | 2 +- src/couchdb/couch_httpd.erl | 2 ++ src/couchdb/couch_httpd_db.erl | 19 +++++++++++++++---- 4 files changed, 23 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/couchdb/couch_db.erl b/src/couchdb/couch_db.erl index aa46a347..7630989a 100644 --- a/src/couchdb/couch_db.erl +++ b/src/couchdb/couch_db.erl @@ -15,7 +15,7 @@ -export([open/2,close/1,create/2,start_compact/1,get_db_info/1,get_design_docs/1]). -export([open_ref_counted/2,is_idle/1,monitor/1,count_changes_since/2]). --export([update_doc/3,update_docs/4,update_docs/2,update_docs/3,delete_doc/3]). +-export([update_doc/3,update_doc/4,update_docs/4,update_docs/2,update_docs/3,delete_doc/3]). -export([get_doc_info/2,open_doc/2,open_doc/3,open_doc_revs/4]). -export([set_revs_limit/2,get_revs_limit/1,register_update_notifier/3]). -export([get_missing_revs/2,name/1,doc_to_tree/1,get_update_seq/1,get_committed_update_seq/1]). @@ -251,7 +251,10 @@ name(#db{name=Name}) -> Name. update_doc(Db, Doc, Options) -> - case update_docs(Db, [Doc], Options) of + update_doc(Db, Doc, Options, interactive_edit). + +update_doc(Db, Doc, Options, UpdateType) -> + case update_docs(Db, [Doc], Options, UpdateType) of {ok, [{ok, NewRev}]} -> {ok, NewRev}; {ok, [Error]} -> diff --git a/src/couchdb/couch_doc.erl b/src/couchdb/couch_doc.erl index 079d9dfa..eb07a9e6 100644 --- a/src/couchdb/couch_doc.erl +++ b/src/couchdb/couch_doc.erl @@ -322,7 +322,7 @@ merge_stubs(#doc{id=Id,atts=MemBins}=StubsDoc, #doc{atts=DiskBins}) -> {ok, #att{revpos=RevPos}=DiskAtt} -> DiskAtt; _ -> - throw({missing_stub_on_target, + throw({missing_stub, <<"id:", Id/binary, ", name:", Name/binary>>}) end; (Att) -> diff --git a/src/couchdb/couch_httpd.erl b/src/couchdb/couch_httpd.erl index a0955daa..9c0a3668 100644 --- a/src/couchdb/couch_httpd.erl +++ b/src/couchdb/couch_httpd.erl @@ -559,6 +559,8 @@ error_info({error, illegal_database_name}) -> {400, <<"illegal_database_name">>, <<"Only lowercase characters (a-z), " "digits (0-9), and any of the characters _, $, (, ), +, -, and / " "are allowed">>}; +error_info({missing_stub, Reason}) -> + {412, <<"missing_stub">>, Reason}; error_info({Error, Reason}) -> {500, couch_util:to_binary(Error), couch_util:to_binary(Reason)}; error_info(Error) -> diff --git a/src/couchdb/couch_httpd_db.erl b/src/couchdb/couch_httpd_db.erl index 4138db7d..71fc3f48 100644 --- a/src/couchdb/couch_httpd_db.erl +++ b/src/couchdb/couch_httpd_db.erl @@ -30,6 +30,7 @@ rev = nil, open_revs = [], show = nil, + update_type = interactive_edit, atts_since = nil }). @@ -780,6 +781,9 @@ db_doc_req(#httpd{method='POST'}=Req, Db, DocId) -> ]}); db_doc_req(#httpd{method='PUT'}=Req, Db, DocId) -> + #doc_query_args{ + update_type = UpdateType + } = parse_doc_query(Req), couch_doc:validate_docid(DocId), Loc = absolute_uri(Req, "/" ++ ?b2l(Db#db.name) ++ "/" ++ ?b2l(DocId)), @@ -789,7 +793,7 @@ db_doc_req(#httpd{method='PUT'}=Req, Db, DocId) -> Doc0 = couch_doc:doc_from_multi_part_stream(ContentType, fun() -> receive_request_data(Req) end), Doc = couch_doc_from_req(Req, DocId, Doc0), - update_doc(Req, Db, DocId, Doc, RespHeaders); + update_doc(Req, Db, DocId, Doc, RespHeaders, UpdateType); _ -> case couch_httpd:qs_value(Req, "batch") of "ok" -> @@ -810,7 +814,7 @@ db_doc_req(#httpd{method='PUT'}=Req, Db, DocId) -> _Normal -> % normal Doc = couch_doc_from_req(Req, DocId, couch_httpd:json_body(Req)), - update_doc(Req, Db, DocId, Doc, RespHeaders) + update_doc(Req, Db, DocId, Doc, RespHeaders, UpdateType) end end; @@ -911,7 +915,10 @@ update_doc_result_to_json(DocId, Error) -> update_doc(Req, Db, DocId, Doc) -> update_doc(Req, Db, DocId, Doc, []). -update_doc(Req, Db, DocId, #doc{deleted=Deleted}=Doc, Headers) -> +update_doc(Req, Db, DocId, Doc, Headers) -> + update_doc(Req, Db, DocId, Doc, Headers, interactive_edit). + +update_doc(Req, Db, DocId, #doc{deleted=Deleted}=Doc, Headers, UpdateType) -> case couch_httpd:header_value(Req, "X-Couch-Full-Commit") of "true" -> Options = [full_commit]; @@ -920,7 +927,7 @@ update_doc(Req, Db, DocId, #doc{deleted=Deleted}=Doc, Headers) -> _ -> Options = [] end, - {ok, NewRev} = couch_db:update_doc(Db, Doc, Options), + {ok, NewRev} = couch_db:update_doc(Db, Doc, Options, UpdateType), NewRevStr = couch_doc:rev_to_str(NewRev), ResponseHeaders = [{"Etag", <<"\"", NewRevStr/binary, "\"">>}] ++ Headers, send_json(Req, if Deleted -> 200; true -> 201 end, @@ -1133,6 +1140,10 @@ parse_doc_query(Req) -> Args#doc_query_args{atts_since = couch_doc:parse_revs(JsonArray)}; {"show", FormatStr} -> Args#doc_query_args{show=parse_doc_format(FormatStr)}; + {"new_edits", "false"} -> + Args#doc_query_args{update_type=replicated_changes}; + {"new_edits", "true"} -> + Args#doc_query_args{update_type=interactive_edit}; _Else -> % unknown key value pair, ignore. Args end -- cgit v1.2.3