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:
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
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)
# 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
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()"""
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(