summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDamien F. Katz <damien@apache.org>2009-11-15 04:11:11 +0000
committerDamien F. Katz <damien@apache.org>2009-11-15 04:11:11 +0000
commit1b0146dd004c1b9cd6769c11969cc13f8a37fcd9 (patch)
tree286cb8b36c63057474fda4fff1245a56e32a05d6 /src
parent29862925728ff98c077107183e75e23184b0e51d (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/couchdb/couch_db.erl7
-rw-r--r--src/couchdb/couch_doc.erl2
-rw-r--r--src/couchdb/couch_httpd.erl2
-rw-r--r--src/couchdb/couch_httpd_db.erl19
4 files changed, 23 insertions, 7 deletions
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