Mercurial > kallithea
changeset 5618:82ed7ad0dc48
Merge stable
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Tue, 05 Jan 2016 16:30:05 +0100 |
parents | eb072b2cfa18 (current diff) 964aa663deca (diff) |
children | 6353b5e87091 |
files | kallithea/__init__.py kallithea/lib/middleware/simplegit.py kallithea/lib/middleware/simplehg.py kallithea/model/db.py |
diffstat | 5 files changed, 33 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/kallithea/__init__.py Fri Dec 25 13:50:37 2015 +0100 +++ b/kallithea/__init__.py Tue Jan 05 16:30:05 2016 +0100 @@ -93,3 +93,9 @@ __version__ += VERSION[4] else: __version__ += '0' + +# Hack for making the celery dependency kombu==1.5.1 compatible with Python +# 2.7.11 which has https://hg.python.org/releases/2.7.11/rev/24bdc4940e81 +import uuid +if not hasattr(uuid, '_uuid_generate_random'): + uuid._uuid_generate_random = None
--- a/kallithea/lib/middleware/simplegit.py Fri Dec 25 13:50:37 2015 +0100 +++ b/kallithea/lib/middleware/simplegit.py Tue Jan 05 16:30:05 2016 +0100 @@ -38,7 +38,7 @@ HTTPNotAcceptable from kallithea.model.db import User, Ui -from kallithea.lib.utils2 import safe_str, fix_PATH, get_server_url, \ +from kallithea.lib.utils2 import safe_str, safe_unicode, fix_PATH, get_server_url, \ _set_extras from kallithea.lib.base import BaseVCSController, WSGIResultCloseCallback from kallithea.lib.utils import make_ui, is_valid_repo @@ -79,9 +79,11 @@ # EXTRACT REPOSITORY NAME FROM ENV #====================================================================== try: - repo_name = self.__get_repository(environ) + str_repo_name = self.__get_repository(environ) + repo_name = safe_unicode(str_repo_name) log.debug('Extracted repo name is %s', repo_name) - except Exception: + except Exception as e: + log.error('error extracting repo_name: %r', e) return HTTPInternalServerError()(environ, start_response) # quick check if that dir exists... @@ -176,7 +178,6 @@ #=================================================================== # GIT REQUEST HANDLING #=================================================================== - str_repo_name = safe_str(repo_name) repo_path = os.path.join(safe_str(self.basepath),str_repo_name) log.debug('Repository path is %s', repo_path)
--- a/kallithea/lib/middleware/simplehg.py Fri Dec 25 13:50:37 2015 +0100 +++ b/kallithea/lib/middleware/simplehg.py Tue Jan 05 16:30:05 2016 +0100 @@ -37,7 +37,7 @@ HTTPNotAcceptable from kallithea.model.db import User -from kallithea.lib.utils2 import safe_str, fix_PATH, get_server_url, \ +from kallithea.lib.utils2 import safe_str, safe_unicode, fix_PATH, get_server_url, \ _set_extras from kallithea.lib.base import BaseVCSController, WSGIResultCloseCallback from kallithea.lib.utils import make_ui, is_valid_repo, ui_sections @@ -83,9 +83,13 @@ # EXTRACT REPOSITORY NAME FROM ENV #====================================================================== try: - repo_name = environ['REPO_NAME'] = self.__get_repository(environ) + str_repo_name = environ['REPO_NAME'] = self.__get_repository(environ) + assert isinstance(str_repo_name, str) + repo_name = safe_unicode(str_repo_name) + assert safe_str(repo_name) == str_repo_name, (str_repo_name, repo_name) log.debug('Extracted repo name is %s', repo_name) - except Exception: + except Exception as e: + log.error('error extracting repo_name: %r', e) return HTTPInternalServerError()(environ, start_response) # quick check if that dir exists... @@ -179,7 +183,6 @@ #====================================================================== # MERCURIAL REQUEST HANDLING #====================================================================== - str_repo_name = safe_str(repo_name) repo_path = os.path.join(safe_str(self.basepath), str_repo_name) log.debug('Repository path is %s', repo_path)
--- a/kallithea/model/db.py Fri Dec 25 13:50:37 2015 +0100 +++ b/kallithea/model/db.py Tue Jan 05 16:30:05 2016 +0100 @@ -34,6 +34,7 @@ import collections import functools +import sqlalchemy from sqlalchemy import * from sqlalchemy.ext.hybrid import hybrid_property from sqlalchemy.orm import relationship, joinedload, class_mapper, validates @@ -1457,7 +1458,7 @@ def __get_instance(self): repo_full_path = self.repo_full_path - alias = get_scm(repo_full_path)[0] + alias = get_scm(safe_str(repo_full_path))[0] log.debug('Creating instance of %s repository from %s', alias, repo_full_path) backend = get_backend(alias) @@ -2132,19 +2133,22 @@ return True inv_obj = cls.query().filter(cls.cache_key == cache_key).scalar() - if not inv_obj: + if inv_obj is None: inv_obj = CacheInvalidation(cache_key, repo_name) - if inv_obj.cache_active: + elif inv_obj.cache_active: return True inv_obj.cache_active = True Session().add(inv_obj) try: Session().commit() - except exc.IntegrityError: + except sqlalchemy.exc.IntegrityError: + log.error('commit of CacheInvalidation failed - retrying') + Session().rollback() inv_obj = cls.query().filter(cls.cache_key == cache_key).scalar() - if not inv_obj: - raise - # TOCTOU - another thread added the key at the same time; no further action required + if inv_obj is None: + log.error('failed to create CacheInvalidation entry') + # TODO: fail badly? + # else: TOCTOU - another thread added the key at the same time; no further action required return False @classmethod
--- a/kallithea/model/repo.py Fri Dec 25 13:50:37 2015 +0100 +++ b/kallithea/model/repo.py Tue Jan 05 16:30:05 2016 +0100 @@ -742,8 +742,8 @@ """ log.info('renaming repo from %s to %s', old, new) - old_path = os.path.join(self.repos_path, old) - new_path = os.path.join(self.repos_path, new) + old_path = safe_str(os.path.join(self.repos_path, old)) + new_path = safe_str(os.path.join(self.repos_path, new)) if os.path.isdir(new_path): raise Exception( 'Was trying to rename to already existing dir %s' % new_path @@ -758,7 +758,7 @@ :param repo: repo object """ - rm_path = os.path.join(self.repos_path, repo.repo_name) + rm_path = safe_str(os.path.join(self.repos_path, repo.repo_name)) log.info("Removing %s", rm_path) _now = datetime.now() @@ -768,4 +768,4 @@ if repo.group: args = repo.group.full_path_splitted + [_d] _d = os.path.join(*args) - shutil.move(rm_path, os.path.join(self.repos_path, _d)) + shutil.move(rm_path, safe_str(os.path.join(self.repos_path, _d)))