From 63927c35611bf56a1fce03750e953ec5250fb282 Mon Sep 17 00:00:00 2001 From: Jannis Pohlmann Date: Wed, 18 Apr 2012 13:55:32 +0100 Subject: Raise a RepositoryNotFoundError if a repo does not exist in the cache. --- morph-cache-server | 2 +- morphcacheserver/repocache.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/morph-cache-server b/morph-cache-server index 777e627..b13241b 100755 --- a/morph-cache-server +++ b/morph-cache-server @@ -41,7 +41,7 @@ class MorphCacheServer(cliapp.Application): app = Bottle() repo_cache = RepoCache(self, self.settings['repo-dir']) - + @app.get('/sha1s') def sha1(): repo = self._unescape_parameter(request.query.repo) diff --git a/morphcacheserver/repocache.py b/morphcacheserver/repocache.py index 49b8200..1b6862c 100644 --- a/morphcacheserver/repocache.py +++ b/morphcacheserver/repocache.py @@ -19,6 +19,13 @@ import os import string +class RepositoryNotFoundError(cliapp.AppException): + + def __init__(self, repo): + cliapp.AppException.__init__( + self, 'Repository %s does not exist in the cache' % repo) + + class InvalidReferenceError(cliapp.AppException): def __init__(self, repo, ref): @@ -44,6 +51,8 @@ class RepoCache(object): def resolve_ref(self, repo_url, ref): quoted_url = self._quote_url(repo_url) repo_dir = os.path.join(self.dirname, quoted_url) + if not os.path.exists(repo_dir): + raise RepositoryNotFoundError(repo_url) try: refs = self._show_ref(repo_dir, ref).split('\n') refs = [x.split() for x in refs if 'origin' in x] @@ -60,9 +69,10 @@ class RepoCache(object): def cat_file(self, repo_url, ref, filename): quoted_url = self._quote_url(repo_url) repo_dir = os.path.join(self.dirname, quoted_url) - if not self._is_valid_sha1(ref): raise UnresolvedNamedReferenceError(repo_url, ref) + if not os.path.exists(repo_dir): + raise RepositoryNotFoundError(repo_url) try: sha1 = self._rev_list(repo_dir, ref).strip() except: -- cgit v1.2.1