raise an error if the file failed to copy to public storage
authorRodney Ewing <ewing.rj@gmail.com>
Wed, 14 Aug 2013 20:47:39 +0000 (13:47 -0700)
committerRodney Ewing <ewing.rj@gmail.com>
Fri, 16 Aug 2013 22:30:22 +0000 (15:30 -0700)
catch copy_local_to_storage errors and raise PublicStoreFail, saving the keyname

mediagoblin/processing/__init__.py

index 0c13e807fb7f7798e66c8706e8cb17f1d70724e1..e31b70bb3732dd0bdd916dc974518f8566a25d6d 100644 (file)
@@ -356,13 +356,24 @@ def store_public(entry, keyname, local_file, target_name=None,
     if target_name is None:
         target_name = os.path.basename(local_file)
     target_filepath = create_pub_filepath(entry, target_name)
+
     if keyname in entry.media_files:
         _log.warn("store_public: keyname %r already used for file %r, "
                   "replacing with %r", keyname,
                   entry.media_files[keyname], target_filepath)
         if delete_if_exists:
             mgg.public_store.delete_file(entry.media_files[keyname])
-    mgg.public_store.copy_local_to_storage(local_file, target_filepath)
+
+    try:
+        mgg.public_store.copy_local_to_storage(local_file, target_filepath)
+    except:
+        raise PublicStoreFail(keyname=keyname)
+
+    # raise an error if the file failed to copy
+    copied_filepath = mgg.public_store.get_local_path(target_filepath)
+    if not os.path.exists(copied_filepath):
+        raise PublicStoreFail(keyname=keyname)
+
     entry.media_files[keyname] = target_filepath
 
 
@@ -396,3 +407,10 @@ class BadMediaFail(BaseProcessingFail):
     for the media type specified.
     """
     general_message = _(u'Invalid file given for media type.')
+
+
+class PublicStoreFail(BaseProcessingFail):
+    """
+    Error that should be raised when copying to public store fails
+    """
+    general_message = _('Copying to public storage failed.')