You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2014/08/01 11:06:21 UTC

[45/49] chttpd commit: updated refs/heads/windsor-merge to 554ef74

Be more careful when matching attachment data

This code was ported from a list comprehension which used
to properly ignore patterns which didn't match the Fd
tuple. This adds back the ability to ignore stub data
entries as this does come up in one case where att_since is
passed in via the API.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/commit/07c2603a
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/tree/07c2603a
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/diff/07c2603a

Branch: refs/heads/windsor-merge
Commit: 07c2603aeafec99a9b4d353f8656d87ce0fe2a76
Parents: 07bf741
Author: Brian Mitchell <br...@cloudant.com>
Authored: Fri May 16 15:57:53 2014 -0400
Committer: Robert Newson <rn...@apache.org>
Committed: Thu Jul 31 11:55:11 2014 +0100

----------------------------------------------------------------------
 src/chttpd_db.erl | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/07c2603a/src/chttpd_db.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_db.erl b/src/chttpd_db.erl
index ae70aa3..f831389 100644
--- a/src/chttpd_db.erl
+++ b/src/chttpd_db.erl
@@ -1361,12 +1361,27 @@ validate_attachment_name(Name) ->
 
 -spec monitor_attachments(couch_att:att() | [couch_att:att()]) -> [reference()].
 monitor_attachments(Atts) when is_list(Atts) ->
-    lists:map(fun(Att) ->
-        {Fd, _} = couch_att:fetch(data, Att),
-        monitor(process, Fd)
-    end, Atts);
+    lists:foldl(fun(Att, Monitors) ->
+        case couch_att:fetch(data, Att) of
+            {Fd, _} -> [monitor(process, Fd) | Monitors];
+            _ -> Monitors
+        end
+    end, [], Atts);
 monitor_attachments(Att) ->
     monitor_attachments([Att]).
 
 demonitor_refs(Refs) when is_list(Refs) ->
     [demonitor(Ref) || Ref <- Refs].
+
+-ifdef(TEST).
+-include_lib("eunit/include/eunit.hrl").
+
+monitor_attachments_test_() ->
+    {"ignore stubs",
+        fun () ->
+            Atts = [couch_att:new([{data, stub}])],
+            ?_assertEqual([], monitor_attachments(Atts))
+        end
+    }.
+
+-endif.