Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

handle non repo matches

  • Loading branch information...
commit 206c8ef2f6c178515a007de434ac77475115a0e9 1 parent deb662d
@mojombo authored
Showing with 29 additions and 14 deletions.
  1. +9 −7 elibs/conf.erl
  2. +20 −7 elibs/upload_pack.erl
View
16 elibs/conf.erl
@@ -10,13 +10,15 @@ read_conf(Conf) ->
convert_path(Host, Path) ->
[{Host, {Regex, Transform}}] = ets:lookup(db, Host),
- M = re:smatch(Path, Regex),
- % io:format("smatch(~p, ~p) = ~p~n", [Host, Path, M]),
- {match, _A, _B, _C, MatchesTuple} = M,
- Matches = tuple_to_list(MatchesTuple),
- Binding = create_binding(Matches),
- % io:format("binding = ~p~n", [Binding]),
- eval_erlang_expr(Transform, Binding).
+ case re:smatch(Path, Regex) of
+ {match, _A, _B, _C, MatchesTuple} ->
+ Matches = tuple_to_list(MatchesTuple),
+ Binding = create_binding(Matches),
+ % io:format("binding = ~p~n", [Binding]),
+ eval_erlang_expr(Transform, Binding);
+ nomatch ->
+ {error, nomatch}
+ end.
%% INTERNAL
View
27 elibs/upload_pack.erl
@@ -5,16 +5,25 @@ handle(Sock, Host, Header) ->
try
handle_upload_pack_impl(Sock, Host, Header)
catch
- throw:{no_such_repo, Repo} ->
- handle_upload_pack_nosuchrepo(Sock, Repo);
- throw:{permission_denied, Repo} ->
- handle_upload_pack_permission_denied(Sock, Repo)
+ throw: {no_repo_match, Repo} ->
+ handle_error_no_repo_match(Sock, Repo);
+ throw: {no_such_repo, Repo} ->
+ handle_error_no_such_repo(Sock, Repo);
+ throw: {permission_denied, Repo} ->
+ handle_error_permission_denied(Sock, Repo)
end.
handle_upload_pack_impl(Sock, Host, Header) ->
% extract and normalize the repo path
{ok, Path} = extract_repo_path(Header),
- {ok, FullPath} = conf:convert_path(Host, Path),
+
+ {Label, Value} = conf:convert_path(Host, Path),
+ case {Label, Value} of
+ {ok, ConvertedFullPath} -> ok;
+ {error, nomatch} -> throw({no_repo_match, Path})
+ end,
+
+ FullPath = Value,
% io:format("fullpath = ~p~n", [FullPath]),
@@ -77,11 +86,15 @@ safe_port_close(Port) ->
_:_ -> ok
end.
-handle_upload_pack_nosuchrepo(Sock, Repo) ->
+handle_error_no_repo_match(Sock, Repo) ->
+ error_logger:info_msg("no repo match: ~p~n", [Repo]),
+ ok = gen_tcp:close(Sock).
+
+handle_error_no_such_repo(Sock, Repo) ->
error_logger:info_msg("no such repo: ~p~n", [Repo]),
ok = gen_tcp:close(Sock).
-handle_upload_pack_permission_denied(Sock, Repo) ->
+handle_error_permission_denied(Sock, Repo) ->
error_logger:info_msg("permission denied to repo: ~p~n", [Repo]),
ok = gen_tcp:close(Sock).
Please sign in to comment.
Something went wrong with that request. Please try again.