~ubuntu-branches/ubuntu/lucid/couchdb/lucid

« back to all changes in this revision

Viewing changes to src/couchdb/couch_httpd_db.erl

  • Committer: Bazaar Package Importer
  • Author(s): Chad Miller, Ken VanDine
  • Date: 2009-09-25 19:18:26 UTC
  • mfrom: (1.2.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20090925191826-km9018omfgxosvah
Tags: 0.10.0~svn818859-0ubuntu1
* Import code from pre-release branch.  (LP: #427860, #408909)
        + Build and System Integration:
          * Changed `couchdb` script configuration options.
          * Added default.d and local.d configuration directories to load
      sequence.
        + HTTP Interface:
          * Added optional cookie-based authentication handler.
          * Added optional two-legged OAuth authentication handler.
* Packaging of couchdb-bin must replace pre-split couchdb.
  (LP: #432219)
* Move all of /etc and /var out of the couchdb-bin package, to the
  couchdb package. 
* /etc/couchdb must be in couchdb-bin, as config files are needed
  by all servers.
  + So the couchdb user must be managed by couchdb-bin.
  + Split postinst/postrm files to manage different files.
  + Set Replaces of couchdb-bin by couchdb so that config files
    migrate.
* Update the version number in postrm.  (!)
* Use the new "Breaks" field in control file to help split pkg.

[Ken VanDine]
* debian/couchdb.install:
  - removed /var
* debian/rules:
  - removed bootstrap 
* debian/couchdb.postinst:
  - Added the debhelper tag

Show diffs side-by-side

added added

removed removed

Lines of Context:
138
138
    true ->
139
139
        case wait_db_updated(Timeout, TimeoutFun) of
140
140
        updated ->
141
 
            {ok, Db2} = couch_db:open(DbName, [{user_ctx, UserCtx}]),
142
 
            keep_sending_changes(Req, Resp, Db2, EndSeq, Prepend2, Timeout,
143
 
                TimeoutFun, ResponseType, Filter, End);
 
141
            case couch_db:open(DbName, [{user_ctx, UserCtx}]) of
 
142
            {ok, Db2} ->
 
143
                keep_sending_changes(Req, Resp, Db2, EndSeq, Prepend2, Timeout,
 
144
                    TimeoutFun, ResponseType, Filter, End);
 
145
            _Else ->
 
146
                end_sending_changes(Resp, EndSeq, ResponseType)
 
147
            end;
144
148
        stop ->
145
149
            end_sending_changes(Resp, EndSeq, ResponseType)
146
150
        end
147
151
    end.
148
152
 
149
153
changes_enumerator(DocInfos, {_, _, FilterFun, Resp, "continuous"}) ->
150
 
    [#doc_info{id=Id, high_seq=Seq}|_] = DocInfos,
 
154
    [#doc_info{id=Id, high_seq=Seq, revs=[#rev_info{deleted=Del}|_]}|_] = DocInfos,
151
155
    Results0 = [FilterFun(DocInfo) || DocInfo <- DocInfos],
152
156
    Results = [Result || Result <- Results0, Result /= null],
153
157
    case Results of
154
158
    [] ->
155
159
        {ok, {Seq, nil, FilterFun, Resp, "continuous"}};
156
160
    _ ->
157
 
        send_chunk(Resp, [?JSON_ENCODE({[{seq,Seq},{id,Id},{changes,Results}]})
158
 
            |"\n"]),
 
161
        send_chunk(Resp, [?JSON_ENCODE(changes_row(Seq, Id, Del, Results)) |"\n"]),
159
162
        {ok, {Seq, nil, FilterFun, Resp, "continuous"}}
160
163
    end;
161
164
changes_enumerator(DocInfos, {_, Prepend, FilterFun, Resp, _}) ->
162
 
    [#doc_info{id=Id, high_seq=Seq}|_] = DocInfos,
 
165
    [#doc_info{id=Id, high_seq=Seq, revs=[#rev_info{deleted=Del}|_]}|_] = DocInfos,
163
166
    Results0 = [FilterFun(DocInfo) || DocInfo <- DocInfos],
164
167
    Results = [Result || Result <- Results0, Result /= null],
165
168
    case Results of
166
169
    [] ->
167
170
        {ok, {Seq, Prepend, FilterFun, Resp, nil}};
168
171
    _ ->
169
 
        send_chunk(Resp, [Prepend, ?JSON_ENCODE({[{seq,Seq},{id,Id},
170
 
            {changes,Results}]})]),
 
172
        send_chunk(Resp, [Prepend, ?JSON_ENCODE(changes_row(Seq, Id, Del, Results))]),
171
173
        {ok, {Seq, <<",\n">>, FilterFun, Resp, nil}}
172
174
    end.
173
175
 
 
176
changes_row(Seq, Id, Del, Results) ->
 
177
    {[{seq,Seq},{id,Id},{changes,Results}] ++ deleted_item(Del)}.
 
178
 
 
179
deleted_item(true) -> [{deleted,true}];
 
180
deleted_item(_) -> [].
 
181
 
174
182
send_changes(Req, Resp, Db, StartSeq, Prepend, ResponseType, FilterFun, End) ->
175
183
    Style = list_to_existing_atom(
176
184
            couch_httpd:qs_value(Req, "style", "main_only")),
936
944
                    end,
937
945
                data = case couch_httpd:body_length(Req) of
938
946
                    undefined ->
939
 
                        undefined;
 
947
                        <<"">>;
940
948
                    {unknown_transfer_encoding, Unknown} ->
941
949
                        exit({unknown_transfer_encoding, Unknown});
942
950
                    chunked ->
945
953
                                ChunkFun, InitState)
946
954
                        end;
947
955
                    0 ->
948
 
                        <<>>;
 
956
                        <<"">>;
949
957
                    Length when is_integer(Length) ->
950
958
                        fun() -> couch_httpd:recv(Req, 0) end;
951
959
                    Length ->