From: Matthias Clasen Date: Fri, 30 Sep 2011 03:32:20 +0000 (-0400) Subject: Prevent data loss in gdesktopappinfo.c X-Git-Tag: 2.31.0~334 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5156d1b2d42d89d7ad916ca3c53db517a2674f31;p=platform%2Fupstream%2Fglib.git Prevent data loss in gdesktopappinfo.c Don't loose the content of mimeapps.list when it doesn't contain a [Added Associations] group. Pointed out by Alexander Larsson. https://bugzilla.gnome.org/show_bug.cgi?id=660130 --- diff --git a/gio/gdesktopappinfo.c b/gio/gdesktopappinfo.c index 9b83662..22d7621 100644 --- a/gio/gdesktopappinfo.c +++ b/gio/gdesktopappinfo.c @@ -1555,7 +1555,10 @@ update_mimeapps_list (const char *desktop_id, key_file = g_key_file_new (); load_succeeded = g_key_file_load_from_file (key_file, filename, G_KEY_FILE_NONE, NULL); - if (!load_succeeded || !g_key_file_has_group (key_file, ADDED_ASSOCIATIONS_GROUP)) + if (!load_succeeded || + (!g_key_file_has_group (key_file, ADDED_ASSOCIATIONS_GROUP) && + !g_key_file_has_group (key_file, REMOVED_ASSOCIATIONS_GROUP) && + !g_key_file_has_group (key_file, DEFAULT_APPLICATIONS_GROUP))) { g_key_file_free (key_file); key_file = g_key_file_new (); @@ -1727,18 +1730,18 @@ update_mimeapps_list (const char *desktop_id, g_strfreev (list); } - g_strfreev (content_types); + g_strfreev (content_types); data = g_key_file_to_data (key_file, &data_size, error); g_key_file_free (key_file); - + res = g_file_set_contents (filename, data, data_size, error); mime_info_cache_reload (NULL); - + g_free (filename); g_free (data); - + return res; }