From a9900041033104be84e09b3fd398cdff18b83278 Mon Sep 17 00:00:00 2001 From: Chilledheart Date: Sat, 16 May 2015 17:43:25 +0800 Subject: [PATCH] nautilus: clean up and fix crash after seafile exits --- nautilus-seafile/nautilus-seafile.c | 50 +++++++++++++++++++++++++-- nautilus-seafile/seafile-rpc-client.c | 4 ++- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/nautilus-seafile/nautilus-seafile.c b/nautilus-seafile/nautilus-seafile.c index c6c63f28b..d94b6f09f 100644 --- a/nautilus-seafile/nautilus-seafile.c +++ b/nautilus-seafile/nautilus-seafile.c @@ -14,6 +14,7 @@ static guint kUpdateFileStatusInterval = 2 * 1000; static void start_autoconnect_rpc_client (); static GObject* find_repo (const char* path); static gboolean update_file_status_by_file (SearpcClient *client, NautilusFileInfo *file); +static void clean_up_all_data (); static GList *watch_set_ = NULL; static GHashTable *file_status_ = NULL; @@ -207,6 +208,7 @@ static void stop_update_watch_set (gpointer data) { is_watch_set_started = FALSE; /* we get disconnected */ + clean_up_all_data (); start_autoconnect_rpc_client (); } @@ -422,7 +424,7 @@ static __inline const char* get_path_status_from_state(const char *state) return ""; } -static void update_file_status_for_repo (SearpcClient *client, GObject *repo, const char *status_hint) +static void update_file_status_for_repo (GObject *repo, const char *status_hint, SearpcClient *client) { char *worktree; char *repo_id; @@ -504,7 +506,7 @@ static gboolean update_watch_set (gpointer data) GList *head = watch_set_; while (head) { - update_file_status_for_repo (client, head->data, NULL); + update_file_status_for_repo (head->data, NULL, client); head = head->next; } } @@ -533,3 +535,47 @@ static GObject* find_repo (const char* path) return head ? head->data : NULL; } +static void clean_up_all_data () +{ + GHashTableIter iter; + gpointer key, value; + + /* clean up file info */ + GFile *gfile; + NautilusFileInfo *file; + g_hash_table_iter_init (&iter, file_status_); + while (g_hash_table_iter_next (&iter, &key, &value)) + { + gfile = g_file_new_for_path ((const char*)key); + if (!gfile) + { + continue; + } + file = nautilus_file_info_lookup (gfile); + if (!file) + { + g_object_unref (gfile); + continue; + } + nautilus_file_info_invalidate_extension_info (file); + g_object_unref (file); + g_object_unref (gfile); + } + g_hash_table_remove_all (file_status_); + + /* clean up watch set */ + if (watch_set_) + { + GList *head = watch_set_; + while (head) + { + GObject *repo = head->data; + update_file_status_for_repo (repo, "none", NULL); + g_object_unref (head->data); + head = head->next; + } + g_list_free (watch_set_); + watch_set_ = NULL; + } +} + diff --git a/nautilus-seafile/seafile-rpc-client.c b/nautilus-seafile/seafile-rpc-client.c index ed675d573..7bc2c06a1 100644 --- a/nautilus-seafile/seafile-rpc-client.c +++ b/nautilus-seafile/seafile-rpc-client.c @@ -56,6 +56,8 @@ void seafile_rpc_instance_disconnect () { return; } - g_object_unref (rpc_client_); + g_free (rpc_client_); g_object_unref (sync_client_); + rpc_client_ = NULL; + sync_client_ = NULL; }