Skip to content

Commit

Permalink
chore: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
janl committed Jul 13, 2023
1 parent 5cfa350 commit 123e08d
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 17 deletions.
15 changes: 8 additions & 7 deletions src/couch/src/couch_db.erl
Original file line number Diff line number Diff line change
Expand Up @@ -842,8 +842,7 @@ check_access(Db, Access) ->
end.

check_name(null, _Access) -> false;
check_name(UserName, Access) ->
lists:member(UserName, Access).
check_name(UserName, Access) -> lists:member(UserName, Access).

check_roles(Roles, Access) ->
UserRolesSet = ordsets:from_list(Roles),
Expand Down Expand Up @@ -1580,7 +1579,8 @@ collect_results_with_metrics(Pid, MRef, []) ->
end.

collect_results(Pid, MRef, ResultsAcc) ->
receive % TDOD: need to receiver access?
% TDOD: need to receiver access?
receive
{result, Pid, Result} ->
collect_results(Pid, MRef, [Result | ResultsAcc]);
{done, Pid} ->
Expand All @@ -1600,10 +1600,11 @@ write_and_commit(
DocBuckets = prepare_doc_summaries(Db, DocBuckets1),
ReplicatedChanges = lists:member(?REPLICATED_CHANGES, Options),
MRef = erlang:monitor(process, Pid),
UserCtx = case has_access_enabled(Db) of
true -> UserCtx0;
false -> []
end,
UserCtx =
case has_access_enabled(Db) of
true -> UserCtx0;
false -> []
end,

try
Pid ! {update_docs, self(), DocBuckets, LocalDocs, ReplicatedChanges, UserCtx},
Expand Down
20 changes: 14 additions & 6 deletions src/couch/src/couch_db_updater.erl
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,13 @@ maybe_tag_doc(#doc{id = Id, revs = {Pos, [_Rev | PrevRevs]}, meta = Meta0} = Doc

merge_updates([[{_, #doc{id = X}, _} | _] = A | RestA], [[{_, #doc{id = X}, _} | _] = B | RestB]) ->
[A ++ B | merge_updates(RestA, RestB)];
merge_updates([[{_, #doc{id = X}, _} | _] | _] = A, [[{_, #doc{id = Y}, _} | _] | _] = B) when X < Y ->
merge_updates([[{_, #doc{id = X}, _} | _] | _] = A, [[{_, #doc{id = Y}, _} | _] | _] = B) when
X < Y
->
[hd(A) | merge_updates(tl(A), B)];
merge_updates([[{_, #doc{id = X}, _} | _] | _] = A, [[{_, #doc{id = Y}, _} | _] | _] = B) when X > Y ->
merge_updates([[{_, #doc{id = X}, _} | _] | _] = A, [[{_, #doc{id = Y}, _} | _] | _] = B) when
X > Y
->
[hd(B) | merge_updates(A, tl(B))];
merge_updates([], RestB) ->
RestB;
Expand Down Expand Up @@ -673,7 +677,6 @@ maybe_stem_full_doc_info(#full_doc_info{rev_tree = Tree} = Info, Limit) ->
Info
end.


update_docs_int(Db, DocsList, LocalDocs, ReplicatedChanges) ->
UpdateSeq = couch_db_engine:get_update_seq(Db),
RevsLimit = couch_db_engine:get_revs_limit(Db),
Expand Down Expand Up @@ -747,7 +750,8 @@ update_docs_int(Db, DocsList, LocalDocs, ReplicatedChanges) ->
% the trees, the attachments are already written to disk)
{ok, IndexFDIs} = flush_trees(Db, NewFullDocInfos, []),
Pairs = pair_write_info(OldDocLookups, IndexFDIs),
LocalDocs1 = apply_local_docs_access(Db, LocalDocs), % TODO: local docs access needs validating
% TODO: local docs access needs validating
LocalDocs1 = apply_local_docs_access(Db, LocalDocs),
LocalDocs2 = update_local_doc_revs(LocalDocs1),

{ok, Db1} = couch_db_engine:write_doc_infos(Db, Pairs, LocalDocs2),
Expand All @@ -765,7 +769,10 @@ update_docs_int(Db, DocsList, LocalDocs, ReplicatedChanges) ->

% Check if we just updated any non-access design documents,
% and update the validation funs if we did.
UpdatedDDocIds = [Id || [{_Client, #doc{id = <<"_design/", _/binary>> = Id, access = []}, _} | _] <- DocsList],
UpdatedDDocIds = [
Id
|| [{_Client, #doc{id = <<"_design/", _/binary>> = Id, access = []}, _} | _] <- DocsList
],
{ok, commit_data(Db1), UpdatedDDocIds}.

% at this point, we already validated this Db is access enabled, so do the checks right away.
Expand Down Expand Up @@ -820,7 +827,8 @@ validate_docs_access(
),

{NewDocsListValidated, NewOldDocInfosValidated} =
case length(NewDocs) of %TODO: what if only 2/3?
%TODO: what if only 2/3?
case length(NewDocs) of
% we sent out all docs as invalid access, drop the old doc info associated with it
0 ->
{[NewDocs | DocsListValidated], OldDocInfosValidated};
Expand Down
2 changes: 1 addition & 1 deletion src/couch/test/eunit/couchdb_access_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ access_test_() ->
% fun should_allow_user_to_replicate_from_no_access_to_access/2,

% fun should_allow_user_to_replicate_from_no_access_to_no_access/2,

% _revs_diff for docs you don’t have access to
fun should_not_allow_user_to_revs_diff_other_docs/2

Expand Down
5 changes: 4 additions & 1 deletion src/couch_mrview/src/couch_mrview_updater.erl
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,10 @@ map_docs(Parent, #mrst{db_name = DbName, idx_name = IdxName} = State0) ->
DocFun = fun
({nil, Seq, _}, {SeqAcc, Results}) ->
{erlang:max(Seq, SeqAcc), Results};
({Id, Seq, #doc{deleted = true, revs = Rev, body = Body, meta = Meta}}, {SeqAcc, Results}) ->
(
{Id, Seq, #doc{deleted = true, revs = Rev, body = Body, meta = Meta}},
{SeqAcc, Results}
) ->
% _access needs deleted docs
case IdxName of
<<"_design/_access">> ->
Expand Down
3 changes: 2 additions & 1 deletion src/couch_mrview/src/couch_mrview_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,8 @@ reduce_to_count(Reductions) ->
get_access_row_count(#mrview{btree = Bt}, UserName) ->
couch_btree:full_reduce_with_options(Bt, [
{start_key, UserName},
{end_key, {[UserName, {[]}]}} % is this correct? should this not be \ufff0?
% is this correct? should this not be \ufff0?
{end_key, {[UserName, {[]}]}}
]).

fold(#mrview{btree = Bt}, Fun, Acc, Opts) ->
Expand Down
3 changes: 2 additions & 1 deletion src/couch_replicator/src/couch_replicator.erl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ replicate(PostBody, Ctx) ->
false ->
check_authorization(RepId, UserCtx),
{ok, Listener} = rep_result_listener(RepId),
Result = % fudge replication id
% fudge replication id
Result =
case do_replication_loop(Rep) of
{ok, {ResultJson}} ->
% TODO: check with options
Expand Down

0 comments on commit 123e08d

Please sign in to comment.