[gvfs] mtp: implemented support for LIBMTP_EVENT_STORE_REMOVED



commit f92fbc0f481f41c04fd61fa4c061c418cc3a0c8c
Author: Rok Mandeljc <rok mandeljc gmail com>
Date:   Sat Jul 26 23:41:06 2014 +0200

    mtp: implemented support for LIBMTP_EVENT_STORE_REMOVED
    
    This patch adds support for LIBMTP_EVENT_STORE_REMOVED, so that if a
    storage is removed, its entry and those of its children are
    automatically removed. For each such entry, delete event is also
    emitted.
    
    With this patch, the corresponding storage disappears from Nautilus
    as soon as the SD card is unmounted on device. Similarly, if Nautilus
    is located in the storage or one of its sub-folders, the window gets
    properly closed after the storage is removed.
    
    Signed-off-by: Rok Mandeljc <rok mandeljc gmail com>

 daemon/gvfsbackendmtp.c |   34 +++++++++++++++++++++++++++++++++-
 1 files changed, 33 insertions(+), 1 deletions(-)
---
diff --git a/daemon/gvfsbackendmtp.c b/daemon/gvfsbackendmtp.c
index 16a504a..bbd2433 100644
--- a/daemon/gvfsbackendmtp.c
+++ b/daemon/gvfsbackendmtp.c
@@ -354,7 +354,7 @@ remove_cache_entry_by_id (GVfsBackendMtp *backend,
     const char *path = key;
     const CacheEntry *entry = value;
 
-    if (entry->id == id) {
+    if (entry->id == id || (entry->id == -1 && entry->storage == id)) {
       g_hash_table_foreach (backend->monitors,
                             emit_delete_event,
                             (char *)path);
@@ -660,6 +660,38 @@ check_event (gpointer user_data)
         remove_cache_entry_by_id (G_VFS_BACKEND_MTP (backend), param1);
         g_mutex_unlock (&backend->mutex);
         g_object_unref (backend);
+        break;
+      } else {
+        return NULL;
+      }
+    case LIBMTP_EVENT_STORE_REMOVED:
+      backend = g_weak_ref_get (event_ref);
+      if (backend && !g_atomic_int_get (&backend->unmount_started)) {
+        g_mutex_lock (&backend->mutex);
+
+        /* Clear the cache entries and emit delete event; first for all
+           entries under the storage in question... */
+        GHashTableIter iter;
+        gpointer key, value;
+        g_hash_table_iter_init (&iter, backend->file_cache);
+        while (g_hash_table_iter_next (&iter, &key, &value)) {
+          const char *path = key;
+          const CacheEntry *entry = value;
+
+          if (entry->storage == param1) {
+            g_hash_table_foreach (backend->monitors,
+                                  emit_delete_event,
+                                  (char *)path);
+            g_hash_table_iter_remove (&iter);
+          }
+        }
+
+        /* ... and then for the storage itself */
+        remove_cache_entry_by_id (G_VFS_BACKEND_MTP (backend), param1);
+
+        g_mutex_unlock (&backend->mutex);
+        g_object_unref (backend);
+        break;
       } else {
         return NULL;
       }


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