diff options
author | Rodney Ewing <ewing.rj@gmail.com> | 2013-08-14 13:47:39 -0700 |
---|---|---|
committer | Rodney Ewing <ewing.rj@gmail.com> | 2013-08-16 15:30:22 -0700 |
commit | 79f84d7e479f6b370709c6826c85070ab1996ea6 (patch) | |
tree | 051f2715cdaebed8a38b1ed6cfef0c67eb12649d /mediagoblin/processing/__init__.py | |
parent | 100a73a298f739d345cc41d9e5260c170a408c03 (diff) | |
download | mediagoblin-79f84d7e479f6b370709c6826c85070ab1996ea6.tar.lz mediagoblin-79f84d7e479f6b370709c6826c85070ab1996ea6.tar.xz mediagoblin-79f84d7e479f6b370709c6826c85070ab1996ea6.zip |
raise an error if the file failed to copy to public storage
catch copy_local_to_storage errors and raise PublicStoreFail, saving the keyname
Diffstat (limited to 'mediagoblin/processing/__init__.py')
-rw-r--r-- | mediagoblin/processing/__init__.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/mediagoblin/processing/__init__.py b/mediagoblin/processing/__init__.py index 0c13e807..e31b70bb 100644 --- a/mediagoblin/processing/__init__.py +++ b/mediagoblin/processing/__init__.py @@ -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.') |