1764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen/* 2764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen * Copyright (C) 2008 Red Hat, Inc 3764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen * 4764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen * This library is free software; you can redistribute it and/or 5764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen * modify it under the terms of the GNU Lesser General Public 6764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen * License as published by the Free Software Foundation; either 7764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen * version 2 of the License, or (at your option) any later version. 8764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen * 9764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen * This library is distributed in the hope that it will be useful, 10764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen * but WITHOUT ANY WARRANTY; without even the implied warranty of 11764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen * Lesser General Public License for more details. 13764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen * 14764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen * You should have received a copy of the GNU Lesser General 15764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen * Public License along with this library; if not, write to the 16764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen * Free Software Foundation, Inc., 59 Temple Place, Suite 330, 17764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen * Boston, MA 02111-1307, USA. 18764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen * 19764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen * Author: Matthias Clasen 20764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen */ 21764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 22764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen#include <glib/glib.h> 23764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen#include <gio/gio.h> 24764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen#include <gio/gdesktopappinfo.h> 25764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen#include <stdlib.h> 26764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen#include <string.h> 27764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 28764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasenstatic char *basedir; 29764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 30764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasenstatic GAppInfo * 31764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasencreate_app_info (const char *name) 32764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen{ 33764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen GError *error; 34764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen GAppInfo *info; 35764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 36764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen error = NULL; 37764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen info = g_app_info_create_from_commandline ("/usr/bin/true blah", 38764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen name, 39764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen G_APP_INFO_CREATE_NONE, 40764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen &error); 41764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_assert (error == NULL); 42764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 43764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen /* this is necessary to ensure that the info is saved */ 44764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_app_info_set_as_default_for_type (info, "application/x-blah", &error); 45764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_assert (error == NULL); 46764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_app_info_remove_supports_type (info, "application/x-blah", &error); 47764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_assert (error == NULL); 48764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_app_info_reset_type_associations ("application/x-blah"); 49764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 50764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen return info; 51764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen} 52764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 53764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasenstatic void 54764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasentest_delete (void) 55764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen{ 56764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen GAppInfo *info; 57764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 58764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen const char *id; 59764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen char *filename; 60764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen gboolean res; 61764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 62764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen info = create_app_info ("Blah"); 63764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 64764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen id = g_app_info_get_id (info); 65764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_assert (id != NULL); 66764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 67764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen filename = g_build_filename (basedir, "applications", id, NULL); 68764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 69764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen res = g_file_test (filename, G_FILE_TEST_EXISTS); 70764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_assert (res); 71764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 72764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen res = g_app_info_can_delete (info); 73764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_assert (res); 74764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 75764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen res = g_app_info_delete (info); 76764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_assert (res); 77764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 78764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen res = g_file_test (filename, G_FILE_TEST_EXISTS); 79764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_assert (!res); 80764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 81764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_object_unref (info); 82764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 83764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen if (g_file_test ("/usr/share/applications/gedit.desktop", G_FILE_TEST_EXISTS)) 84764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen { 85764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen info = (GAppInfo*)g_desktop_app_info_new ("gedit.desktop"); 86764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_assert (info); 87764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 88764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen res = g_app_info_can_delete (info); 89764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_assert (!res); 90764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 91764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen res = g_app_info_delete (info); 92764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_assert (!res); 93764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen } 94764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen} 95764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 96764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasenstatic void 97764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasentest_default (void) 98764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen{ 99764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen GAppInfo *info, *info1, *info2, *info3; 100764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen GList *list; 101764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen GError *error = NULL; 102764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 103764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen info1 = create_app_info ("Blah1"); 104764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen info2 = create_app_info ("Blah2"); 105764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen info3 = create_app_info ("Blah3"); 106764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 107764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_app_info_set_as_default_for_type (info1, "application/x-test", &error); 108764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_assert (error == NULL); 109764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 110764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_app_info_set_as_default_for_type (info2, "application/x-test", &error); 111764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_assert (error == NULL); 112764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 113764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen list = g_app_info_get_all_for_type ("application/x-test"); 114764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_assert (g_list_length (list) == 2); 115764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 116764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen /* check that both are in the list, info2 before info1 */ 117764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen info = (GAppInfo *)list->data; 118764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_assert (g_strcmp0 (g_app_info_get_id (info), g_app_info_get_id (info2)) == 0); 119764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 120764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen info = (GAppInfo *)list->next->data; 121764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_assert (g_strcmp0 (g_app_info_get_id (info), g_app_info_get_id (info1)) == 0); 122764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 123764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_list_foreach (list, (GFunc)g_object_unref, NULL); 124764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_list_free (list); 125764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 126764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen /* now try adding something at the end */ 127764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_app_info_add_supports_type (info3, "application/x-test", &error); 128764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_assert (error == NULL); 129764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 130764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen list = g_app_info_get_all_for_type ("application/x-test"); 131764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_assert (g_list_length (list) == 3); 132764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 133764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen /* check that all are in the list, info2, info1, info3 */ 134764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen info = (GAppInfo *)list->data; 135764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_assert (g_strcmp0 (g_app_info_get_id (info), g_app_info_get_id (info2)) == 0); 136764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 137764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen info = (GAppInfo *)list->next->data; 138764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_assert (g_strcmp0 (g_app_info_get_id (info), g_app_info_get_id (info1)) == 0); 139764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 140764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen info = (GAppInfo *)list->next->next->data; 141764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_assert (g_strcmp0 (g_app_info_get_id (info), g_app_info_get_id (info3)) == 0); 142764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 143764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_list_foreach (list, (GFunc)g_object_unref, NULL); 144764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_list_free (list); 145764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 146764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen /* now remove info1 again */ 147764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_app_info_remove_supports_type (info1, "application/x-test", &error); 148764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_assert (error == NULL); 149764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 150764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen list = g_app_info_get_all_for_type ("application/x-test"); 151764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_assert (g_list_length (list) == 2); 152764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 153764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen /* check that both are in the list, info2 before info3 */ 154764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen info = (GAppInfo *)list->data; 155764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_assert (g_strcmp0 (g_app_info_get_id (info), g_app_info_get_id (info2)) == 0); 156764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 157764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen info = (GAppInfo *)list->next->data; 158764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_assert (g_strcmp0 (g_app_info_get_id (info), g_app_info_get_id (info3)) == 0); 159764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 160764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_list_foreach (list, (GFunc)g_object_unref, NULL); 161764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_list_free (list); 162764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 163764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen /* now clean it all up */ 164764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_app_info_reset_type_associations ("application/x-test"); 165764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 166764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen list = g_app_info_get_all_for_type ("application/x-test"); 167764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_assert (list == NULL); 168764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 169764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_app_info_delete (info1); 170764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_app_info_delete (info2); 171764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_app_info_delete (info3); 172764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 173764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_object_unref (info1); 174764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_object_unref (info2); 175764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen} 176764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 177764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasenstatic void 178764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasencleanup_dir_recurse (GFile *parent, GFile *root) 179764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen{ 180764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen gboolean res; 181764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen GError *error; 182764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen GFileEnumerator *enumerator; 183764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen GFileInfo *info; 184764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen GFile *descend; 185764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen char *relative_path; 186764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 187764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_assert (root != NULL); 188764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 189764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen error = NULL; 190764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen enumerator = 191764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_file_enumerate_children (parent, "*", 192764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen G_FILE_QUERY_INFO_NOFOLLOW_SYMLINKS, NULL, 193764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen &error); 194764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen if (! enumerator) 195764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen return; 196764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen error = NULL; 197764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen info = g_file_enumerator_next_file (enumerator, NULL, &error); 198764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen while ((info) && (!error)) 199764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen { 200764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen descend = g_file_get_child (parent, g_file_info_get_name (info)); 201764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_assert (descend != NULL); 202764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen relative_path = g_file_get_relative_path (root, descend); 203764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_assert (relative_path != NULL); 204764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 205764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen if (g_file_info_get_file_type (info) == G_FILE_TYPE_DIRECTORY) 206764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen cleanup_dir_recurse (descend, root); 207764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 208764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen error = NULL; 209764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen res = g_file_delete (descend, NULL, &error); 210764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_assert_cmpint (res, ==, TRUE); 211764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 212764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_object_unref (descend); 213764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen error = NULL; 214764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen info = g_file_enumerator_next_file (enumerator, NULL, &error); 215764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen } 216764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_assert (error == NULL); 217764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 218764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen error = NULL; 219764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen res = g_file_enumerator_close (enumerator, NULL, &error); 220764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_assert_cmpint (res, ==, TRUE); 221764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_assert (error == NULL); 222764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen} 223764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 224764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasenstatic void 225764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasencleanup_subdirs (const char *basedir) 226764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen{ 227764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen GFile *base, *file; 228764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 229764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen base = g_file_new_for_path (basedir); 230764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen file = g_file_get_child (base, "applications"); 231764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen cleanup_dir_recurse (file, file); 232764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_object_unref (file); 233764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen file = g_file_get_child (base, "mime"); 234764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen cleanup_dir_recurse (file, file); 235764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_object_unref (file); 236764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen} 237764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 238764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasenint 239764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasenmain (int argc, 240764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen char *argv[]) 241764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen{ 24282c68c6a14633f949186e7e96fbacb20a5f98931Matthias Clasen gint result; 24382c68c6a14633f949186e7e96fbacb20a5f98931Matthias Clasen 244764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_type_init (); 245764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_test_init (&argc, &argv, NULL); 246764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 247764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen basedir = g_get_current_dir (); 248764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_setenv ("XDG_DATA_HOME", basedir, TRUE); 249764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen cleanup_subdirs (basedir); 250764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 251764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_test_add_func ("/desktop-app-info/delete", test_delete); 252764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen g_test_add_func ("/desktop-app-info/default", test_default); 253764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen 25482c68c6a14633f949186e7e96fbacb20a5f98931Matthias Clasen result = g_test_run (); 25582c68c6a14633f949186e7e96fbacb20a5f98931Matthias Clasen 25682c68c6a14633f949186e7e96fbacb20a5f98931Matthias Clasen cleanup_subdirs (basedir); 25782c68c6a14633f949186e7e96fbacb20a5f98931Matthias Clasen 25882c68c6a14633f949186e7e96fbacb20a5f98931Matthias Clasen return result; 259764e187fd9f1f54a2c622fce2b3e1c0aa4fafdf0Matthias Clasen} 260