fixing bug #255 as Joar and CWebber ask me to do :)
authorJorge Araya Navarro <jorgean@lavabit.com>
Fri, 29 Jun 2012 04:13:26 +0000 (22:13 -0600)
committerJorge Araya Navarro <jorgean@lavabit.com>
Fri, 29 Jun 2012 04:13:26 +0000 (22:13 -0600)
mediagoblin/storage/filestorage.py
mediagoblin/tools/files.py
mediagoblin/user_pages/views.py

index 1252a3f57f7ff8a6e979ed6796909e11f1c4c0c4..00d6335ef8ece3a9a3429a6035117ba6fd5b2879 100644 (file)
@@ -64,12 +64,7 @@ class BasicFileStorage(StorageInterface):
     def delete_file(self, filepath):
         # TODO: Also delete unused directories if empty (safely, with
         # checks to avoid race conditions).
-        try:
-            os.remove(self._resolve_filepath(filepath))
-        except OSError:
-            # the file do not exists!
-            # This should fix bug #255
-            pass
+        os.remove(self._resolve_filepath(filepath))
 
     def file_url(self, filepath):
         if not self.base_url:
index 25c1a6e6f1bab9f565effd6d8a95358f407b8548..31a7a97231fe810d71c504021666f98fbb886a38 100644 (file)
 
 from mediagoblin import mg_globals
 
+import os
+
+def _jointhat(thing):
+    if type(thing) == type(list()) or\
+            type(thing) == type(tuple()):
+        filepath = ""
+        for item in thing:
+            filepath = os.path.join(filepath, item)
+        return filepath
+    else:
+        raise TypeError, "expecting a list or tuple, {0} received".format(
+            str(type(thing)))
+
 def delete_media_files(media):
     """
     Delete all files associated with a MediaEntry
@@ -23,10 +36,21 @@ def delete_media_files(media):
     Arguments:
      - media: A MediaEntry document
     """
+    noSuchFiles = []
     for listpath in media.media_files.itervalues():
-        mg_globals.public_store.delete_file(
-            listpath)
+        try:
+            mg_globals.public_store.delete_file(
+                listpath)
+        except OSError:
+            noSuchFiles.append(_jointhat(listpath))
 
     for attachment in media.attachment_files:
-        mg_globals.public_store.delete_file(
-            attachment['filepath'])
+        try:
+            mg_globals.public_store.delete_file(
+                attachment['filepath'])
+        except OSError:
+            noSuchFiles.append(_jointhat(attachment))
+
+    if noSuchFiles:
+        # This breaks pep8 as far as I know
+        raise OSError, ", ".join(noSuchFiles)
index dad68ba54374f3cfc5fe62ea37898696a3aef853..870e215548a6b4f421d3077fac6305e6ab3ddd3f 100644 (file)
@@ -15,6 +15,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 from webob import exc
+import logging
 
 from mediagoblin import messages, mg_globals
 from mediagoblin.db.util import DESCENDING, ObjectId
@@ -33,6 +34,9 @@ from werkzeug.contrib.atom import AtomFeed
 from mediagoblin.media_types import get_media_manager
 
 
+_log = logging.getLogger(__name__)
+_log.setLevel(logging.DEBUG)
+
 @uses_pagination
 def user_home(request, page):
     """'Homepage' of a User()"""
@@ -185,7 +189,14 @@ def media_confirm_delete(request, media):
                 comment.delete()
 
             # Delete all files on the public storage
-            delete_media_files(media)
+            try:
+                delete_media_files(media)
+            except OSError, error:
+                _log.error('No such files from the user "{1}"'
+                           ' to delete: {0}'.format(str(error), username))
+                messages.add_message(request, messages.ERROR,
+                                     _('Some of the files with this entry seem'
+                                       ' to be missing.  Deleting anyway.'))
 
             media.delete()
             messages.add_message(