Skip to content

Commit

Permalink
nautilus: clean up and fix crash after seafile exits
Browse files Browse the repository at this point in the history
  • Loading branch information
Chilledheart committed May 16, 2015
1 parent dcfb29d commit a990004
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 3 deletions.
50 changes: 48 additions & 2 deletions nautilus-seafile/nautilus-seafile.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 ();
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
}

4 changes: 3 additions & 1 deletion nautilus-seafile/seafile-rpc-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit a990004

Please sign in to comment.