Improve handling of file-not-found in remote storage layer.
authorMichael Vrable <mvrable@cs.ucsd.edu>
Thu, 20 Nov 2008 23:38:39 +0000 (15:38 -0800)
committerMichael Vrable <mvrable@turin.ucsd.edu>
Thu, 20 Nov 2008 23:38:39 +0000 (15:38 -0800)
Implement a single NotFoundError which is thrown whenever a file does not
exist in any remote store, instead instance-specific error handling.

python/cumulus/store/__init__.py
python/cumulus/store/file.py
python/cumulus/store/s3.py

index 08b4517..7c43b69 100644 (file)
@@ -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."""
 
index 6034835..6b16fb6 100644 (file)
@@ -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
index 9fa006e..1e7257a 100644 (file)
@@ -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)}