Show More
@@ -2,6 +2,7 b'' | |||||
2 | # encoding: utf-8 |
|
2 | # encoding: utf-8 | |
3 | # middleware to handle mercurial api calls |
|
3 | # middleware to handle mercurial api calls | |
4 | # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> |
|
4 | # Copyright (C) 2009-2010 Marcin Kuzminski <marcin@python-works.com> | |
|
5 | from mercurial.error import RepoError | |||
5 |
|
6 | |||
6 | # This program is free software; you can redistribute it and/or |
|
7 | # This program is free software; you can redistribute it and/or | |
7 | # modify it under the terms of the GNU General Public License |
|
8 | # modify it under the terms of the GNU General Public License | |
@@ -32,10 +33,11 b' from mercurial.hgweb.request import wsgi' | |||||
32 | from paste.auth.basic import AuthBasicAuthenticator |
|
33 | from paste.auth.basic import AuthBasicAuthenticator | |
33 | from paste.httpheaders import REMOTE_USER, AUTH_TYPE |
|
34 | from paste.httpheaders import REMOTE_USER, AUTH_TYPE | |
34 | from pylons_app.lib.auth import authfunc, HasPermissionAnyMiddleware |
|
35 | from pylons_app.lib.auth import authfunc, HasPermissionAnyMiddleware | |
35 | from pylons_app.lib.utils import is_mercurial, make_ui, invalidate_cache |
|
36 | from pylons_app.lib.utils import is_mercurial, make_ui, invalidate_cache, \ | |
|
37 | check_repo_fast | |||
36 | from pylons_app.model import meta |
|
38 | from pylons_app.model import meta | |
37 | from pylons_app.model.db import UserLog, User |
|
39 | from pylons_app.model.db import UserLog, User | |
38 | from webob.exc import HTTPNotFound, HTTPForbidden |
|
40 | from webob.exc import HTTPNotFound, HTTPForbidden, HTTPInternalServerError | |
39 | import logging |
|
41 | import logging | |
40 | import os |
|
42 | import os | |
41 | import traceback |
|
43 | import traceback | |
@@ -68,9 +70,9 b' class SimpleHg(object):' | |||||
68 |
|
70 | |||
69 | try: |
|
71 | try: | |
70 | repo_name = '/'.join(environ['PATH_INFO'].split('/')[1:]) |
|
72 | repo_name = '/'.join(environ['PATH_INFO'].split('/')[1:]) | |
71 |
except |
|
73 | except: | |
72 | log.error(traceback.format_exc()) |
|
74 | log.error(traceback.format_exc()) | |
73 |
return HTTP |
|
75 | return HTTPInternalServerError()(environ, start_response) | |
74 |
|
76 | |||
75 | #=================================================================== |
|
77 | #=================================================================== | |
76 | # CHECK PERMISSIONS FOR THIS REQUEST |
|
78 | # CHECK PERMISSIONS FOR THIS REQUEST | |
@@ -83,7 +85,8 b' class SimpleHg(object):' | |||||
83 | user = sa.query(User)\ |
|
85 | user = sa.query(User)\ | |
84 | .filter(User.username == username).one() |
|
86 | .filter(User.username == username).one() | |
85 | except: |
|
87 | except: | |
86 | return HTTPNotFound()(environ, start_response) |
|
88 | log.error(traceback.format_exc()) | |
|
89 | return HTTPInternalServerError()(environ, start_response) | |||
87 | #check permissions for this repository |
|
90 | #check permissions for this repository | |
88 | if action == 'pull': |
|
91 | if action == 'pull': | |
89 | if not HasPermissionAnyMiddleware('repository.read', |
|
92 | if not HasPermissionAnyMiddleware('repository.read', | |
@@ -110,11 +113,19 b' class SimpleHg(object):' | |||||
110 | self.baseui = make_ui(self.config['hg_app_repo_conf']) |
|
113 | self.baseui = make_ui(self.config['hg_app_repo_conf']) | |
111 | self.basepath = self.config['base_path'] |
|
114 | self.basepath = self.config['base_path'] | |
112 | self.repo_path = os.path.join(self.basepath, repo_name) |
|
115 | self.repo_path = os.path.join(self.basepath, repo_name) | |
|
116 | ||||
|
117 | #quick check if that dir exists... | |||
|
118 | if check_repo_fast(repo_name, self.basepath): | |||
|
119 | return HTTPNotFound()(environ, start_response) | |||
|
120 | ||||
113 | try: |
|
121 | try: | |
114 | app = wsgiapplication(self.__make_app) |
|
122 | app = wsgiapplication(self.__make_app) | |
|
123 | except RepoError as e: | |||
|
124 | if str(e).find('not found') != -1: | |||
|
125 | return HTTPNotFound()(environ, start_response) | |||
115 | except Exception: |
|
126 | except Exception: | |
116 | log.error(traceback.format_exc()) |
|
127 | log.error(traceback.format_exc()) | |
117 |
return HTTP |
|
128 | return HTTPInternalServerError()(environ, start_response) | |
118 |
|
129 | |||
119 |
|
130 | |||
120 | #invalidate cache on push |
|
131 | #invalidate cache on push |
General Comments 0
You need to be logged in to leave comments.
Login now