summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJannis Pohlmann <jannis.pohlmann@codethink.co.uk>2012-04-18 13:55:32 +0100
committerJannis Pohlmann <jannis.pohlmann@codethink.co.uk>2012-04-18 13:55:32 +0100
commit63927c35611bf56a1fce03750e953ec5250fb282 (patch)
tree76ef3cf6ab81b3fb67cf405828573a3532f02eae
parent9ba282863b41bea8d9fe990a9aba92677e2f4501 (diff)
downloadmorph-cache-server-63927c35611bf56a1fce03750e953ec5250fb282.tar.gz
Raise a RepositoryNotFoundError if a repo does not exist in the cache.
-rwxr-xr-xmorph-cache-server2
-rw-r--r--morphcacheserver/repocache.py12
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: