You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ja...@apache.org on 2010/06/25 16:24:06 UTC
svn commit: r957979 - in /couchdb/branches/0.11.x:
share/www/script/test/attachments.js src/couchdb/couch_doc.erl
Author: jan
Date: Fri Jun 25 14:24:06 2010
New Revision: 957979
URL: http://svn.apache.org/viewvc?rev=957979&view=rev
Log:
Merge r957800 from trunk:
Added checking to ensure when a revpos is sent with a stub, it's correct.
Modified:
couchdb/branches/0.11.x/share/www/script/test/attachments.js
couchdb/branches/0.11.x/src/couchdb/couch_doc.erl
Modified: couchdb/branches/0.11.x/share/www/script/test/attachments.js
URL: http://svn.apache.org/viewvc/couchdb/branches/0.11.x/share/www/script/test/attachments.js?rev=957979&r1=957978&r2=957979&view=diff
==============================================================================
--- couchdb/branches/0.11.x/share/www/script/test/attachments.js (original)
+++ couchdb/branches/0.11.x/share/www/script/test/attachments.js Fri Jun 25 14:24:06 2010
@@ -255,13 +255,19 @@ couchTests.attachments= function(debug)
}
}
}
- var save_response = db.save(bin_doc6);
- bin_doc6._rev = save_response["rev"];
+ T(db.save(bin_doc6).ok);
// stub out the attachment
bin_doc6._attachments["foo.txt"] = { stub: true };
+ T(db.save(bin_doc6).ok == true);
- var xhr = CouchDB.request("PUT", "/test_suite_db/bin_doc6", {
- body: JSON.stringify(bin_doc6)
- });
- TEquals(201, xhr.status, "should send 201 Created when attachment stub contains only the 'stub' field");
+ // wrong rev pos specified
+
+ // stub out the attachment with the wrong revpos
+ bin_doc6._attachments["foo.txt"] = { stub: true, revpos: 10};
+ try {
+ T(db.save(bin_doc6).ok == true);
+ T(false && "Shouldn't get here!");
+ } catch (e) {
+ T(e.error == "missing_stub")
+ }
};
Modified: couchdb/branches/0.11.x/src/couchdb/couch_doc.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/0.11.x/src/couchdb/couch_doc.erl?rev=957979&r1=957978&r2=957979&view=diff
==============================================================================
--- couchdb/branches/0.11.x/src/couchdb/couch_doc.erl (original)
+++ couchdb/branches/0.11.x/src/couchdb/couch_doc.erl Fri Jun 25 14:24:06 2010
@@ -198,7 +198,7 @@ transfer_fields([{<<"_attachments">>, {J
case proplists:get_value(<<"stub">>, BinProps) of
true ->
Type = proplists:get_value(<<"content_type">>, BinProps),
- RevPos = proplists:get_value(<<"revpos">>, BinProps, 0),
+ RevPos = proplists:get_value(<<"revpos">>, BinProps, nil),
DiskLen = proplists:get_value(<<"length">>, BinProps),
{Enc, EncLen} = att_encoding_info(BinProps),
#att{name=Name, data=stub, type=Type, att_len=EncLen,
@@ -310,6 +310,7 @@ att_foldl(#att{data=DataFun,att_len=Len}
att_foldl_decode(#att{data={Fd,Sp},md5=Md5,encoding=Enc}, Fun, Acc) ->
couch_stream:foldl_decode(Fd, Sp, Md5, Enc, Fun, Acc).
+
att_to_bin(#att{data=Bin}) when is_binary(Bin) ->
Bin;
att_to_bin(#att{data=Iolist}) when is_list(Iolist) ->
@@ -355,9 +356,10 @@ has_stubs([_Att|Rest]) ->
merge_stubs(#doc{id=Id,atts=MemBins}=StubsDoc, #doc{atts=DiskBins}) ->
BinDict = dict:from_list([{Name, Att} || #att{name=Name}=Att <- DiskBins]),
MergedBins = lists:map(
- fun(#att{name=Name, data=stub}) ->
+ fun(#att{name=Name, data=stub, revpos=StubRevPos}) ->
case dict:find(Name, BinDict) of
- {ok, #att{}=DiskAtt} ->
+ {ok, #att{revpos=DiskRevPos}=DiskAtt}
+ when DiskRevPos == StubRevPos orelse StubRevPos == nil ->
DiskAtt;
_ ->
throw({missing_stub,