couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dam...@apache.org
Subject svn commit: r957800 - in /couchdb/trunk: share/www/script/test/attachments.js src/couchdb/couch_doc.erl
Date Fri, 25 Jun 2010 05:18:28 GMT
Author: damien
Date: Fri Jun 25 05:18:28 2010
New Revision: 957800

URL: http://svn.apache.org/viewvc?rev=957800&view=rev
Log:
Added checking to ensure when a revpos is sent with a stub, it's correct.

Modified:
    couchdb/trunk/share/www/script/test/attachments.js
    couchdb/trunk/src/couchdb/couch_doc.erl

Modified: couchdb/trunk/share/www/script/test/attachments.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/test/attachments.js?rev=957800&r1=957799&r2=957800&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/test/attachments.js (original)
+++ couchdb/trunk/share/www/script/test/attachments.js Fri Jun 25 05:18:28 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/trunk/src/couchdb/couch_doc.erl
URL: http://svn.apache.org/viewvc/couchdb/trunk/src/couchdb/couch_doc.erl?rev=957800&r1=957799&r2=957800&view=diff
==============================================================================
--- couchdb/trunk/src/couchdb/couch_doc.erl (original)
+++ couchdb/trunk/src/couchdb/couch_doc.erl Fri Jun 25 05:18:28 2010
@@ -198,7 +198,7 @@ transfer_fields([{<<"_attachments">>, {J
         case couch_util:get_value(<<"stub">>, BinProps) of
         true ->
             Type = couch_util:get_value(<<"content_type">>, BinProps),
-            RevPos = couch_util:get_value(<<"revpos">>, BinProps, 0),
+            RevPos = couch_util:get_value(<<"revpos">>, BinProps, nil),
             DiskLen = couch_util:get_value(<<"length">>, BinProps),
             {Enc, EncLen} = att_encoding_info(BinProps),
             #att{name=Name, data=stub, type=Type, att_len=EncLen,
@@ -309,8 +309,8 @@ 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_foldl_decode(#att{data=Fun,att_len=Len, encoding=identity}, Fun, Acc) ->
-       fold_streamed_data(Fun, Len, Fun, Acc).
+att_foldl_decode(#att{data=Fun2,att_len=Len, encoding=identity}, Fun, Acc) ->
+       fold_streamed_data(Fun2, Len, Fun, Acc).
 
 att_to_bin(#att{data=Bin}) when is_binary(Bin) ->
     Bin;
@@ -357,9 +357,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,



Mime
View raw message