summaryrefslogtreecommitdiff
path: root/src/storage.c
diff options
context:
space:
mode:
authorJukka Rissanen <jukka.rissanen@linux.intel.com>2012-06-05 11:24:03 +0300
committerPatrik Flykt <patrik.flykt@linux.intel.com>2012-06-11 13:01:42 +0300
commit2402957bc789667f0eb0cdbe25fdcebc2edc3b57 (patch)
tree1b78740d36984af6445e7714dcc51e644e36cd9b /src/storage.c
parente7e7c461a0a0d5db36db677a46aa751a78beedca (diff)
downloadconnman-2402957bc789667f0eb0cdbe25fdcebc2edc3b57.tar.gz
connman-2402957bc789667f0eb0cdbe25fdcebc2edc3b57.tar.bz2
connman-2402957bc789667f0eb0cdbe25fdcebc2edc3b57.zip
storage: Add function to remove a service directory
All known files from service directory are removed and if successfull then the service directory is also removed.
Diffstat (limited to 'src/storage.c')
-rw-r--r--src/storage.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/storage.c b/src/storage.c
index b93554d0..47bd0cbc 100644
--- a/src/storage.c
+++ b/src/storage.c
@@ -266,6 +266,69 @@ int __connman_storage_save_service(GKeyFile *keyfile, const char *service_id)
return ret;
}
+static gboolean remove_file(const char *service_id, const char *file)
+{
+ gchar *pathname;
+ gboolean ret = FALSE;
+
+ pathname = g_strdup_printf("%s/%s/%s", STORAGEDIR, service_id, file);
+ if(pathname == NULL)
+ return FALSE;
+
+ if (g_file_test(pathname, G_FILE_TEST_EXISTS) == FALSE) {
+ ret = TRUE;
+ } else if (g_file_test(pathname, G_FILE_TEST_IS_REGULAR) == TRUE) {
+ unlink(pathname);
+ ret = TRUE;
+ }
+
+ g_free(pathname);
+ return ret;
+}
+
+static gboolean remove_dir(const char *service_id)
+{
+ gchar *pathname;
+ gboolean ret = FALSE;
+
+ pathname = g_strdup_printf("%s/%s", STORAGEDIR, service_id);
+ if(pathname == NULL)
+ return FALSE;
+
+ if (g_file_test(pathname, G_FILE_TEST_EXISTS) == FALSE) {
+ ret = TRUE;
+ } else if (g_file_test(pathname, G_FILE_TEST_IS_DIR) == TRUE) {
+ rmdir(pathname);
+ ret = TRUE;
+ }
+
+ g_free(pathname);
+ return ret;
+}
+
+gboolean __connman_storage_remove_service(const char *service_id)
+{
+ gboolean removed;
+
+ /* Remove service configuration file */
+ removed = remove_file(service_id, SETTINGS);
+ if (removed == FALSE)
+ return FALSE;
+
+ /* Remove the statistics file also */
+ removed = remove_file(service_id, "data");
+ if (removed == FALSE)
+ return FALSE;
+
+ removed = remove_dir(service_id);
+ if (removed == FALSE)
+ return FALSE;
+
+ DBG("Removed service dir %s/%s", STORAGEDIR, service_id);
+
+ return TRUE;
+}
+
GKeyFile *__connman_storage_load_provider(const char *identifier)
{
gchar *pathname;