[rhythmbox] android: improve error handling in the scan process a bit



commit ac923235c705e8eb9d439172c74710688407e8a8
Author: Jonathan Matthew <jonathan d14n org>
Date:   Sat Aug 22 21:48:48 2020 +1000

    android: improve error handling in the scan process a bit
    
    If the source is selected multiple times while still mounting the
    volume, bail out rather than trying to scan for music files
    repeatedly.
    
    In callbacks for the operations used to look for music directories,
    don't access the source until we've determined that the operation
    wasn't cancelled - if it was, the source has been disposed, so
    it can't be accessed.

 plugins/android/rb-android-source.c | 31 +++++++++++++++++++++++++------
 1 file changed, 25 insertions(+), 6 deletions(-)
---
diff --git a/plugins/android/rb-android-source.c b/plugins/android/rb-android-source.c
index b6f636663..8b207d711 100644
--- a/plugins/android/rb-android-source.c
+++ b/plugins/android/rb-android-source.c
@@ -214,8 +214,8 @@ music_dirs_done (RBAndroidSource *source)
 static void
 enum_files_cb (GObject *obj, GAsyncResult *result, gpointer data)
 {
-       RBAndroidSource *source = RB_ANDROID_SOURCE (data);
-       RBAndroidSourcePrivate *priv = GET_PRIVATE(source);
+       RBAndroidSource *source;
+       RBAndroidSourcePrivate *priv;
        GFileEnumerator *e = G_FILE_ENUMERATOR (obj);
        GError *error = NULL;
        GFileInfo *info;
@@ -225,10 +225,16 @@ enum_files_cb (GObject *obj, GAsyncResult *result, gpointer data)
        files = g_file_enumerator_next_files_finish (e, result, &error);
        if (error != NULL) {
                rb_debug ("error listing files: %s", error->message);
-               music_dirs_done (source);
+               if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
+                       music_dirs_done (RB_ANDROID_SOURCE (data));
+               }
+               g_clear_error (&error);
                return;
        }
 
+       source = RB_ANDROID_SOURCE (data);
+       priv = GET_PRIVATE(source);
+
        if (files == NULL) {
                priv->scanned++;
                g_object_unref (e);
@@ -276,19 +282,23 @@ enum_files_cb (GObject *obj, GAsyncResult *result, gpointer data)
 static void
 enum_child_cb (GObject *obj, GAsyncResult *result, gpointer data)
 {
-       RBAndroidSource *source = RB_ANDROID_SOURCE (data);
-       RBAndroidSourcePrivate *priv = GET_PRIVATE(source);
+       RBAndroidSource *source;
+       RBAndroidSourcePrivate *priv;
        GFileEnumerator *e;
        GError *error = NULL;
 
        e = g_file_enumerate_children_finish (G_FILE (obj), result, &error);
        if (e == NULL) {
                rb_debug ("enum error: %s", error->message);
+               if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
+                       music_dirs_done (RB_ANDROID_SOURCE (data));
+               }
                g_clear_error (&error);
-               music_dirs_done (source);
                return;
        }
 
+       source = RB_ANDROID_SOURCE (data);
+       priv = GET_PRIVATE(source);
        g_file_enumerator_next_files_async (e, 64, G_PRIORITY_DEFAULT, priv->cancel, enum_files_cb, source);
 }
 
@@ -370,6 +380,10 @@ actually_load (RBAndroidSource *source)
        char *name;
        char *label;
 
+       if (priv->loaded) {
+               rb_debug ("already loading");
+               return;
+       }
        priv->loaded = TRUE;
        rb_media_player_source_load (RB_MEDIA_PLAYER_SOURCE (source));
 
@@ -1031,6 +1045,11 @@ impl_dispose (GObject *object)
 {
        RBAndroidSourcePrivate *priv = GET_PRIVATE (object);
 
+       if (priv->cancel != NULL) {
+               g_cancellable_cancel (priv->cancel);
+               g_clear_object (&priv->cancel);
+       }
+
        if (priv->db != NULL) {
                if (priv->ignore_type != NULL) {
                        rhythmdb_entry_delete_by_type (priv->db, priv->ignore_type);


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