diff options
author | Rok Mandeljc <rok.mandeljc@gmail.com> | 2014-07-26 23:41:06 +0200 |
---|---|---|
committer | Philip Langdale <philipl@overt.org> | 2014-07-26 20:48:27 -0700 |
commit | f92fbc0f481f41c04fd61fa4c061c418cc3a0c8c (patch) | |
tree | 795bbd5e58a1240e06c0a80a65a46499075c8d92 | |
parent | 0f84e858fd236412fda7c5d3837fefb79ac442e1 (diff) | |
download | gvfs-f92fbc0f481f41c04fd61fa4c061c418cc3a0c8c.tar.gz |
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>
-rw-r--r-- | daemon/gvfsbackendmtp.c | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/daemon/gvfsbackendmtp.c b/daemon/gvfsbackendmtp.c index 16a504a8..bbd2433d 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; } |