diff options
author | Nicolas Dufresne <nicolas.dufresne@collabora.co.uk> | 2011-02-09 12:10:02 +0000 |
---|---|---|
committer | Nicolas Dufresne <nicolas.dufresne@collabora.co.uk> | 2011-02-10 17:03:36 +0000 |
commit | fd085ea5f2310e2fc23a8c53b4e00f9e73641b0a (patch) | |
tree | cd97e1f0a6038d859bf267558e87698992934568 /telepathy-logger/util.c | |
parent | f89d14a18f2d1b8fd9759a3faf12119d2f35c787 (diff) | |
download | telepathy-logger-fd085ea5f2310e2fc23a8c53b4e00f9e73641b0a.tar.gz |
Implement clear method for XML log store
Diffstat (limited to 'telepathy-logger/util.c')
-rw-r--r-- | telepathy-logger/util.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/telepathy-logger/util.c b/telepathy-logger/util.c index 112c56d..13dfbd4 100644 --- a/telepathy-logger/util.c +++ b/telepathy-logger/util.c @@ -24,6 +24,10 @@ #include "datetime-internal.h" #include "log-store-sqlite-internal.h" +#include <errno.h> +#include <glib.h> +#include <glib/gstdio.h> + /* Bug#26838 prevents us to trust Messages' iface message-token * header, so I need to create a token which TPL can trust to be unique * within itself */ @@ -48,3 +52,41 @@ _tpl_create_message_token (const gchar *channel, return retval; } + + +void +_tpl_rmdir_recursively (const gchar *dir_name) +{ + GDir *dir; + const gchar *name; + GError *error = NULL; + + dir = g_dir_open (dir_name, 0, &error); + + if (dir == NULL) + { + /* Directory does not exist, nothing to do */ + g_error_free (error); + return; + } + + while ((name = g_dir_read_name (dir)) != NULL) + { + gchar *filename = g_build_path (G_DIR_SEPARATOR_S, + dir_name, name, NULL); + + if (g_file_test (filename, G_FILE_TEST_IS_DIR)) + _tpl_rmdir_recursively (filename); + else if (g_unlink (filename) < 0) + g_warning ("Could not unlink '%s': %s", filename, g_strerror (errno)); + + g_free (filename); + } + + g_dir_close (dir); + + if (g_rmdir (dir_name) < 0) + g_warning ("Could not remove directory '%s': %s", + dir_name, g_strerror (errno)); +} + |