Convert media processing backends to delete the queue directory (#254)
authorSebastian Spaeth <Sebastian@SSpaeth.de>
Wed, 12 Dec 2012 15:32:43 +0000 (16:32 +0100)
committerChristopher Allan Webber <cwebber@dustycloud.org>
Tue, 22 Jan 2013 20:05:54 +0000 (14:05 -0600)
We never deleted our queue directory which were created per submission.
With the FileStorage backend being able to delete directories now, we can
request the deletion of the task directory too. It will only be deleted if
it is completely empty.

mediagoblin/media_types/ascii/processing.py
mediagoblin/media_types/audio/processing.py
mediagoblin/media_types/image/processing.py
mediagoblin/media_types/stl/processing.py
mediagoblin/media_types/video/processing.py

index 254717ebf725ab627819e0ca1688a0e41f0515ee..dbc9661e2ced3df5cc25abaf45121facb8bb876b 100644 (file)
@@ -127,8 +127,14 @@ def process_ascii(entry, workbench=None):
                     'ascii',
                     'xmlcharrefreplace'))
 
-    mgg.queue_store.delete_file(queued_filepath)
+    # Remove queued media file from storage and database.
+    # queued_filepath is in the task_id directory which should
+    # be removed too, but fail if the directory is not empty to be on
+    # the super-safe side.
+    mgg.queue_store.delete_file(queued_filepath)      # rm file
+    mgg.queue_store.delete_dir(queued_filepath[:-1])  # rm dir
     entry.queued_media_file = []
+
     media_files_dict = entry.setdefault('media_files', {})
     media_files_dict['thumb'] = thumb_filepath
     media_files_dict['unicode'] = unicode_filepath
index e12cefe659a48cae0d7e42e6505b08394eaf2463..a89d6634701a09e5d7d96b5c3bf0925996e77194 100644 (file)
@@ -147,4 +147,10 @@ def process_audio(entry, workbench=None):
     else:
         entry.media_files['thumb'] = ['fake', 'thumb', 'path.jpg']
 
-    mgg.queue_store.delete_file(queued_filepath)
+    # Remove queued media file from storage and database.
+    # queued_filepath is in the task_id directory which should
+    # be removed too, but fail if the directory is not empty to be on
+    # the super-safe side.
+    mgg.queue_store.delete_file(queued_filepath)      # rm file
+    mgg.queue_store.delete_dir(queued_filepath[:-1])  # rm dir
+    entry.queued_media_file = []
index e6a34ca004e44a3f011f3fcdcba96b1d27629948..2a5c463ec72976be65e83e015275444be0bc28d1 100644 (file)
@@ -128,8 +128,12 @@ def process_image(entry, workbench=None):
             entry, name_builder.fill('{basename}{ext}'))
     mgg.public_store.copy_local_to_storage(queued_filename, original_filepath)
 
-    # Remove queued media file from storage and database
-    mgg.queue_store.delete_file(queued_filepath)
+    # Remove queued media file from storage and database.
+    # queued_filepath is in the task_id directory which should
+    # be removed too, but fail if the directory is not empty to be on
+    # the super-safe side.
+    mgg.queue_store.delete_file(queued_filepath)      # rm file
+    mgg.queue_store.delete_dir(queued_filepath[:-1])  # rm dir
     entry.queued_media_file = []
 
     # Insert media file information into database
index 3089f29512d917461a8dc19212a87001c76f9ba6..12b87317e967600b53f79859037a65a90ea28062 100644 (file)
@@ -164,8 +164,12 @@ def process_stl(entry, workbench=None):
         with open(queued_filename, 'rb') as queued_file:
             model_file.write(queued_file.read())
 
-    # Remove queued media file from storage and database
-    mgg.queue_store.delete_file(queued_filepath)
+    # Remove queued media file from storage and database.
+    # queued_filepath is in the task_id directory which should
+    # be removed too, but fail if the directory is not empty to be on
+    # the super-safe side.
+    mgg.queue_store.delete_file(queued_filepath)      # rm file
+    mgg.queue_store.delete_dir(queued_filepath[:-1])  # rm dir
     entry.queued_media_file = []
 
     # Insert media file information into database
index 4c9f01319edff3ec688b3a8e095b0f39145e826e..68d14148af97aa281fd5f6ed4796cda2548e960d 100644 (file)
@@ -121,4 +121,10 @@ def process_video(entry, workbench=None):
         mgg.public_store.copy_local_to_storage(queued_filename, original_filepath)
         entry.media_files['original'] = original_filepath
 
-    mgg.queue_store.delete_file(queued_filepath)
+    # Remove queued media file from storage and database.
+    # queued_filepath is in the task_id directory which should
+    # be removed too, but fail if the directory is not empty to be on
+    # the super-safe side.
+    mgg.queue_store.delete_file(queued_filepath)      # rm file
+    mgg.queue_store.delete_dir(queued_filepath[:-1])  # rm dir
+    entry.queued_media_file = []