couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject svn commit: r1128698 - in /couchdb/branches/1.1.x: share/www/script/test/attachments_multipart.js src/couchdb/couch_db.erl src/couchdb/couch_doc.erl
Date Sat, 28 May 2011 16:15:14 GMT
Author: rnewson
Date: Sat May 28 16:15:14 2011
New Revision: 1128698

URL: http://svn.apache.org/viewvc?rev=1128698&view=rev
Log:
COUCHDB-1173 - pass md5 in stub so replication verifies the transfer.

Modified:
    couchdb/branches/1.1.x/share/www/script/test/attachments_multipart.js
    couchdb/branches/1.1.x/src/couchdb/couch_db.erl
    couchdb/branches/1.1.x/src/couchdb/couch_doc.erl

Modified: couchdb/branches/1.1.x/share/www/script/test/attachments_multipart.js
URL: http://svn.apache.org/viewvc/couchdb/branches/1.1.x/share/www/script/test/attachments_multipart.js?rev=1128698&r1=1128697&r2=1128698&view=diff
==============================================================================
--- couchdb/branches/1.1.x/share/www/script/test/attachments_multipart.js (original)
+++ couchdb/branches/1.1.x/share/www/script/test/attachments_multipart.js Sat May 28 16:15:14
2011
@@ -90,6 +90,7 @@ couchTests.attachments_multipart= functi
   
   //lets change attachment bar
   delete doc._attachments["bar.txt"].stub; // remove stub member (or could set to false)
+  delete doc._attachments["bar.txt"].digest; // remove the digest (it's for the gzip form)
   doc._attachments["bar.txt"].length = 18;
   doc._attachments["bar.txt"].follows = true;
   //lets delete attachment baz:
@@ -107,6 +108,7 @@ couchTests.attachments_multipart= functi
       "this is 18 chars l" +
       "\r\n--abc123--"
     });
+  TEquals(201, xhr.status);
   
   xhr = CouchDB.request("GET", "/test_suite_db/multipart/bar.txt");
   

Modified: couchdb/branches/1.1.x/src/couchdb/couch_db.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/1.1.x/src/couchdb/couch_db.erl?rev=1128698&r1=1128697&r2=1128698&view=diff
==============================================================================
--- couchdb/branches/1.1.x/src/couchdb/couch_db.erl (original)
+++ couchdb/branches/1.1.x/src/couchdb/couch_db.erl Sat May 28 16:15:14 2011
@@ -812,7 +812,7 @@ doc_flush_atts(Doc, Fd) ->
     Doc#doc{atts=[flush_att(Fd, Att) || Att <- Doc#doc.atts]}.
 
 check_md5(_NewSig, <<>>) -> ok;
-check_md5(Sig1, Sig2) when Sig1 == Sig2 -> ok;
+check_md5(Sig, Sig) -> ok;
 check_md5(_, _) -> throw(md5_mismatch).
 
 flush_att(Fd, #att{data={Fd0, _}}=Att) when Fd0 == Fd ->

Modified: couchdb/branches/1.1.x/src/couchdb/couch_doc.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/1.1.x/src/couchdb/couch_doc.erl?rev=1128698&r1=1128697&r2=1128698&view=diff
==============================================================================
--- couchdb/branches/1.1.x/src/couchdb/couch_doc.erl (original)
+++ couchdb/branches/1.1.x/src/couchdb/couch_doc.erl Sat May 28 16:15:14 2011
@@ -87,8 +87,14 @@ to_json_attachments(Atts, OutputData, Da
         fun(#att{disk_len=DiskLen, att_len=AttLen, encoding=Enc}=Att) ->
             {Att#att.name, {[
                 {<<"content_type">>, Att#att.type},
-                {<<"revpos">>, Att#att.revpos}
-                ] ++
+                {<<"revpos">>, Att#att.revpos}] ++
+                case Att#att.md5 of
+                    <<>> ->
+                        [];
+                    Md5 ->
+                        EncodedMd5 = base64:encode(Md5),
+                        [{<<"digest">>, <<"md5-",EncodedMd5/binary>>}]
+                end ++
                 if not OutputData orelse Att#att.data == stub ->
                     [{<<"length">>, DiskLen}, {<<"stub">>, true}];
                 true ->
@@ -199,6 +205,12 @@ transfer_fields([{<<"_rev">>, _Rev} | Re
 
 transfer_fields([{<<"_attachments">>, {JsonBins}} | Rest], Doc) ->
     Atts = lists:map(fun({Name, {BinProps}}) ->
+        Md5 = case couch_util:get_value(<<"digest">>, BinProps) of
+            <<"md5-",EncodedMd5/binary>> ->
+                base64:decode(EncodedMd5);
+            _ ->
+               <<>>
+        end,
         case couch_util:get_value(<<"stub">>, BinProps) of
         true ->
             Type = couch_util:get_value(<<"content_type">>, BinProps),
@@ -206,7 +218,7 @@ transfer_fields([{<<"_attachments">>, {J
             DiskLen = couch_util:get_value(<<"length">>, BinProps),
             {Enc, EncLen} = att_encoding_info(BinProps),
             #att{name=Name, data=stub, type=Type, att_len=EncLen,
-                disk_len=DiskLen, encoding=Enc, revpos=RevPos};
+                disk_len=DiskLen, encoding=Enc, revpos=RevPos, md5=Md5};
         _ ->
             Type = couch_util:get_value(<<"content_type">>, BinProps,
                     ?DEFAULT_ATTACHMENT_CONTENT_TYPE),
@@ -216,7 +228,7 @@ transfer_fields([{<<"_attachments">>, {J
                 DiskLen = couch_util:get_value(<<"length">>, BinProps),
                 {Enc, EncLen} = att_encoding_info(BinProps),
                 #att{name=Name, data=follows, type=Type, encoding=Enc,
-                    att_len=EncLen, disk_len=DiskLen, revpos=RevPos};
+                    att_len=EncLen, disk_len=DiskLen, revpos=RevPos, md5=Md5};
             _ ->
                 Value = couch_util:get_value(<<"data">>, BinProps),
                 Bin = base64:decode(Value),



Mime
View raw message