From: Michael Vrable Date: Thu, 20 Nov 2008 23:38:39 +0000 (-0800) Subject: Improve handling of file-not-found in remote storage layer. X-Git-Url: http://git.vrable.net/?p=cumulus.git;a=commitdiff_plain;h=c519cb09affc7e3235a7d75c349ef4cdddc778e0 Improve handling of file-not-found in remote storage layer. Implement a single NotFoundError which is thrown whenever a file does not exist in any remote store, instead instance-specific error handling. --- diff --git a/python/cumulus/store/__init__.py b/python/cumulus/store/__init__.py index 08b4517..7c43b69 100644 --- a/python/cumulus/store/__init__.py +++ b/python/cumulus/store/__init__.py @@ -1,4 +1,4 @@ -import re, urlparse +import exceptions, re, urlparse type_patterns = { 'checksums': re.compile(r"^snapshot-(.*)\.(\w+)sums$"), @@ -6,6 +6,11 @@ type_patterns = { 'snapshots': re.compile(r"^snapshot-(.*)\.lbs$") } +class NotFoundError(exceptions.KeyError): + """Exception thrown when a file is not found in a repository.""" + + pass + class Store: """Base class for all cumulus storage backends.""" diff --git a/python/cumulus/store/file.py b/python/cumulus/store/file.py index 6034835..6b16fb6 100644 --- a/python/cumulus/store/file.py +++ b/python/cumulus/store/file.py @@ -33,5 +33,8 @@ class FileStore(cumulus.store.Store): os.unlink(k) def stat(self, type, name): - stat = os.stat(self._get_path(type, name)) - return {'size': stat.st_size} + try: + stat = os.stat(self._get_path(type, name)) + return {'size': stat.st_size} + except OSError: + raise cumulus.store.NotFoundError diff --git a/python/cumulus/store/s3.py b/python/cumulus/store/s3.py index 9fa006e..1e7257a 100644 --- a/python/cumulus/store/s3.py +++ b/python/cumulus/store/s3.py @@ -39,4 +39,6 @@ class S3Store(cumulus.store.Store): def stat(self, type, name): k = self.bucket.get_key("%s/%s/%s" % (self.prefix, type, name)) + if k is None: + raise cumulus.store.NotFoundError return {'size': int(k.size)}