[gnome-photos/wip/rishi/thumbnailer: 14/15] base-item: Delete the thumbnail if create_thumbnail was cancelled



commit ec1abc2d977cef16e22a47b23f7b9c1dc1de515b
Author: Debarshi Ray <debarshir gnome org>
Date:   Wed Feb 22 20:10:41 2017 +0100

    base-item: Delete the thumbnail if create_thumbnail was cancelled
    
    In a subsequent patch, any ongoing thumbnailing job will be cancelled
    when the pipeline is saved so that a new thumbnail can be created to
    reflect the edited state of the item. We want to ensure that there are
    no remnants from the cancelled operation before submitting a new one.
    Since all thumbnailing operations are serialized in a single-threaded
    GThreadPool, this will guarantee that any leftover has been cleaned up
    before the new operation commences.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=763329

 src/photos-base-item.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)
---
diff --git a/src/photos-base-item.c b/src/photos-base-item.c
index d0d64b1..33c3a42 100644
--- a/src/photos-base-item.c
+++ b/src/photos-base-item.c
@@ -439,15 +439,31 @@ photos_base_item_create_thumbnail_in_thread_func (gpointer data, gpointer user_d
 {
   GTask *task = G_TASK (data);
   PhotosBaseItem *self;
+  PhotosBaseItemPrivate *priv;
   GCancellable *cancellable;
   GError *error;
 
   self = PHOTOS_BASE_ITEM (g_task_get_source_object (task));
+  priv = photos_base_item_get_instance_private (self);
+
   cancellable = g_task_get_cancellable (task);
 
   error = NULL;
   if (!PHOTOS_BASE_ITEM_GET_CLASS (self)->create_thumbnail (self, cancellable, &error))
     {
+      if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+        {
+          GFile *file;
+          gchar *path = NULL;
+
+          path = photos_utils_get_thumbnail_path_for_uri (priv->uri);
+          file = g_file_new_for_path (path);
+          g_file_delete (file, NULL, NULL);
+
+          g_free (path);
+          g_object_unref (file);
+        }
+
       g_task_return_error (task, error);
       goto out;
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]