From 887c9b1a8b551272c3ca06906cfdc4fb901830a8 Mon Sep 17 00:00:00 2001 From: Adam Kocoloski Date: Mon, 4 May 2009 22:36:46 +0000 Subject: use revisions when replicating attachments. Closes COUCHDB-337 git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@771480 13f79535-47bb-0310-9956-ffa450edef68 --- src/couchdb/couch_rep.erl | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/couchdb/couch_rep.erl b/src/couchdb/couch_rep.erl index 9d100d1f..f7b1e9ae 100644 --- a/src/couchdb/couch_rep.erl +++ b/src/couchdb/couch_rep.erl @@ -369,10 +369,11 @@ attachment_loop(ReqId) -> {ibrowse_async_response_end, ReqId} -> ok end. -attachment_stub_converter(DbS, Id, {Name, {stub, Type, Length}}) -> +attachment_stub_converter(DbS, Id, Rev, {Name, {stub, Type, Length}}) -> #http_db{uri=DbUrl, headers=Headers} = DbS, - % TODO worry about revisions - Url = DbUrl ++ url_encode(Id) ++ "/" ++ url_encode(?b2l(Name)), + {Pos, [RevId|_]} = Rev, + Url = lists:flatten([DbUrl, url_encode(Id), "/", url_encode(?b2l(Name)), + "?rev=", couch_doc:rev_to_str({Pos,RevId})]), ?LOG_DEBUG("Attachment URL ~p", [Url]), {ok, RcvFun} = make_attachment_stub_receiver(Url, Headers, Name, Type, Length), @@ -712,8 +713,9 @@ open_doc_revs(#http_db{uri=DbUrl, headers=Headers} = DbS, DocId, Revs0, fun({[{<<"missing">>, Rev}]}) -> {{not_found, missing}, couch_doc:parse_rev(Rev)}; ({[{<<"ok">>, JsonDoc}]}) -> - #doc{id=Id, attachments=Attach} = Doc = couch_doc:from_json_obj(JsonDoc), - Attach2 = [attachment_stub_converter(DbS,Id,A) || A <- Attach], + #doc{id=Id, revs=Rev, attachments=Attach} = Doc = + couch_doc:from_json_obj(JsonDoc), + Attach2 = [attachment_stub_converter(DbS,Id,Rev,A) || A <- Attach], {ok, Doc#doc{attachments=Attach2}} end, JsonResults), {ok, Results}; -- cgit v1.2.3