From babd9857027a20ac25d373a6378cceaf417e2634 Mon Sep 17 00:00:00 2001 From: Patrick McDermott Date: Fri, 10 Nov 2017 11:58:53 -0500 Subject: mq_profiles_remove(): Remove profile directory --- diff --git a/src/config/profiles.c b/src/config/profiles.c index 3c8abad..021df5e 100644 --- a/src/config/profiles.c +++ b/src/config/profiles.c @@ -309,10 +309,43 @@ mq_profiles_insert(MqProfiles *profiles, const gchar *name, const gchar *color) } } +static gboolean +unlink_recursive(const gchar *dir_path) +{ + GDir *dir; + const gchar *entry_name; + gchar *entry_path; + + dir = g_dir_open(dir_path, 0, NULL); + if (!dir) { + return FALSE; + } + + while ((entry_name = g_dir_read_name(dir))) { + entry_path = g_build_filename(dir_path, entry_name, NULL); + if (g_file_test(entry_path, G_FILE_TEST_IS_DIR)) { + unlink_recursive(entry_path); + } + if (g_unlink(entry_path) != 0) { + return FALSE; + } + g_free(entry_path); + } + + g_dir_close(dir); + if (g_rmdir(dir_path) != 0) { + return FALSE; + } + + return TRUE; +} + gboolean mq_profiles_remove(MqProfiles *profiles, const gchar *profile) { - return g_key_file_remove_group(profiles->key_file, profile, NULL); + return unlink_recursive( + g_build_filename(profiles->config_dir, profile, NULL)) + && g_key_file_remove_group(profiles->key_file, profile, NULL); } gboolean -- cgit v0.9.1