[rhythmbox] podcast: don't set status on current download when cancelling



commit 1b8ff842e2a3d942de8e74507fdf829955bad6d5
Author: Jonathan Matthew <jonathan d14n org>
Date:   Thu Oct 15 16:13:08 2020 +1000

    podcast: don't set status on current download when cancelling
    
    This can race with the download task, so we should wait until the
    task callback instead.

 podcast/rb-podcast-manager.c | 13 ++++++++-----
 podcast/rb-podcast-manager.h |  2 +-
 podcast/rb-podcast-source.c  |  7 ++++---
 3 files changed, 13 insertions(+), 9 deletions(-)
---
diff --git a/podcast/rb-podcast-manager.c b/podcast/rb-podcast-manager.c
index 33b956e7a..2b31ea86b 100644
--- a/podcast/rb-podcast-manager.c
+++ b/podcast/rb-podcast-manager.c
@@ -166,7 +166,7 @@ static void download_task                           (GTask *task,
                                                         gpointer task_data,
                                                         GCancellable *cancel);
 static void download_info_free                         (RBPodcastDownload *data);
-static void cancel_download                            (RBPodcastDownload *pd);
+static gboolean cancel_download                                (RBPodcastDownload *pd);
 static void rb_podcast_manager_start_update_timer      (RBPodcastManager *pd);
 
 G_DEFINE_TYPE (RBPodcastManager, rb_podcast_manager, G_TYPE_OBJECT)
@@ -1239,7 +1239,7 @@ rb_podcast_manager_delete_download (RBPodcastManager *pd, RhythmDBEntry *entry)
        g_object_unref (file);
 }
 
-void
+gboolean
 rb_podcast_manager_cancel_download (RBPodcastManager *pd, RhythmDBEntry *entry)
 {
        GList *lst;
@@ -1248,10 +1248,11 @@ rb_podcast_manager_cancel_download (RBPodcastManager *pd, RhythmDBEntry *entry)
        for (lst = pd->priv->download_list; lst != NULL; lst = lst->next) {
                RBPodcastDownload *data = (RBPodcastDownload *) lst->data;
                if (data->entry == entry) {
-                       cancel_download (data);
-                       return;
+                       return cancel_download (data);
                }
        }
+
+       return FALSE;
 }
 
 static void
@@ -2260,7 +2261,7 @@ download_task (GTask *task, gpointer source_object, gpointer task_data, GCancell
 }
 
 
-static void
+static gboolean
 cancel_download (RBPodcastDownload *data)
 {
        g_assert (rb_is_main_thread ());
@@ -2271,9 +2272,11 @@ cancel_download (RBPodcastDownload *data)
                g_cancellable_cancel (data->cancel);
 
                /* download data will be cleaned up after the task returns */
+               return TRUE;
        } else {
                /* destroy download data */
                data->pd->priv->download_list = g_list_remove (data->pd->priv->download_list, data);
                download_info_free (data);
+               return FALSE;
        }
 }
diff --git a/podcast/rb-podcast-manager.h b/podcast/rb-podcast-manager.h
index bdde1404e..14c3ee718 100644
--- a/podcast/rb-podcast-manager.h
+++ b/podcast/rb-podcast-manager.h
@@ -67,7 +67,7 @@ typedef struct
 GType                   rb_podcast_manager_get_type                    (void);
 RBPodcastManager*              rb_podcast_manager_new                  (RhythmDB *db);
 void                    rb_podcast_manager_download_entry      (RBPodcastManager *pd, RhythmDBEntry *entry);
-void                   rb_podcast_manager_cancel_download      (RBPodcastManager *pd, RhythmDBEntry *entry);
+gboolean               rb_podcast_manager_cancel_download      (RBPodcastManager *pd, RhythmDBEntry *entry);
 void                   rb_podcast_manager_update_feeds         (RBPodcastManager *pd);
 void                    rb_podcast_manager_start_sync                  (RBPodcastManager *pd);
 void                   rb_podcast_manager_delete_download      (RBPodcastManager *pd, RhythmDBEntry *entry);
diff --git a/podcast/rb-podcast-source.c b/podcast/rb-podcast-source.c
index ec06805fb..3e249c93b 100644
--- a/podcast/rb-podcast-source.c
+++ b/podcast/rb-podcast-source.c
@@ -453,6 +453,7 @@ podcast_download_cancel_action_cb (GSimpleAction *action, GVariant *parameter, g
 
        lst = rb_entry_view_get_selected_entries (posts);
        g_value_init (&val, G_TYPE_ULONG);
+       g_value_set_ulong (&val, RHYTHMDB_PODCAST_STATUS_PAUSED);
 
        while (lst != NULL) {
                RhythmDBEntry *entry  = (RhythmDBEntry *) lst->data;
@@ -460,9 +461,9 @@ podcast_download_cancel_action_cb (GSimpleAction *action, GVariant *parameter, g
 
                if ((status > 0 && status < RHYTHMDB_PODCAST_STATUS_COMPLETE) ||
                    status == RHYTHMDB_PODCAST_STATUS_WAITING) {
-                       g_value_set_ulong (&val, RHYTHMDB_PODCAST_STATUS_PAUSED);
-                       rhythmdb_entry_set (source->priv->db, entry, RHYTHMDB_PROP_STATUS, &val);
-                       rb_podcast_manager_cancel_download (source->priv->podcast_mgr, entry);
+                       if (rb_podcast_manager_cancel_download (source->priv->podcast_mgr, entry) == FALSE) {
+                               rhythmdb_entry_set (source->priv->db, entry, RHYTHMDB_PROP_STATUS, &val);
+                       }
                }
 
                lst = lst->next;


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