[evolution-data-server] mbox_store_get_full_path(): Improve path building.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] mbox_store_get_full_path(): Improve path building.
- Date: Fri, 10 Aug 2012 11:42:35 +0000 (UTC)
commit 0a9a5edcc872a75af97345e4137e98f2bceabdab
Author: Matthew Barnes <mbarnes redhat com>
Date: Fri Aug 10 07:34:19 2012 -0400
mbox_store_get_full_path(): Improve path building.
Deal with the root path not ending in a directory separator, and use a
GString for heaven sake!
camel/providers/local/camel-mbox-store.c | 43 ++++++++++++-----------------
1 files changed, 18 insertions(+), 25 deletions(-)
---
diff --git a/camel/providers/local/camel-mbox-store.c b/camel/providers/local/camel-mbox-store.c
index 0354a8b..e7ab514 100644
--- a/camel/providers/local/camel-mbox-store.c
+++ b/camel/providers/local/camel-mbox-store.c
@@ -904,10 +904,9 @@ mbox_store_get_full_path (CamelLocalStore *ls,
CamelLocalSettings *local_settings;
CamelSettings *settings;
CamelService *service;
- const gchar *inptr = full_name;
- gint subdirs = 0;
+ GString *full_path;
gchar *root_path;
- gchar *path, *p;
+ const gchar *cp;
service = CAMEL_SERVICE (ls);
settings = camel_service_get_settings (service);
@@ -916,35 +915,29 @@ mbox_store_get_full_path (CamelLocalStore *ls,
root_path = camel_local_settings_dup_path (local_settings);
g_return_val_if_fail (root_path != NULL, NULL);
- while (*inptr != '\0') {
- if (G_IS_DIR_SEPARATOR (*inptr))
- subdirs++;
- inptr++;
- }
-
- path = g_malloc (strlen (root_path) + (inptr - full_name) + (4 * subdirs) + 1);
- p = g_stpcpy (path, root_path);
-
- g_free (root_path);
+ full_path = g_string_new (root_path);
- inptr = full_name;
- while (*inptr != '\0') {
- while (!G_IS_DIR_SEPARATOR (*inptr) && *inptr != '\0')
- *p++ = *inptr++;
+ /* Root path may or may not have a trailing separator. */
+ if (!g_str_has_suffix (root_path, G_DIR_SEPARATOR_S))
+ g_string_append_c (full_path, G_DIR_SEPARATOR);
- if (G_IS_DIR_SEPARATOR (*inptr)) {
- p = g_stpcpy (p, ".sbd/");
- inptr++;
+ cp = full_name;
+ while (*cp != '\0') {
+ if (G_IS_DIR_SEPARATOR (*cp)) {
+ g_string_append (full_path, ".sbd");
+ g_string_append_c (full_path, *cp++);
- /* strip extranaeous '/'s */
- while (G_IS_DIR_SEPARATOR (*inptr))
- inptr++;
+ /* Skip extranaeous separators. */
+ while (G_IS_DIR_SEPARATOR (*cp))
+ cp++;
+ } else {
+ g_string_append_c (full_path, *cp++);
}
}
- *p = '\0';
+ g_free (root_path);
- return path;
+ return g_string_free (full_path, FALSE);
}
static gchar *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]